HTTP ping monitor driver for Monitoring Framework
Change-Id: Iab2e0d92ffd52d6575a4372aeadc5285dab85277 Implements: blueprint monitoring
This commit is contained in:
parent
0773f4e1a1
commit
0e91cd11c8
39
devstack/samples/sample-vnfd-http-monitor.yaml
Normal file
39
devstack/samples/sample-vnfd-http-monitor.yaml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
template_name: sample-vnfd-http-monitor
|
||||||
|
description: demo-example
|
||||||
|
|
||||||
|
service_properties:
|
||||||
|
Id: sample-vnfd
|
||||||
|
vendor: tacker
|
||||||
|
version: 1
|
||||||
|
|
||||||
|
vdus:
|
||||||
|
vdu1:
|
||||||
|
id: vdu1
|
||||||
|
vm_image: ubuntu
|
||||||
|
instance_type: m1.small
|
||||||
|
|
||||||
|
network_interfaces:
|
||||||
|
management:
|
||||||
|
network: net_mgmt
|
||||||
|
management: true
|
||||||
|
pkt_in:
|
||||||
|
network: net0
|
||||||
|
pkt_out:
|
||||||
|
network: net1
|
||||||
|
|
||||||
|
placement_policy:
|
||||||
|
availability_zone: nova
|
||||||
|
|
||||||
|
auto-scaling: noop
|
||||||
|
monitoring_policy:
|
||||||
|
http_ping:
|
||||||
|
monitoring_params:
|
||||||
|
retry: 5
|
||||||
|
timeout: 10
|
||||||
|
port: 8000
|
||||||
|
actions:
|
||||||
|
failure: respawn
|
||||||
|
|
||||||
|
config:
|
||||||
|
param0: key0
|
||||||
|
param1: key1
|
@ -398,6 +398,7 @@ mgmt_driver = openwrt
|
|||||||
|
|
||||||
# Specify drivers for monitoring
|
# Specify drivers for monitoring
|
||||||
monitor_driver = ping
|
monitor_driver = ping
|
||||||
|
monitor_driver = http_ping
|
||||||
|
|
||||||
[servicevm_nova]
|
[servicevm_nova]
|
||||||
# parameters for novaclient to talk to nova
|
# parameters for novaclient to talk to nova
|
||||||
|
@ -55,6 +55,7 @@ tacker.servicevm.mgmt.drivers =
|
|||||||
openwrt = tacker.vm.mgmt_drivers.openwrt.openwrt:DeviceMgmtOpenWRT
|
openwrt = tacker.vm.mgmt_drivers.openwrt.openwrt:DeviceMgmtOpenWRT
|
||||||
tacker.servicevm.monitor.drivers =
|
tacker.servicevm.monitor.drivers =
|
||||||
ping = tacker.vm.monitor_drivers.ping.ping:VNFMonitorPing
|
ping = tacker.vm.monitor_drivers.ping.ping:VNFMonitorPing
|
||||||
|
http_ping = tacker.vm.monitor_drivers.http_ping.http_ping:VNFMonitorHTTPPing
|
||||||
|
|
||||||
|
|
||||||
[build_sphinx]
|
[build_sphinx]
|
||||||
|
0
tacker/vm/monitor_drivers/http_ping/__init__.py
Normal file
0
tacker/vm/monitor_drivers/http_ping/__init__.py
Normal file
77
tacker/vm/monitor_drivers/http_ping/http_ping.py
Normal file
77
tacker/vm/monitor_drivers/http_ping/http_ping.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
import urllib2
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from tacker.common import log
|
||||||
|
from tacker.i18n import _LW
|
||||||
|
from tacker.openstack.common import log as logging
|
||||||
|
from tacker.vm.monitor_drivers import abstract_driver
|
||||||
|
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
OPTS = [
|
||||||
|
cfg.IntOpt('retry', default=5,
|
||||||
|
help=_('number of times to retry')),
|
||||||
|
cfg.IntOpt('timeout', default=1,
|
||||||
|
help=_('number of seconds to wait for a response')),
|
||||||
|
cfg.IntOpt('port', default=80,
|
||||||
|
help=_('HTTP port number to send request'))
|
||||||
|
]
|
||||||
|
cfg.CONF.register_opts(OPTS, 'monitor_http_ping')
|
||||||
|
|
||||||
|
|
||||||
|
class VNFMonitorHTTPPing(abstract_driver.VNFMonitorAbstractDriver):
|
||||||
|
def get_type(self):
|
||||||
|
return 'http_ping'
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
return 'HTTP ping'
|
||||||
|
|
||||||
|
def get_description(self):
|
||||||
|
return 'Tacker HTTP Ping Driver for VNF'
|
||||||
|
|
||||||
|
def monitor_url(self, plugin, context, device):
|
||||||
|
LOG.debug(_('monitor_url %s'), device)
|
||||||
|
return device.get('monitor_url', '')
|
||||||
|
|
||||||
|
def _is_pingable(self, mgmt_ip='', retry=5, timeout=5, port=80, **kwargs):
|
||||||
|
"""Checks whether the server is reachable by using urllib2.
|
||||||
|
|
||||||
|
Waits for connectivity for `timeout` seconds,
|
||||||
|
and if connection refused, it will retry `retry`
|
||||||
|
times.
|
||||||
|
:param mgmt_ip: IP to check
|
||||||
|
:param retry: times to reconnect if connection refused
|
||||||
|
:param timeout: seconds to wait for connection
|
||||||
|
:param port: port number to check connectivity
|
||||||
|
:return: bool - True or False depending on pingability.
|
||||||
|
"""
|
||||||
|
url = 'http://' + mgmt_ip + ':' + str(port)
|
||||||
|
for retry_index in range(int(retry)):
|
||||||
|
try:
|
||||||
|
urllib2.urlopen(url, timeout=timeout)
|
||||||
|
return True
|
||||||
|
except urllib2.URLError:
|
||||||
|
LOG.warning(_LW('Unable to reach to the url %s'), url)
|
||||||
|
return 'failure'
|
||||||
|
|
||||||
|
@log.log
|
||||||
|
def monitor_call(self, device, kwargs):
|
||||||
|
if not kwargs['mgmt_ip']:
|
||||||
|
return
|
||||||
|
|
||||||
|
return self._is_pingable(**kwargs)
|
Loading…
x
Reference in New Issue
Block a user