portscan driver for VNF application Monitoring

This driver is Port monitoring driver for checking application
Status.

Until now, Tacker monitoring drivers can check network(ping) and
application(using HTTP URL).

Moreover, When VNF is rebooted by Ping monitoring result, tacker
re-make same whole VNF.

Therefore, I think port monitoring driver is needed for auto
healing of VNFC level and it is a useful when we check the
VNF inside status too.

Change-Id: I13a2e2ff90c8f30f2468f266c8ab39b948a86772
This commit is contained in:
hyunsik Yang 2016-06-14 21:13:39 +09:00
parent 5ed939be6b
commit 2236d56ada
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,16 @@
1. add port driver in tacker.conf
# Specify drivers for monitoring
monitor_driver = ping, http_ping, port
2. add the port entry_point in setup.cfg
tacker.tacker.monitor.drivers =
ping = tacker.vm.monitor_drivers.ping.ping:VNFMonitorPing
http_ping = tacker.vm.monitor_drivers.http_ping.http_ping:VNFMonitorHTTPPing
port = tacker.vm.monitor_drivers.port.port:VNFMonitorPort
3. install

View File

@ -0,0 +1,90 @@
#
# 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.
#
from oslo_config import cfg
from oslo_log import log as logging
from socket import socket
from tacker._i18n import _LW
from tacker.common import log
from tacker.vm.monitor_drivers import abstract_driver
LOG = logging.getLogger(__name__)
OPTS = [
cfg.StrOpt('count', default='1', help=_('number of ICMP packets to send')),
cfg.StrOpt('timeout', default='1',
help=_('number of seconds to wait for a response')),
cfg.StrOpt('sockmode', default='1',
help=_('socket mode of TCP, UDP(TCP:1, UDP:0)')),
cfg.StrOpt('scanports', default='80', help=_('number of Target port'))
]
cfg.CONF.register_opts(OPTS, 'monitor_port')
class VNFMonitorPort(abstract_driver.VNFMonitorAbstractDriver):
def get_type(self):
return 'port'
def get_name(self):
return 'port'
def get_description(self):
return 'Tacker VNFMonitor Port Driver'
def monitor_url(self, plugin, context, device):
LOG.debug(_('monitor_url %s'), device)
return device.get('monitor_url', '')
def _is_portable(self, mgmt_ip="", count=5, timeout=1, sockmode=1,
scanports=80, **kwargs):
"""Checks whether an Target port is reachable by porting.
:param ip: target IP to check
:param port: target port check
:param mode: check socket mode(TCP or UDP)
:return: bool - True or string 'failure' depending on portability.
"""
try:
if sockmode:
connskt = socket(socket.AF_INET, socket.SOCK_STREAM)
else:
connskt = socket(socket.AF_INET, socket.SOCK_DGRAM)
connskt.settimeout(timeout)
# Make a Socket Connection (TCP)
result = connskt.connect_ex((mgmt_ip, scanports))
if result == 0:
LOG.debug(_("OPEN ip address: %(mgmt_ip)s,"
" port: %(scanports)d\n"))
else:
LOG.debug(_("Close ip address: %(mgmt_ip)s,"
" port: %(scanports)d\n"))
connskt.close()
return 'failure'
connskt.close()
# Close the connection
return True
except RuntimeError:
LOG.warning(_LW("Cannot scan port ip address: %(mgmt_ip)s,"
" port: %(scanports)d\n"))
return 'failure'
@log.log
def monitor_call(self, device, kwargs):
if not kwargs['mgmt_ip']:
return
return self._is_portable(**kwargs)