def merge_local_require(bindings): """"Merge local require in bindings. This takes a list of bindings, and return a new list of bindings.""" created_bindings = [] removed_bindings = [] merge = [] local = [] # For all bindings, for b in bindings: # if it is a local binding if b.type == "local": # we try to find this provide as a require in an other binding for b1 in bindings: if b1.require_xpath == b.provide_xpath: logger.debug("created bindings %s" % b) created_bindings.append(Binding(b.require_xpath, "external", b1.provide_xpath, b1.arity)) # We create merge information which will be used # for unmerge operation. # We store the port that is merged, the orginal require and the new require. merge.append(("@"+b1.provide_xpath, get_lifecycle(b1.require_xpath), get_lifecycle(b.require_xpath))) removed_bindings.append(b1) # We create a tuple (requirer, provider) of local # require. This will be used to update location of the # local require to be the same than the provider component. local.append((get_lifecycle(b.require_xpath), get_lifecycle(b.provide_xpath))) # Finally, we removed merged bindings for b in bindings: if b not in created_bindings: if b not in removed_bindings: created_bindings.append(b) return (created_bindings, merge, local)
def get_non_local_provide(initial, bindings): """Return the list of lifecycle and state that are not local provide. They will be used by specification. :rtype: [{"component":lifecycle, "state": state}] """ non_local = [] i = initial.xpath non_local.append({"component": get_lifecycle(i), "state": get_state(i)}) for b in bindings: if b.type == "external": non_local.append({"component": get_lifecycle(b.provide_xpath), "state": get_state(b.provide_xpath)}) return non_local
def visualisation_plan(workspace_path): file_replay = workspace_path + "/" + aeolus.common.FILE_ARMONIC_REPLAY_FILLED file_metis_plan = workspace_path + "/" + aeolus.common.FILE_METIS_PLAN_JSON with open(file_replay, 'r') as f: replay = json.load(f) with open(file_metis_plan, 'r') as f: metis_plan = json.load(f) plan = aeolus.launcher.metis_to_armonic(metis_plan, replay) def is_final_state(jid, cpt, plan): # Used to know if a component state change is the last one or not. for p in plan: if p.type == 'state-goto' and p.jid == jid and utils.get_lifecycle(p.xpath) == cpt: return False return True ret = [] for idx, action in enumerate(plan): if type(action) == StateGoto: action.location = action.jid action.component_type = utils.get_lifecycle(action.xpath) action.state = utils.get_state(action.xpath) action.final = is_final_state(action.location, action.component_type, plan[idx+1:]) action.last_one = (idx == len(plan) - 1) else: pass plan.insert(0, Start(len(plan))) plan.append(End()) return plan
def get_component(components, xpath): name = get_lifecycle(xpath) # First, we create components that provide something os = [armonic.utils.OsTypeMBS(), armonic.utils.OsTypeDebian()] lfms = [] for o in os: l = armonic.serialize.Serialize(os_type=o) lf = name state = get_state(xpath) state_xpath = "%s/%s" % (lf, state) path = l.state_goto_path(state_xpath)[0]['paths'] if len(path) > 1: raise Exception("Number of paths to reach %s must not be greather than 1" % state_xpath) if len(path) == 1: lfms.append(l) if len(lfms) > 1: logger.error("%s is available the following OS:" % xpath) for l in lfms: logger.error(" %s" % l.lf_manager.os_type) raise Exception("%s is available on several OS and this is not supported (yet)." % xpath) lfm = lfms[0] c = None for i in components: if i.name == name: c = i break if c is None: c = Component(name, lfm) components.append(c) return c
def test_volume_manifest_spec_from_interface(self): cont = self.getContainerbyName("fake-vol-interface") spec = utils.get_lifecycle(cont, "Kubernetes") test = VolumeManifest("myapp", cont, spec) self.assertEqual( test.resource.get("spec").get("hostPath").get("path"), "getthispath" )
def _get_terraform_interface(self, node): """ Return tosca interfaces for the node """ interfaces = utils.get_lifecycle(node, "Terraform") if not interfaces: logger.debug("No interface for Terraform in {}".format(node.name)) return interfaces
def _node_data_get_interface(self, node): """ Get interface for node from tosca """ interfaces = utils.get_lifecycle(node, "Occopus") if not interfaces: logger.debug("No interface for Occopus in {}".format(node.name)) return interfaces
def create_visualisation_attributes(self): def is_final_state(jid, cpt, actions): # Used to know if a component state change is the last one or not. for p in actions: if p.type == 'state-goto' and p.jid == jid and utils.get_lifecycle(p.xpath) == cpt: return False return True for idx, action in enumerate(self.actions): if type(action) == StateGoto: action.location = action.jid action.component_type = utils.get_lifecycle(action.xpath) action.state = utils.get_state(action.xpath) action.final = is_final_state(action.location, action.component_type, self.actions[idx+1:]) action.last_one = (idx == len(self.actions) - 1) else: pass # Add header and footer used to inform interface deployment has started and is ended self.actions.insert(0, Start(len(self.actions))) self.actions.append(End())
def is_final_state(jid, cpt, actions): # Used to know if a component state change is the last one or not. for p in actions: if p.type == 'state-goto' and p.jid == jid and utils.get_lifecycle(p.xpath) == cpt: return False return True
def test_overwrite_parent_interfaces(self): cont = self.getContainerbyName("overwrite-with-auto") test = utils.get_lifecycle(cont, "Kubernetes") self.assertEqual(test.get("create").get("kind"), "Deployment")
def test_get_parent_interfaces(self): cont = self.getContainerbyName("daemonset-by-auto") test = utils.get_lifecycle(cont, "Kubernetes") self.assertEqual(test.get("create").get("kind"), "DaemonSet")
def test_config_manifest_spec_from_property(self): cont = self.getContainerbyName("fake-config-abst") spec = utils.get_lifecycle(cont, "Kubernetes") test = ConfigMapManifest("myapp", cont, spec) self.assertEqual(test.resource.get("data"), {"datagoes": "here"})
def test_config_manifest_spec_overwrite_from_interface(self): cont = self.getContainerbyName("fake-config") spec = utils.get_lifecycle(cont, "Kubernetes") test = ConfigMapManifest("myapp", cont, spec) self.assertEqual(test.resource.get("binaryData"), {"bingoes": "here"})
def test_volume_manifest_spec_from_property(self): cont = self.getContainerbyName("fake-vol-abst") spec = utils.get_lifecycle(cont, "Kubernetes") test = VolumeManifest("myapp", cont, spec) self.assertEqual(test.resource.get("spec").get("nfs").get("path"), "volinprop")
def test_volume_manifest_spec_overwrite_from_interface(self): cont = self.getContainerbyName("fake-vol-interface") spec = utils.get_lifecycle(cont, "Kubernetes") test = VolumeManifest("myapp", cont, spec) self.assertEqual(len(test.resource.get("spec").get("accessModes")), 1)