X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwcm%2Fplugins%2Frwconman%2Frift%2Ftasklets%2Frwconmantasklet%2Frwconman_events.py;h=e576aac8643e1522470db53b6a5f86140d80ba58;hb=refs%2Fchanges%2F42%2F1742%2F1;hp=f292a689394a935a81fccf531ca982d08c710956;hpb=255ff03a528a3090ce7f46f0a63b65da3e6f9bcf;p=osm%2FSO.git
diff --git a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_events.py b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_events.py
index f292a689..e576aac8 100644
--- a/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_events.py
+++ b/rwcm/plugins/rwconman/rift/tasklets/rwconmantasklet/rwconman_events.py
@@ -97,23 +97,8 @@ class ConfigManagerEvents(object):
yield from self.update_vnf_state(vnf_cfg, conmanY.RecordState.CFG_SEND)
try:
- if vnf_cfg['config_method'] == 'netconf':
- self._log.info("Creating ncc handle for VNF cfg = %s!", vnf_cfg)
- self.ncc = ConfigManagerVNFnetconf(self._log, self._loop, self, vnf_cfg)
- if vnf_cfg['protocol'] == 'ssh':
- yield from self.ncc.connect_ssh()
- else:
- yield from self.ncc.connect()
- yield from self.ncc.apply_edit_cfg()
- elif vnf_cfg['config_method'] == 'rest':
- if self.rcc is None:
- self._log.info("Creating rcc handle for VNF cfg = %s!", vnf_cfg)
- self.rcc = ConfigManagerVNFrestconf(self._log, self._loop, self, vnf_cfg)
- self.ncc.apply_edit_cfg()
- elif vnf_cfg['config_method'] == 'script':
- self._log.info("Executing script for VNF cfg = %s!", vnf_cfg)
- scriptc = ConfigManagerVNFscriptconf(self._log, self._loop, self, vnf_cfg)
- yield from scriptc.apply_edit_cfg()
+ if vnf_cfg['config_method'] == 'script':
+ self._log.info("Executing script for VNF cfg = %s, No action needed!", vnf_cfg)
elif vnf_cfg['config_method'] == 'juju':
self._log.info("Executing juju config for VNF cfg = %s!", vnf_cfg)
jujuc = ConfigManagerVNFjujuconf(self._log, self._loop, self._parent, vnf_cfg)
@@ -139,194 +124,6 @@ class ConfigManagerEvents(object):
return True
-class ConfigManagerVNFscriptconf(object):
-
- def __init__(self, log, loop, parent, vnf_cfg):
- self._log = log
- self._loop = loop
- self._parent = parent
- self._manager = None
- self._vnf_cfg = vnf_cfg
-
- #@asyncio.coroutine
- def apply_edit_cfg(self):
- vnf_cfg = self._vnf_cfg
- self._log.debug("Attempting to apply scriptconf to VNF: %s", log_this_vnf(vnf_cfg))
- try:
- st = os.stat(vnf_cfg['cfg_file'])
- os.chmod(vnf_cfg['cfg_file'], st.st_mode | stat.S_IEXEC)
- #script_msg = subprocess.check_output(vnf_cfg['cfg_file'], shell=True).decode('utf-8')
-
- proc = yield from asyncio.create_subprocess_exec(
- vnf_cfg['script_type'], vnf_cfg['cfg_file'],
- stdout=asyncio.subprocess.PIPE)
- script_msg = yield from proc.stdout.read()
- rc = yield from proc.wait()
-
- if rc != 0:
- raise ScriptError(
- "script config returned error code : %s" % rc
- )
-
- self._log.debug("config script output (%s)", script_msg)
- except Exception as e:
- self._log.error("Error (%s) while executing script config for VNF: %s",
- str(e), log_this_vnf(vnf_cfg))
- raise
-
-class ConfigManagerVNFrestconf(object):
-
- def __init__(self, log, loop, parent, vnf_cfg):
- self._log = log
- self._loop = loop
- self._parent = parent
- self._manager = None
- self._vnf_cfg = vnf_cfg
-
- def fetch_handle(self, response):
- if response.error:
- self._log.error("Failed to send HTTP config request - %s", response.error)
- else:
- self._log.debug("Sent HTTP config request - %s", response.body)
-
- @asyncio.coroutine
- def apply_edit_cfg(self):
- vnf_cfg = self._vnf_cfg
- self._log.debug("Attempting to apply restconf to VNF: %s", log_this_vnf(vnf_cfg))
- try:
- http_c = tornadoh.AsyncHTTPClient()
- # TBD
- # Read the config entity from file?
- # Convert connectoin-point?
- http_c.fetch("http://", self.fetch_handle)
- except Exception as e:
- self._log.error("Error (%s) while applying HTTP config", str(e))
-
-class ConfigManagerVNFnetconf(object):
-
- def __init__(self, log, loop, parent, vnf_cfg):
- self._log = log
- self._loop = loop
- self._parent = parent
- self._manager = None
- self._vnf_cfg = vnf_cfg
-
- self._model = RwYang.Model.create_libncx()
- self._model.load_schema_ypbc(conmanY.get_schema())
-
- @asyncio.coroutine
- def connect(self, timeout_secs=120):
- vnf_cfg = self._vnf_cfg
- start_time = time.time()
- self._log.debug("connecting netconf .... %s", vnf_cfg)
- while (time.time() - start_time) < timeout_secs:
-
- try:
- self._log.info("Attemping netconf connection to VNF: %s", log_this_vnf(vnf_cfg))
-
- self._manager = yield from ncclient.asyncio_manager.asyncio_connect(
- loop=self._loop,
- host=vnf_cfg['mgmt_ip_address'],
- port=vnf_cfg['port'],
- username=vnf_cfg['username'],
- password=vnf_cfg['password'],
- allow_agent=False,
- look_for_keys=False,
- hostkey_verify=False,
- )
-
- self._log.info("Netconf connected to VNF: %s", log_this_vnf(vnf_cfg))
- return
-
- except ncclient.transport.errors.SSHError as e:
- yield from self._parent.update_vnf_state(vnf_cfg, conmanY.RecordState.FAILED_CONNECTION)
- self._log.error("Netconf connection to VNF: %s, failed: %s",
- log_this_vnf(vnf_cfg), str(e))
-
- yield from asyncio.sleep(2, loop=self._loop)
-
- raise ConfigManagerROifConnectionError(
- "Failed to connect to VNF: %s within %s seconds" %
- (log_this_vnf(vnf_cfg), timeout_secs)
- )
-
- @asyncio.coroutine
- def connect_ssh(self, timeout_secs=120):
- vnf_cfg = self._vnf_cfg
- start_time = time.time()
-
- if (self._manager != None and self._manager.connected == True):
- self._log.debug("Disconnecting previous session")
- self._manager.close_session
-
- self._log.debug("connecting netconf via SSH .... %s", vnf_cfg)
- while (time.time() - start_time) < timeout_secs:
-
- try:
- yield from self._parent.update_vnf_state(vnf_cfg, conmanY.RecordState.CONNECTING)
- self._log.debug("Attemping netconf connection to VNF: %s", log_this_vnf(vnf_cfg))
-
- self._manager = ncclient.asyncio_manager.manager.connect_ssh(
- host=vnf_cfg['mgmt_ip_address'],
- port=vnf_cfg['port'],
- username=vnf_cfg['username'],
- password=vnf_cfg['password'],
- allow_agent=False,
- look_for_keys=False,
- hostkey_verify=False,
- )
-
- yield from self._parent.update_vnf_state(vnf_cfg, conmanY.RecordState.NETCONF_SSH_CONNECTED)
- self._log.debug("netconf over SSH connected to VNF: %s", log_this_vnf(vnf_cfg))
- return
-
- except ncclient.transport.errors.SSHError as e:
- yield from self._parent.update_vnf_state(vnf_cfg, conmanY.RecordState.FAILED_CONNECTION)
- self._log.error("Netconf connection to VNF: %s, failed: %s",
- log_this_vnf(vnf_cfg), str(e))
-
- yield from asyncio.sleep(2, loop=self._loop)
-
- raise ConfigManagerROifConnectionError(
- "Failed to connect to VNF: %s within %s seconds" %
- (log_this_vnf(vnf_cfg), timeout_secs)
- )
-
- @asyncio.coroutine
- def apply_edit_cfg(self):
- vnf_cfg = self._vnf_cfg
- self._log.debug("Attempting to apply netconf to VNF: %s", log_this_vnf(vnf_cfg))
-
- if self._manager is None:
- self._log.error("Netconf is not connected to VNF: %s, aborting!", log_this_vnf(vnf_cfg))
- return
-
- # Get config file contents
- try:
- with open(vnf_cfg['cfg_file']) as f:
- configuration = f.read()
- except Exception as e:
- self._log.error("Reading contents of the configuration file(%s) failed: %s", vnf_cfg['cfg_file'], str(e))
- return
-
- try:
- self._log.debug("apply_edit_cfg to VNF: %s", log_this_vnf(vnf_cfg))
- xml = '{}'.format(configuration)
- response = yield from self._manager.edit_config(xml, target='running')
- if hasattr(response, 'xml'):
- response_xml = response.xml
- else:
- response_xml = response.data_xml.decode()
-
- self._log.debug("apply_edit_cfg response: %s", response_xml)
- if '' in response_xml:
- raise ConfigManagerROifConnectionError("apply_edit_cfg response has rpc-error : %s",
- response_xml)
-
- self._log.debug("apply_edit_cfg Successfully applied configuration {%s}", xml)
- except:
- raise
-
class ConfigManagerVNFjujuconf(object):
def __init__(self, log, loop, parent, vnf_cfg):