-
-class VcsComponent(object):
- """ VCS Component within the VNF descriptor """
- def __init__(self, dts, log, loop, cluster_name, vcs_handler, component, mangled_name):
- self._dts = dts
- self._log = log
- self._loop = loop
- self._component = component
- self._cluster_name = cluster_name
- self._vcs_handler = vcs_handler
- self._mangled_name = mangled_name
-
- @staticmethod
- def mangle_name(component_name, vnf_name, vnfd_id):
- """ mangled component name """
- return vnf_name + ":" + component_name + ":" + vnfd_id
-
- @property
- def name(self):
- """ name of this component"""
- return self._mangled_name
-
- @property
- def path(self):
- """ The path for this object """
- return("D,/rw-manifest:manifest" +
- "/rw-manifest:operational-inventory" +
- "/rw-manifest:component" +
- "[rw-manifest:component-name = '{}']").format(self.name)
-
- @property
- def instance_xpath(self):
- """ The path for this object """
- return("D,/rw-base:vcs" +
- "/instances" +
- "/instance" +
- "[instance-name = '{}']".format(self._cluster_name))
-
- @property
- def start_comp_xpath(self):
- """ start component xpath """
- return (self.instance_xpath +
- "/child-n[instance-name = 'START-REQ']")
-
- def get_start_comp_msg(self, ip_address):
- """ start this component """
- start_msg = RwBaseYang.VcsInstance_Instance_ChildN()
- start_msg.instance_name = 'START-REQ'
- start_msg.component_name = self.name
- start_msg.admin_command = "START"
- start_msg.ip_address = ip_address
-
- return start_msg
-
- @property
- def msg(self):
- """ Returns the message for this vcs component"""
-
- vcs_comp_dict = self._component.as_dict()
-
- def mangle_comp_names(comp_dict):
- """ mangle component name with VNF name, id"""
- for key, val in comp_dict.items():
- if isinstance(val, dict):
- comp_dict[key] = mangle_comp_names(val)
- elif isinstance(val, list):
- i = 0
- for ent in val:
- if isinstance(ent, dict):
- val[i] = mangle_comp_names(ent)
- else:
- val[i] = ent
- i += 1
- elif key == "component_name":
- comp_dict[key] = VcsComponent.mangle_name(val,
- self._vnfd_name,
- self._vnfd_id)
- return comp_dict
-
- mangled_dict = mangle_comp_names(vcs_comp_dict)
- msg = RwManifestYang.OpInventory_Component.from_dict(mangled_dict)
- return msg
-
- @asyncio.coroutine
- def publish(self, xact):
- """ Publishes the VCS component """
- self._log.debug("Publishing the VcsComponent %s, path = %s comp = %s",
- self.name, self.path, self.msg)
- yield from self._vcs_handler.publish(xact, self.path, self.msg)
-
- @asyncio.coroutine
- def start(self, xact, parent, ip_addr=None):
- """ Starts this VCS component """
- # ATTN RV - replace with block add
- start_msg = self.get_start_comp_msg(ip_addr)
- self._log.debug("starting component %s %s",
- self.start_comp_xpath, start_msg)
- yield from self._dts.query_create(self.start_comp_xpath,
- 0,
- start_msg)
- self._log.debug("started component %s, %s",
- self.start_comp_xpath, start_msg)
-
-