def service_connection_actions(rtsprofile): # The ports on those components in any required connections must also be # present. checks = [] make_connections = [] for conn in rtsprofile.required_service_connections(): source_comp = rtsprofile.find_comp_by_target(conn.source_service_port) source_path = '/' + source_comp.path_uri source_port = conn.source_service_port.port_name prefix = source_comp.instance_name + '.' if source_port.startswith(prefix): source_port = source_port[len(prefix):] dest_comp = rtsprofile.find_comp_by_target(conn.target_service_port) dest_path = '/' + dest_comp.path_uri dest_port = conn.target_service_port.port_name prefix = dest_comp.instance_name + '.' if dest_port.startswith(prefix): dest_port = dest_port[len(prefix):] checks.append( actions.CheckForPortAct(source_path, source_port, callbacks=[actions.RequiredActionCB()])) checks.append( actions.CheckForPortAct(dest_path, dest_port, callbacks=[actions.RequiredActionCB()])) make_connections.append( actions.ConnectPortsAct(source_path, source_port, dest_path, dest_port, str(conn.name), str(conn.connector_id), {}, callbacks=[actions.RequiredActionCB()])) # Add the other connections to the list for conn in rtsprofile.optional_service_connections(): source_comp = rtsprofile.find_comp_by_target(conn.source_service_port) source_path = '/' + source_comp.path_uri source_port = conn.source_service_port.port_name prefix = source_comp.instance_name + '.' if source_port.startswith(prefix): source_port = source_port[len(prefix):] dest_comp = rtsprofile.find_comp_by_target(conn.target_service_port) dest_path = '/' + dest_comp.path_uri dest_port = conn.target_service_port.port_name prefix = dest_comp.instance_name + '.' if dest_port.startswith(prefix): dest_port = dest_port[len(prefix):] make_connections.append( actions.ConnectPortsAct(source_path, source_port, dest_path, dest_port, str(conn.name), str(conn.connector_id), {})) return checks, make_connections
def check_required_component_actions(rtsprofile): checks = [] # First perform a sanity check of the system. # All required components must be present for comp in [c for c in rtsprofile.components if c.is_required]: checks.append(actions.CheckForRequiredCompAct('/' + comp.path_uri, comp.id, comp.instance_name, callbacks=[actions.RequiredActionCB()])) return checks
def activate_actions(rtsprofile): checks = check_required_component_actions(rtsprofile) activates = [] for comp in [c for c in rtsprofile.components if c.is_required]: for ec in comp.execution_contexts: activates.append(actions.ActivateCompAct('/' + comp.path_uri, comp.id, comp.instance_name, ec.id, callbacks=[actions.RequiredActionCB()])) for comp in [c for c in rtsprofile.components if not c.is_required]: for ec in comp.execution_contexts: activates.append(actions.ActivateCompAct('/' + comp.path_uri, comp.id, comp.instance_name, ec.id)) return checks, activates