Exemple #1
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >> sys.stderr, '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)
        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 >>sys.stderr, \
                            'Skipped existing connection with ID {0}'.format(
                                    self._id)
                return True, None
Exemple #2
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >>sys.stderr, \
                    '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)
        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
Exemple #3
0
 def _execute(self, rtctree):
     if option_store.OptionStore().verbose:
         print >> sys.stderr, '{0} {1} in {2}'.format(
             self._verbose_str, self._path_str, self._ec_id)
     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)
Exemple #4
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >> sys.stderr, 'Setting configuration set "{0}" active on \
component {1}'.format(self._set, self._path_str)
        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
Exemple #5
0
 def _execute(self, rtctree):
     if option_store.OptionStore().verbose:
         print >>sys.stderr, 'Checking configuration set "{0}" is active '\
                 'on component {1}'.format(self._set, self._path_str)
     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
Exemple #6
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >> sys.stderr, 'Checking for required port {0} on component \
{1}'.format(self._port_name, self._path_str)
        # 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
Exemple #7
0
    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
Exemple #8
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >>sys.stderr, 'Setting parameter "{0}" in set "{1}" on \
component at path {2} to "{3}"'.format(self._param, self._set,
                    self._path_str, self._new_value)
        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 rts_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
Exemple #9
0
 def _execute(self, rtctree):
     if option_store.OptionStore().verbose:
         print >>sys.stderr, 'Checking parameter "{0}" in set "{1}" on '\
                 'component "{2}" is "{3}"'.format(self._param, self._set,
                         self._path_str, self._value)
     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
Exemple #10
0
    def _execute(self, rtctree):
        if option_store.OptionStore().verbose:
            print >> sys.stderr, 'Checking for required component {0} with ID \
"{1}" and instance name "{2}"'.format(self._path_str, self._id,
                                      self._instance_name)
        # 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
Exemple #11
0
                      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, e:
        print >> sys.stderr, 'OptionError: ', e
        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, e:
        if options.verbose:
            traceback.print_exc()
        print >> sys.stderr, '{0}: {1}'.format(sys.argv[0], e)
        return 1