diff --git a/devstack/samples/sample-vnfd-http-monitor.yaml b/devstack/samples/sample-vnfd-http-monitor.yaml new file mode 100644 index 000000000..8a1388aef --- /dev/null +++ b/devstack/samples/sample-vnfd-http-monitor.yaml @@ -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 diff --git a/etc/tacker/tacker.conf b/etc/tacker/tacker.conf index 4c250e8d9..279e28ce6 100644 --- a/etc/tacker/tacker.conf +++ b/etc/tacker/tacker.conf @@ -398,6 +398,7 @@ mgmt_driver = openwrt # Specify drivers for monitoring monitor_driver = ping +monitor_driver = http_ping [servicevm_nova] # parameters for novaclient to talk to nova diff --git a/setup.cfg b/setup.cfg index 3af6938b4..43d8b2219 100644 --- a/setup.cfg +++ b/setup.cfg @@ -55,6 +55,7 @@ tacker.servicevm.mgmt.drivers = openwrt = tacker.vm.mgmt_drivers.openwrt.openwrt:DeviceMgmtOpenWRT tacker.servicevm.monitor.drivers = ping = tacker.vm.monitor_drivers.ping.ping:VNFMonitorPing + http_ping = tacker.vm.monitor_drivers.http_ping.http_ping:VNFMonitorHTTPPing [build_sphinx] diff --git a/tacker/vm/monitor_drivers/http_ping/__init__.py b/tacker/vm/monitor_drivers/http_ping/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tacker/vm/monitor_drivers/http_ping/http_ping.py b/tacker/vm/monitor_drivers/http_ping/http_ping.py new file mode 100644 index 000000000..ff678383a --- /dev/null +++ b/tacker/vm/monitor_drivers/http_ping/http_ping.py @@ -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)