def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Disconnecting {0}:{1} from {2}:{3} with ID {4}'.format(\ self._source_path_str, self._source_port, self._dest_path_str, self._dest_port, self._id), file=sys.stderr) source_comp = rtctree.get_node(self._source_path) if not source_comp or not source_comp.is_component: return False, 'Source component missing: {0}'.format(\ self._source_path_str) source_port_obj = source_comp.get_port_by_name(self._source_port) if not source_port_obj: return False, 'Source port missing: {0}:{1}'.format(\ self._source_path_str, self._source_port) dest_comp = rtctree.get_node(self._dest_path) if not dest_comp or not dest_comp.is_component: return False, 'Destination component missing: {0}'.format(\ self._dest_path_str) dest_port_obj = dest_comp.get_port_by_name(self._dest_port) if not dest_port_obj: return False, 'Destination port missing: {0}:{1}'.format(\ self._dest_path_str, self._dest_port) s_conn = source_port_obj.get_connection_by_id(self._id) if not s_conn: return False, 'No connection from {0}:{1} with ID {2}'.format( self._source_path_str, self._source_port, self._id) d_conn = dest_port_obj.get_connection_by_id(self._id) if not d_conn: return False, 'No connection to {0}:{1} with ID {2}'.format( self._dest_path_str, self._dest_port, self._id) s_conn.disconnect() return True, None
def main(argv=None, tree=None): usage = '''Usage: %prog [options] [RTSProfile file] Destroy an RT system using an RTSProfile.''' parser = optparse.OptionParser(usage=usage, version=rtshell.RTSH_VERSION) parser.add_option( '--dry-run', dest='dry_run', action='store_true', default=False, help="Print what will be done but don't actually do anything. \ [Default: %default]") parser.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='Verbose output. [Default: %default]') parser.add_option('-x', '--xml', dest='xml', action='store_true', default=True, help='Use XML input format. [Default: True]') parser.add_option('-y', '--yaml', dest='xml', action='store_false', help='Use YAML input format. [Default: False]') if argv: sys.argv = [sys.argv[0]] + argv try: options, args = parser.parse_args() except optparse.OptionError as e: print('OptionError:', e, file=sys.stderr) return 1 option_store.OptionStore().verbose = options.verbose if not args: profile = None elif len(args) == 1: profile = args[0] else: print(usage, file=sys.stderr) return 1 try: teardown(profile=profile, xml=options.xml, dry_run=options.dry_run, tree=tree) except Exception as e: if options.verbose: traceback.print_exc() print('{0}: {1}'.format(os.path.basename(sys.argv[0]), e), file=sys.stderr) return 1 return 0
def _execute(self, rtctree): if option_store.OptionStore().verbose: print((self._verbose_str, self._path_str, self._ec_id), file=sys.stderr) comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, 'Component missing: {0}'.format(self._path_str) ec_index = comp.get_ec_index(int(self._ec_id)) if ec_index < 0: return False, 'Invalid execution context: {0}'.format(self._ec_id) return self._action_impl(comp, ec_index)
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Setting configuration set "{0}" active on \ component {1}'.format(self._set, self._path_str), file=sys.stderr) comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, 'Component missing: {0}'.format(self._path_str) try: comp.activate_conf_set(self._set) except rts_exceptions.NoConfSetError: return False, 'Invalid configuration set: {0}'.format(self._set) return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Checking configuration set "{0}" is active '\ 'on component {1}'.format(self._set, self._path_str), file=sys.stderr) comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, 'Component missing: {0}'.format(self._path_str) if comp.active_conf_set_name != self._set: return False, 'Wrong configuration set is active on {0} '\ '(Active set: {1})'.format(self._path_str, comp.active_conf_set_name) return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Checking for required port {0} on component \ {1}'.format(self._port_name, self._path_str), file=sys.stderr) # Get the component at the specified path comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return True, None # Check for the port if not comp.has_port_by_name(self._port_name): return False, \ 'Required port not found: {0}'.format(self._port_name) # All good return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Checking for connection between {0}:{1} and ' \ '{2}:{3}'.format(self._source[0], self._source[1], self._dest[0], self._dest[1])) # Get the source component s_comp = rtctree.get_node(self._s_path) if not s_comp or not s_comp.is_component: return False, 'Source component missing: {0}'.format(\ self._source[0]) s_port = s_comp.get_port_by_name(self._source[1]) if not s_port: return False, 'Source port missing: {0}:{1}'.format(\ self._source[0], self._source[1]) # Get the destination component d_comp = rtctree.get_node(self._d_path) if not d_comp or not d_comp.is_component: return False, 'Destination component missing: {0}'.format(\ self._dest[0]) d_port = d_comp.get_port_by_name(self._dest[1]) if not d_port: return False, 'Destination port missing: {0}:{1}'.format(\ self._dest[0], self._dest[1]) conn = s_port.get_connection_by_id(self._id) if not conn: # No connection: fail return False, 'No connection between {0}:{1} and {2}:{3}'.format( self._source[0], self._source[1], self._dest[0], self._dest[1]) conn = d_port.get_connection_by_id(self._id) if not conn: # No connection: fail return False, 'No connection between {0}:{1} and {2}:{3}'.format( self._source[0], self._source[1], self._dest[0], self._dest[1]) # Check the properties for k in self._props: if self._props[k] != conn.properties[k]: return False, 'Property {0} of connection from {1}:{2} to '\ '{3}:{4} is incorrect.'.format(k, self._source[0], self._source[1], self._dest[0], self._dest[1]) # All good return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Checking parameter "{0}" in set "{1}" on '\ 'component "{2}" is "{3}"'.format(self._param, self._set, self._path_str, self._value), file=sys.stderr) comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, 'Component missing: {0}'.format(self._path_str) if not self._set in comp.conf_sets: return False, 'Invalid configuration set: {0}'.format(self._set) if not comp.conf_sets[self._set].has_param(self._param): return False, 'Invalid configuration parameter: '\ '{0}'.format(self._param) if comp.conf_sets[self._set].data[self._param] != self._value: return False, 'Configuration parameter {0} in set {1} on '\ 'component {2} is incorrect (value: {3})'.format( self._param, self._set, self._path_str, comp.conf_sets[self._set].data[self._param]) return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Setting parameter "{0}" in set "{1}" on \ component at path {2} to "{3}"'.format(self._param, self._set, self._path_str, self._new_value), file=sys.stderr) comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, 'Component missing: {0}'.format(self._path_str) try: comp.set_conf_set_value(self._set, self._param, self._new_value) except rts_exceptions.NoConfSetError: return False, 'Invalid configuration set: {0}'.format(self._set) except rtc_exceptions.NoSuchConfParamError: return False, 'Invalid configuration parameter: {0}'.format( self._param) comp.reparse_conf_sets() if self._set == comp.active_conf_set_name: comp.activate_conf_set(self._set) return True, None
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Checking for required component {0} with ID \ "{1}" and instance name "{2}"'.format(self._path_str, self._id, self._instance_name), file=sys.stderr) # Check there is a component at the specified path comp = rtctree.get_node(self._path) if not comp or not comp.is_component: return False, \ 'Required component missing: {0}'.format(self._path_str) # Check the instance names match if comp.instance_name != self._instance_name: return False, 'Component instance names mismatched: {0} != \ {1}'.format(comp.instance_name, self._instance_name) # Check the IDs match - in rtctree, the ID is formed from like so: # 'RTC:'<vendor>:<category>:<type_name>:<version> id = 'RTC:{0}:{1}:{2}:{3}'.format(comp.vendor, comp.category, comp.type_name, comp.version) if id != self._id: return False, 'Component IDs mismatched: {0} != {1}'.format( id, self._id) # All good return True, None
def main(argv=None, tree=None): usage = '''Usage: %prog [options] [name servers] Record a running RT System in an RTSProfile specification.''' parser = optparse.OptionParser(usage=usage, version=rtshell.RTSH_VERSION) parser.add_option('-a', '--abstract', dest='abstract', action='store', type='string', default='RT System created by rtcryo.', help='Brief description of the RT System.') parser.add_option('-n', '--system-name', dest='sysname', action='store', type='string', default='RTSystem', help='Name of the RT System. [Default: %default]') parser.add_option('-o', '--output', dest='output', action='store', type='string', default='-', help='Output file name. [Default: standard out]') parser.add_option('-v', '--system-version', dest='version', action='store', type='string', default='0', help='Version of the RT System. [Default: %default]') parser.add_option('-e', '--vendor', dest='vendor', action='store', type='string', default='Me', help='Vendor of the RT System. [Default: %default]') parser.add_option('-x', '--xml', dest='xml', action='store_true', default=True, help='Use XML output format. [Default: True]') parser.add_option('-y', '--yaml', dest='xml', action='store_false', help='Use YAML output format. [Default: False]') parser.add_option('--verbose', dest='verbose', action='store_true', default=False, help='Verbose output. [Default: %default]') if argv: sys.argv = [sys.argv[0]] + argv try: options, args = parser.parse_args() except optparse.OptionError as e: print('OptionError: ', e, file=sys.stderr) return 1 option_store.OptionStore().verbose = options.verbose try: freeze_dry(args, dest=options.output, xml=options.xml, abstract=options.abstract, vendor=options.vendor, sysname=options.sysname, version=options.version, tree=tree) except Exception as e: if options.verbose: traceback.print_exc() print('{0}: {1}'.format(sys.argv[0], e), file=sys.stderr) return 1 return 0
def _execute(self, rtctree): if option_store.OptionStore().verbose: print('Connect {0}:{1} to {2}:{3} with \ ID {4} and properties {5}'.format(self._source_path_str, self._source_port, self._dest_path_str, self._dest_port, self._id, self._properties), file=sys.stderr) source_comp = rtctree.get_node(self._source_path) if not source_comp or not source_comp.is_component: return False, 'Source component missing: {0}'.format(\ self._source_path_str) s_port = source_comp.get_port_by_name(self._source_port) if not s_port: return False, 'Source port missing: {0}:{1}'.format(\ self._source_path_str, self._source_port) dest_comp = rtctree.get_node(self._dest_path) if not dest_comp or not dest_comp.is_component: return False, 'Destination component missing: {0}'.format(\ self._dest_path_str) d_port = dest_comp.get_port_by_name(self._dest_port) if not d_port: return False, 'Destination port missing: {0}:{1}'.format(\ self._dest_path_str, self._dest_port) conn = s_port.get_connection_by_id(self._id) if not conn: if d_port.get_connection_by_id(self._id) is None: # No existing connection s_port.connect([d_port], name=self._name, id=self._id, props=self._properties) return True, None else: # The destination port has a connection with that ID but # different ports. return False, \ 'Destination port has existing connection with ID {0}'.format( self._id) else: if len(conn.ports) != 2 or not conn.has_port(d_port): # The source port has a connection with that ID but different # ports. return False, \ 'Source port has existing connection with ID {0}'.format( self._id) else: # The connection already exists - check the properties match for k in self._properties: if self._properties[k] != conn.properties[k]: return False, \ 'Property {0} of existing connection from '\ '{1}:{2} to {3}:{4} with ID {5} does not '\ 'match'.format(k, self._source_path_str, self._source_port, self._dest_path_str, self._dest_port, self._id) if option_store.OptionStore().verbose: print('Skipped existing connection with ID {0}'.format( self._id), file=sys.stderr) return True, None