vnfd = self.descriptor.vnfd[0]
# Add vnf configuration
vnf_config = vnfd.vnf_configuration
-
- # vnf_config.config_attributes.config_delay = 10
-
- # Select "script" configuration
- vnf_config.script.script_type = 'bash'
+ vnf_config.script.script_type = 'python'
# Add initial config primitive
- vnf_config.create_initial_config_primitive()
init_config = VnfdYang.InitialConfigPrimitive.from_dict(
{
"seq": 1,
vnfd = self.descriptor.vnfd[0]
# Add vnf configuration
vnf_config = vnfd.vnf_configuration
-
- # Select "script" configuration
- vnf_config.script.script_type = 'bash'
+ vnf_config.script.script_type = 'python'
# Add initial config primitive
- vnf_config.create_initial_config_primitive()
init_config = VnfdYang.InitialConfigPrimitive.from_dict(
{
"seq": 1,
self.vnfd_config = {}
self._placement_groups = []
- def default_config(self, vnfd):
+ def default_config(self, constituent_vnfd, vnfd, mano_ut, use_ns_init_conf, use_vnf_init_conf):
vnf_config = vnfd.vnfd.vnf_configuration
vnf_config.config_attributes.config_priority = 0
vnf_config.config_attributes.config_delay = 0
- # Select "script" configuration
- vnf_config.script.script_type = 'bash'
- vnf_config.config_template = "#!/bin/bash"
+ if vnfd.name == 'pong_vnfd' or vnfd.name == 'pong_vnfd_with_epa' or vnfd.name == 'pong_vnfd_aws':
+ vnf_config.config_attributes.config_priority = 1
+ # First priority config delay will delay the entire NS config delay
+ if mano_ut is False:
+ vnf_config.config_attributes.config_delay = 60
+ else:
+ # This is PONG and inside mano_ut
+ # This is test only
+ vnf_config.config_attributes.config_delay = 10
+
+ if vnfd.name == 'ping_vnfd' or vnfd.name == 'ping_vnfd_with_epa' or vnfd.name == 'ping_vnfd_aws':
+ vnf_config.config_attributes.config_priority = 2
def ns_config(self, nsd, vnfd_list, mano_ut):
constituent_vnfd.start_by_default = False
constituent_vnfd.vnfd_id_ref = vnfd.descriptor.vnfd[0].id
- self.default_config(vnfd)
+ self.default_config(constituent_vnfd, vnfd, mano_ut,
+ - use_ns_init_conf, use_vnf_init_conf)
member_vnf_index += 1
# Enable config primitives if either mano_ut or
choice config-method {
description
"Defines the configuration method for the VNF.";
- case netconf {
- description
- "Use NETCONF for configuring the VNF.";
- container netconf {
- leaf target {
- description
- "Netconf configuration target";
- type enumeration {
- enum running;
- enum candidate;
- }
- }
-
- leaf protocol {
- description
- "Protocol to use for NETCONF, such as ssh";
- type enumeration {
- enum None;
- enum ssh;
- }
- }
-
- leaf port {
- description
- "Port for the NETCONF server.";
- type inet:port-number;
- }
- }
- }
-
- case rest {
- description
- "Use REST for configuring the VNF.";
- container rest {
- leaf port {
- description
- "Port for the REST server.";
- type inet:port-number;
- }
- }
- }
-
case script {
description
"Use custom script for configuring the VNF.
- This script is executed in the context of
+ This script is executed in the context of
Orchestrator (The same system and environment
as the Launchpad).";
container script {
leaf script-type {
description
- "Script type - currently supported : bash, expect";
+ "Script type - currently supported : python";
type enumeration {
- enum bash;
- enum expect;
+ enum python;
}
}
}
}
}
- container config-access {
- leaf mgmt-ip-address {
- description
- "IP address to be used to configure this VNF,
- optional if it is possible to resolve dynamically.";
- type inet:ip-address;
- }
-
- leaf username {
- description
- "User name for configuration.";
- type string;
- }
-
- leaf password {
- description
- "Password for configuration access authentication.";
- type string;
- }
- }
-
container config-attributes {
description
"Miscellaneous input parameters to be considered
key "seq";
uses initial-config;
}
-
- leaf config-template {
- description
- "Configuration template for each VNF";
- type string;
- }
}
} // END - grouping vnf-configuration
include(rift_plugin)
set(TASKLET_NAME rwconmantasklet)
-set(CONMAN_INSTALL "etc/conman")
-
-##
-# Install translation script in demos
-##
-install(
- FILES
- rift/tasklets/${TASKLET_NAME}/xlate_cfg.py
- rift/tasklets/${TASKLET_NAME}/xlate_tags.yml
- DESTINATION ${CONMAN_INSTALL}
- COMPONENT ${PKG_LONG_NAME})
-
##
# This function creates an install target for the plugin artifacts
def process_nsd_vnf_configuration(self, nsr_obj, vnfr):
def get_config_method(vnf_config):
- cfg_types = ['netconf', 'juju', 'script']
+ cfg_types = ['juju', 'script']
for method in cfg_types:
if method in vnf_config:
return method
return None
- def get_cfg_file_extension(method, configuration_options):
+ def get_cfg_file_extension(method):
ext_dict = {
- "netconf" : "xml",
- "script" : {
- "bash" : "sh",
- "expect" : "exp",
- },
- "juju" : "yml"
+ "juju" : "yml",
+ "script" : "py"
}
- if method == "netconf":
+ if method == "juju":
return ext_dict[method]
elif method == "script":
- return ext_dict[method][configuration_options['script_type']]
- elif method == "juju":
return ext_dict[method]
else:
return "cfg"
configuration_options[cfg_opt] = vnf_config[method][cfg_opt]
vnf_cfg[cfg_opt] = configuration_options[cfg_opt]
- cfg_opt_list = ['mgmt_ip_address', 'username', 'password']
- for cfg_opt in cfg_opt_list:
- if cfg_opt in vnf_config['config_access']:
- configuration_options[cfg_opt] = vnf_config['config_access'][cfg_opt]
- vnf_cfg[cfg_opt] = configuration_options[cfg_opt]
-
# Add to the cp_dict
vnf_cp_dict = nsr_obj._cp_dict[vnfr['member_vnf_index_ref']]
vnf_cp_dict['rw_mgmt_ip'] = vnf_cfg['mgmt_ip_address']
# TBD - see if we can neatly include the config in "config_attributes" file, no need though
- #config_priority['config_template'] = vnf_config['config_template']
# Create config file
vnf_cfg['juju_script'] = os.path.join(self._parent.cfg_dir, 'juju_if.py')
-
- if 'config_template' in vnf_config:
- vnf_cfg['cfg_template'] = '{}_{}_template.cfg'.format(nsr_obj.cfg_path_prefix, config_priority['configuration_type'])
- vnf_cfg['cfg_file'] = '{}.{}'.format(nsr_obj.cfg_path_prefix, get_cfg_file_extension(method, configuration_options))
- vnf_cfg['xlate_script'] = os.path.join(self._parent.cfg_dir, 'xlate_cfg.py')
- try:
- # Now write this template into file
- with open(vnf_cfg['cfg_template'], "w") as cf:
- cf.write(vnf_config['config_template'])
- except Exception as e:
- self._log.error("Processing NSD, failed to generate configuration template : %s (Error : %s)",
- vnf_config['config_template'], str(e))
- raise
+ vnf_cfg['cfg_file'] = '{}.{}'.format(nsr_obj.cfg_path_prefix, get_cfg_file_extension(method))
self._log.debug("VNF endpoint so far: %s", vnf_cfg)
nsr_dict = self._nsr_dict
self._log.info("Configure NSR, id = %s", id)
- #####################TBD###########################
- # yield from self._config_agent_mgr.invoke_config_agent_plugins('notify_create_nsr', self.id, self._nsd)
- # yield from self._config_agent_mgr.invoke_config_agent_plugins('notify_nsr_active', self.id, self._vnfrs)
-
try:
if id not in nsr_dict:
nsr_obj = ConfigManagerNSR(self._log, self._loop, self, id)
self._log.info("Checking NS config directory: %s", nsr_dir)
if not os.path.isdir(nsr_dir):
os.makedirs(nsr_dir)
- # self._log.critical("NS %s is not to be configured by Service Orchestrator!", nsr_obj.nsr_name)
- # yield from nsr_obj.update_ns_cm_state(conmanY.RecordState.READY_NO_CFG)
- # return
nsr_obj.set_config_dir(self)
nsr_obj.agent_nsr,
agent_vnfr)
- #####################TBD###########################
- # self._log.debug("VNF active. Apply initial config for vnfr {}".format(vnfr.name))
- # yield from self._config_agent_mgr.invoke_config_agent_plugins('apply_initial_config',
- # vnfr.id, vnfr)
- # yield from self._config_agent_mgr.invoke_config_agent_plugins('notify_terminate_vnf', self.id, vnfr)
-
except Exception as e:
self._log.error("Failed processing NSR (%s) as (%s)", nsr_obj.nsr_name, str(e))
self._log.exception(e)
except Exception as e:
self._log.error("NS:(%s) failed to write config attributes file as (%s)", nsr_obj.nsr_name, str(e))
- try:
- # Generate nsr_xlate_dict.yaml (For debug reference)
- with open(nsr_obj.xlate_dict_file, "w") as yf:
- yf.write(yaml.dump(nsr_obj._cp_dict, default_flow_style=False))
- except Exception as e:
- self._log.error("NS:(%s) failed to write nsr xlate tags file as (%s)", nsr_obj.nsr_name, str(e))
-
self._log.debug("Starting to configure each VNF")
# Check if this NS has input parametrs
# Go in loop to configure by specified order
self._log.info("Using Dynamic configuration input parametrs for NS: %s", nsr_obj.nsr_name)
- # cfg_delay = nsr_obj.nsr_cfg_config_attributes_dict['configuration_delay']
- # if cfg_delay:
- # self._log.info("Applying configuration delay for NS (%s) ; %d seconds",
- # nsr_obj.nsr_name, cfg_delay)
- # yield from asyncio.sleep(cfg_delay, loop=self._loop)
-
for config_attributes_dict in nsr_obj.nsr_cfg_config_attributes_dict.values():
# Iterate through each priority level
for vnf_config_attributes_dict in config_attributes_dict:
# Iterate through each vnfr at this priority level
- # Make up vnf_unique_name with vnfd name and member index
- #vnfr_name = "{}.{}".format(nsr_obj.nsr_name, vnf_config_attributes_dict['name'])
vnf_unique_name = get_vnf_unique_name(
nsr_obj.nsr_name,
vnf_config_attributes_dict['name'],
# publish delete cm-state (cm-nsr)
yield from nsr_obj.delete_cm_nsr()
- #####################TBD###########################
- # yield from self._config_agent_mgr.invoke_config_agent_plugins('notify_terminate_ns', self.id)
-
self._log.info("NSR(%s/%s) is deleted", nsr_obj.nsr_name, id)
@asyncio.coroutine
self._log.debug("NSR:(%s), Created configuration directory(%s)",
caller._nsr['name_ref'], self.this_nsr_dir)
self.config_attributes_file = os.path.join(self.this_nsr_dir, "configuration_config_attributes.yml")
- self.xlate_dict_file = os.path.join(self.this_nsr_dir, "nsr_xlate_dict.yml")
- def xlate_conf(self, vnfr, vnf_cfg):
-
- # If configuration type is not already set, try to read from attributes
- if vnf_cfg['interface_type'] is None:
- # Prepare unique name for this VNF
- vnf_unique_name = get_vnf_unique_name(
- vnf_cfg['nsr_name'],
- vnfr['short_name'],
- vnfr['member_vnf_index_ref'],
- )
-
- # Find this particular (unique) VNF's config attributes
- if (vnf_unique_name in self.vnf_config_attributes_dict):
- vnf_cfg_config_attributes_dict = self.vnf_config_attributes_dict[vnf_unique_name]
- vnf_cfg['interface_type'] = vnf_cfg_config_attributes_dict['configuration_type']
- if 'configuration_options' in vnf_cfg_config_attributes_dict:
- cfg_opts = vnf_cfg_config_attributes_dict['configuration_options']
- for key, value in cfg_opts.items():
- vnf_cfg[key] = value
-
- cfg_path_prefix = '{}/{}/{}_{}'.format(
- self._parent._parent.cfg_dir,
- vnf_cfg['nsr_name'],
- vnfr['short_name'],
- vnfr['member_vnf_index_ref'],
- )
-
- vnf_cfg['cfg_template'] = '{}_{}_template.cfg'.format(cfg_path_prefix, vnf_cfg['interface_type'])
- vnf_cfg['cfg_file'] = '{}.cfg'.format(cfg_path_prefix)
- vnf_cfg['xlate_script'] = self._parent._parent.cfg_dir + '/xlate_cfg.py'
-
- self._log.debug("VNF endpoint so far: %s", vnf_cfg)
-
- self._log.info("Checking cfg_template %s", vnf_cfg['cfg_template'])
- if os.path.exists(vnf_cfg['cfg_template']):
- return True
- return False
-
def ConfigVNF(self, vnfr):
vnf_cfg = vnfr['vnf_cfg']
self._cp_dict['rw_mgmt_ip'] = vnf_cfg['mgmt_ip_address']
self._cp_dict['rw_username'] = vnf_cfg['username']
self._cp_dict['rw_password'] = vnf_cfg['password']
- ############################################################
- # TBD - Need to lookup above 3 for a given VNF, not global #
- # Once we do that no need to dump below file again before #
- # each VNF configuration translation. #
- # This will require all existing config templates to be #
- # changed for above three tags to include member index #
- ############################################################
- try:
- nsr_obj = vnf_cfg['nsr_obj']
- # Generate config_config_attributes.yaml (For debug reference)
- with open(nsr_obj.xlate_dict_file, "w") as yf:
- yf.write(yaml.dump(nsr_obj._cp_dict, default_flow_style=False))
- except Exception as e:
- self._log.error("NS:(%s) failed to write nsr xlate tags file as (%s)", nsr_obj.nsr_name, str(e))
-
- if 'cfg_template' in vnf_cfg:
- script_cmd = 'python3 {} -i {} -o {} -x "{}"'.format(vnf_cfg['xlate_script'], vnf_cfg['cfg_template'], vnf_cfg['cfg_file'], self.xlate_dict_file)
- self._log.debug("xlate script command (%s)", script_cmd)
- #xlate_msg = subprocess.check_output(script_cmd).decode('utf-8')
- xlate_msg = subprocess.check_output(script_cmd, shell=True).decode('utf-8')
- self._log.info("xlate script output (%s)", xlate_msg)
except Exception as e:
vnf_cm_state['state'] = self.state_to_string(conmanY.RecordState.CFG_PROCESS_FAILED)
- self._log.error("Failed to execute translation script for VNF: %s with (%s)", log_this_vnf(vnf_cfg), str(e))
+ self._log.error("Failed to set tags for VNF: %s with (%s)", log_this_vnf(vnf_cfg), str(e))
return
self._log.info("Applying config to VNF: %s = %s!", log_this_vnf(vnf_cfg), vnf_cfg)
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)
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 = '<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">{}</config>'.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 '<rpc-error>' 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):
+++ /dev/null
-# This template has all supported TAGs.
-# This template can be used as input to the xlate_cfg.py script as follows:
-
-# python3 ./xlate_cfg.py -i ./rwconman_test_config_template.cfg -o ./rwconman_test_config.cfg -x ./rwconman_test_xlate_dict.yml
-
-
-# This is error
-#0. <rw_connection_point_name test/cp2>
-
-# Following are simple TAGs
-1. This is Management IP: <rw_mgmt_ip>
-2. This is Username: <rw_username>
-3. This is Password: <rw_password>
-4. This is globally unique connection point: <rw_connection_point_name test/cp1>
-
-# Following are colon separated complex TAGs
-5. This is connection point for a given VNF with unique member index: <rw_unique_index:rw_connection_point_name 2:test/cp1>
-6. This is converting connection point IP address into network address: <rw_connection_point:masklen_network test/cp1:24>
-7. This is converting connection point IP address into boadcast address: <rw_connection_point:masklen_broadcast test/cp1:24>
-
-# Following generated tuple with original connectino point name (Global only)
-8. This is not used anywhere: <rw_connection_point_tuple test/cp1>
-
-# Following are multi-colon separated complex TAGs
-9. This is converting connection point IP address into network address VNF with unique member index: <rw_unique_index:rw_connection_point:masklen_network 2:test/cp1:24>
-10. This is converting connection point IP address into network address VNF with unique member index: <rw_unique_index:rw_connection_point:masklen_broadcast 2:test/cp1:24>
-
-# Following test all of the above in single line
-11. All at once: START| rw_mgmt_ip: <rw_mgmt_ip> | rw_username: <rw_username> | rw_password: <rw_password> | global CP: <rw_connection_point_name test/cp1> | 1 CP: <rw_unique_index:rw_connection_point_name 1:test/cp1> | network: <rw_connection_point:masklen_network test/cp1:24> | broadcast: <rw_connection_point:masklen_broadcast test/cp1:24> | tuple: <rw_connection_point_tuple test/cp1> | 2 network: <rw_unique_index:rw_connection_point:masklen_network 2:test/cp1:24> | 2 broadcast: <rw_unique_index:rw_connection_point:masklen_broadcast 2:test/cp1:24> |END
-
-# Need to work on the solution for multiple pattern of same type in single line.
-
+++ /dev/null
-1:
- test/cp1: 11.0.0.1
-2:
- test/cp1: 11.0.0.2
-test/cp1: 11.0.0.3
-rw_mgmt_ip: 1.1.1.1
-rw_username: admin
-rw_password: admin
+++ /dev/null
-#!/usr/bin/env python3
-
-#
-# Copyright 2016 RIFT.IO Inc
-#
-# 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.
-#
-
-
-'''
-This script will go through the input conffiguration template and convert all the matching "regular expression" and "strings"
-specified in xlate_cp_list & xlate_str_list with matching IP addresses passed in as dictionary to this script.
-
--i Configuration template
--o Output final configuration complete with IP addresses
--x Xlate(Translate dictionary in string format
--t TAGS to be translated
-
-'''
-
-import sys
-import getopt
-import ast
-import re
-import yaml
-import netaddr
-
-from inspect import getsourcefile
-import os.path
-
-xlate_dict = None
-
-def xlate_cp_list(line, cp_list):
- for cp_string in cp_list:
- match = re.search(cp_string, line)
- if match is not None:
- # resolve IP address using Connection Point dictionary
- resolved_ip = xlate_dict[match.group(1)]
- if resolved_ip is None:
- print("No matching CP found: ", match.group(1))
- exit(2)
- else:
- line = line[:match.start()] + resolved_ip + line[match.end():]
- return line
-
-def xlate_multi_colon_list(line, multi_colon_list):
- for ucp_string in multi_colon_list:
- #print("Searching :", ucp_string)
- match = re.search(ucp_string, line)
- if match is not None:
- #print("match :", match.group())
- # resolve IP address using Connection Point dictionary for specified member (unique) index
- ucp_str_list = match.group(1).split(':')
- print("matched = {}, split list = {}".format(match.group(1), ucp_str_list))
- if len(ucp_str_list) != 3:
- print("Invalid TAG in the configuration: ", match.group(1))
- exit(2)
-
- # Traslate given CP address & mask into netaddr
- if ucp_string.startswith('<rw_unique_index:rw_connection_point:masklen'):
- member_vnf_index = int(ucp_str_list[0])
- resolved_ip = xlate_dict[ucp_str_list[1]]
- masklen = ucp_str_list[2]
- if resolved_ip is None:
- print("No matching CP found: ", ucp_str_list[1])
- exit(2)
- if int(masklen) <= 0:
- print("Invalid mask length: ", masklen)
- exit(2)
- else:
- # Generate netaddr
- ip_str = resolved_ip + '/' + masklen
- #print("ip_str:", ip_str)
- ip = netaddr.IPNetwork(ip_str)
- if ucp_string.startswith('<rw_unique_index:rw_connection_point:masklen_broadcast'):
- # Traslate given CP address & mask into broadcast address
- addr = ip.broadcast
- if ucp_string.startswith('<rw_unique_index:rw_connection_point:masklen_network'):
- # Traslate given CP address & mask into network address
- addr = ip.network
- line = line[:match.start()] + str(addr) + line[match.end():]
- return line
-
-
-
-def xlate_colon_list(line, colon_list):
- for ucp_string in colon_list:
- #print("Searching :", ucp_string)
- match = re.search(ucp_string, line)
- if match is not None:
- #print("match :", match.group())
- # resolve IP address using Connection Point dictionary for specified member (unique) index
- ucp_str_list = match.group(1).split(':')
- #print("matched = {}, split list = {}".format(match.group(1), ucp_str_list))
- if len(ucp_str_list) != 2:
- print("Invalid TAG in the configuration: ", match.group(1))
- exit(2)
-
- # Unique Connection Point translation to IP
- if ucp_string.startswith('<rw_unique_index:'):
- member_vnf_index = int(ucp_str_list[0])
- resolved_ip = xlate_dict[member_vnf_index][ucp_str_list[1]]
- #print("member_vnf_index = {}, resolved_ip = {}", member_vnf_index, resolved_ip)
- if resolved_ip is None:
- print("For Unique index ({}), No matching CP found: {}", ucp_str_list[0], ucp_str_list[1])
- exit(2)
- else:
- line = line[:match.start()] + resolved_ip + line[match.end():]
-
- # Traslate given CP address & mask into netaddr
- if ucp_string.startswith('<rw_connection_point:masklen'):
- resolved_ip = xlate_dict[ucp_str_list[0]]
- masklen = ucp_str_list[1]
- if resolved_ip is None:
- print("No matching CP found: ", ucp_str_list[0])
- exit(2)
- if int(masklen) <= 0:
- print("Invalid mask length: ", masklen)
- exit(2)
- else:
- # Generate netaddr
- ip_str = resolved_ip + '/' + masklen
- #print("ip_str:", ip_str)
- ip = netaddr.IPNetwork(ip_str)
-
- if ucp_string.startswith('<rw_connection_point:masklen_broadcast'):
- # Traslate given CP address & mask into broadcast address
- addr = ip.broadcast
- if ucp_string.startswith('<rw_connection_point:masklen_network'):
- # Traslate given CP address & mask into network address
- addr = ip.network
-
- line = line[:match.start()] + str(addr) + line[match.end():]
- return line
-
-def xlate_cp_to_tuple_list(line, cp_to_tuple_list):
- for cp_string in cp_to_tuple_list:
- match = re.search(cp_string, line)
- if match is not None:
- # resolve IP address using Connection Point dictionary
- resolved_ip = xlate_dict[match.group(1)]
- if resolved_ip is None:
- print("No matching CP found: ", match.group(1))
- exit(2)
- else:
- line = line[:match.start()] + match.group(1) + ':' + resolved_ip + line[match.end():]
- return line
-
-def xlate_str_list(line, str_list):
- for replace_tag in str_list:
- replace_string = replace_tag[1:-1]
- line = line.replace(replace_tag, xlate_dict[replace_string])
- return line
-
-
-def main(argv=sys.argv[1:]):
- cfg_template = None
- cfg_file = None
- global xlate_dict
- try:
- opts, args = getopt.getopt(argv,"i:o:x:")
- except getopt.GetoptError:
- print("Check arguments {}".format(argv))
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-i':
- cfg_template = arg
- elif opt in ("-o"):
- cfg_file = arg
- elif opt in ("-x"):
- xlate_arg = arg
-
- # Read TAGS from yaml file
- # Read the translation tags from yaml file
- yml_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
- tags_input_file = os.path.join(yml_dir, 'xlate_tags.yml')
- with open(tags_input_file, "r") as ti:
- xlate_tags = yaml.load(ti.read())
-
- # Need to work on the solution for multiple pattern of same type in single line.
- try:
- with open(xlate_arg, "r") as ti:
- xlate_dict = yaml.load(ti.read())
- try:
- with open(cfg_template, 'r') as r:
- try:
- with open(cfg_file, 'w') as w:
- # Traslate
- try:
- # For each line
- for line in r:
- if line.startswith("#"):
- # Skip comment lines
- continue
- #print("1.Line : ", line)
- # For each Connection Point translation to IP
- line = xlate_cp_list(line, xlate_tags['xlate_cp_list'])
- #print("2.Line : ", line)
-
- # For each colon(:) separated tag, i.e. 3 inputs in a tag.
- line = xlate_multi_colon_list(line, xlate_tags['xlate_multi_colon_list'])
- #print("2a.Line : ", line)
-
- # For each colon(:) separated tag, i.e. 2 inputs in a tag.
- line = xlate_colon_list(line, xlate_tags['xlate_colon_list'])
- #print("3.Line : ", line)
-
- # For each connection point to tuple replacement
- line = xlate_cp_to_tuple_list(line, xlate_tags['xlate_cp_to_tuple_list'])
- #print("4.Line : ", line)
-
- # For each direct replacement (currently only management IP address for ping/pong)
- line = xlate_str_list(line, xlate_tags['xlate_str_list'])
- #print("5.Line : ", line)
-
- # Finally write the modified line to the new config file
- w.write(line)
- except Exception as e:
- print("Error ({}) on line: {}".format(str(e), line))
- exit(2)
- except Exception as e:
- print("Failed to open for write: {}, error({})".format(cfg_file, str(e)))
- exit(2)
- except Exception as e:
- print("Failed to open for read: {}, error({})".format(cfg_template, str(e)))
- exit(2)
- print("Wrote configuration file", cfg_file)
- except Exception as e:
- print("Could not translate dictionary, error: ", str(e))
-
-if __name__ == "__main__":
- try:
- main()
- except Exception as e:
- print(str(e))
+++ /dev/null
-# """
-# #
-# Copyright 2016 RIFT.IO Inc
-#
-# 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.
-#
-
-# @file xlate_tags.yml
-# @author Manish Patel (Manish.Patel@riftio.com)
-# @date 01/14/2016
-# """
-
-# This file contains the tags that needs translation
-# One can add some tags with processing limitations by the translation script.
-
-# Add Regular expressions here (connection-points received dynamically from VNFR)
-
-# Translate connection point names (Connection point name is read using RegEx)
-
-xlate_cp_list :
- - <rw_connection_point_name (.*?)>
-
-# Literal string translations
-xlate_str_list :
- - <rw_mgmt_ip>
- - <rw_username>
- - <rw_password>
-
-# This list contains 2 tags separated by colon (:)
-xlate_colon_list :
- # Fetch CP from the member_index dictionary (I.e. CP of a particular VNF)
- - <rw_unique_index:rw_connection_point_name (.*?)>
- # Generate network address from CP address and mask (mask is expected to be a hard coded number in config)
- - <rw_connection_point:masklen_network (.*?)>
- # Generate broadcast address from CP address and mask (mask is expected to be a hard coded number in config)
- - <rw_connection_point:masklen_broadcast (.*?)>
-
-# This list contains 3 tags separated by colon (:)
-xlate_multi_colon_list :
- # Generate network address from CP of a particular VNF (mask is expected to be a hard coded number in config))
- - <rw_unique_index:rw_connection_point:masklen_network (.*?)>
- # Generate broadcast address from CP of a particular VNF (mask is expected to be a hard coded number in config))
- - <rw_unique_index:rw_connection_point:masklen_broadcast (.*?)>
-
-# This translates connection point name and generates tuple with name:resolved IP
-xlate_cp_to_tuple_list :
- - <rw_connection_point_tuple (.*?)>
-
if self._vnfr.vnf_configuration is not None:
vnfr_msg.vnf_configuration.from_dict(self._vnfr.vnf_configuration.as_dict())
- if (ip_address is not None and
- vnfr_msg.vnf_configuration.config_access.mgmt_ip_address is None):
- vnfr_msg.vnf_configuration.config_access.mgmt_ip_address = ip_address
for group in self._vnfr_msg.placement_groups_info:
group_info = VnfrYang.YangData_Vnfr_VnfrCatalog_Vnfr_PlacementGroupsInfo()