Example #1
0
    def get_port_tag_dict(self):
        """Get a dict of port names and associated vlan tags.

        e.g. the returned dict is of the following form::

            {u'int-br-eth2': [],
             u'patch-tun': [],
             u'qr-76d9e6b6-21': 1,
             u'tapce5318ff-78': 1,
             u'tape1400310-e6': 1}

        The TAG ID is only available in the "Port" table and is not available
        in the "Interface" table queried by the get_vif_port_set() method.

        """
        port_names = self.get_port_name_list()
        args = ['--format=json', '--', '--columns=name,tag', 'list', 'Port']
        result = self.run_vsctl(args, check_error=True)
        port_tag_dict = {}
        if not result:
            return port_tag_dict
        for name, tag in utils.loads(result)['data']:
            if name not in port_names:
                continue
            # 'tag' can be [u'set', []] or an integer
            if isinstance(tag, list):
                tag = tag[1]
            port_tag_dict[name] = tag
        return port_tag_dict
Example #2
0
    def get_port_qos_dict(self):

        """Get a dict of port names and associated qos.
        e.g. the returned dict of the following form::
            {u'int-br-eth2': [],
             u'patch-tun': [],
             u'tapce5318ff-78': 6ab0474a-055e-4978-8c1e-bb7a558973b5}

        The QOS ID is only available in the "Port" table and is not available
        in the "Interface" table queried by the get_vif_port_set() method.

        """
        port_names = self.get_port_name_list()
        args = ['--format=json', '--', '--columns=name,qos', 'list', 'Port']
        result = self.run_vsctl(args, check_error=True)
        port_qos_dict = {}
        if not result:
            return port_qos_dict
        for name, qos in utils.loads(result)['data']:
            if name not in port_names:
                continue
            if isinstance(qos, list):
                qos = qos[1]
            port_qos_dict[name] = qos
        return port_qos_dict
Example #3
0
    def get_queue_dict(self):

        """Get a dict of qos _uuid and associated queues.
        e.g. the returned dict of the following form:
        {u'6ab0474a-055e-4978-8c1e-bb7a558973b5':
        queues: {1=c6f5cb29-4cd7-4e70-a183-21e80cc85ac5}}
        """
        args = ['--format=json', '--', '--columns=_uuid,queues', 'list', 'QoS']
        result = self.run_vsctl(args, check_error=True)
        queue_dict = {}
        if not result:
            return queue_dict
        for _uuid, queues in utils.loads(result)['data']:
            #queue = [u'map', [[1, [u'uuid', u'1c1237ac-5450-40fb-aa06-339b847d7e6e']]]]
            if isinstance(queues, list) and isinstance(_uuid, list):
                queue_dict[_uuid[1]] = queues[1][0][1][1]
        return queue_dict
Example #4
0
 def get_vif_port_by_id(self, port_id):
     args = ['--format=json', '--', '--columns=external_ids,name,ofport',
             'find', 'Interface',
             'external_ids:iface-id="%s"' % port_id]
     result = self.run_vsctl(args)
     if not result:
         return
     json_result = utils.loads(result)
     try:
         # Retrieve the indexes of the columns we're looking for
         headings = json_result['headings']
         ext_ids_idx = headings.index('external_ids')
         name_idx = headings.index('name')
         ofport_idx = headings.index('ofport')
         # If data attribute is missing or empty the line below will raise
         # an exeception which will be captured in this block.
         # We won't deal with the possibility of ovs-vsctl return multiple
         # rows since the interface identifier is unique
         data = json_result['data'][0]
         port_name = data[name_idx]
         switch = get_bridge_for_iface(port_name)
         if switch != self.br_name:
             LOG.info(_("Port: %(port_name)s is on %(switch)s,"
                        " not on %(br_name)s"), {'port_name': port_name,
                                                 'switch': switch,
                                                 'br_name': self.br_name})
             return
         ofport = data[ofport_idx]
         # ofport must be integer otherwise return None
         if not isinstance(ofport, int) or ofport == -1:
             LOG.warn(_("ofport: %(ofport)s for VIF: %(vif)s is not a "
                        "positive integer"), {'ofport': ofport,
                                              'vif': port_id})
             return
         # Find VIF's mac address in external ids
         ext_id_dict = dict((item[0], item[1]) for item in
                            data[ext_ids_idx][1])
         vif_mac = ext_id_dict['attached-mac']
         return VifPort(port_name, ofport, port_id, vif_mac, self)
     except Exception as e:
         LOG.warn(_("Unable to parse interface details. Exception: %s"), e)
         return
Example #5
0
 def get_vif_port_set(self):
     port_names = self.get_port_name_list()
     edge_ports = set()
     args = ['--format=json', '--', '--columns=name,external_ids,ofport',
             'list', 'Interface']
     result = self.run_vsctl(args, check_error=True)
     if not result:
         return edge_ports
     for row in utils.loads(result)['data']:
         name = row[0]
         if name not in port_names:
             continue
         external_ids = dict(row[1][1])
         # Do not consider VIFs which aren't yet ready
         # This can happen when ofport values are either [] or ["set", []]
         # We will therefore consider only integer values for ofport
         ofport = row[2]
         try:
             int_ofport = int(ofport)
         except (ValueError, TypeError):
             LOG.warn(_("Found not yet ready openvswitch port: %s"), row)
         else:
             if int_ofport > 0:
                 if ("iface-id" in external_ids and
                     "attached-mac" in external_ids):
                     edge_ports.add(external_ids['iface-id'])
                 elif ("xs-vif-uuid" in external_ids and
                       "attached-mac" in external_ids):
                     # if this is a xenserver and iface-id is not
                     # automatically synced to OVS from XAPI, we grab it
                     # from XAPI directly
                     iface_id = self.get_xapi_iface_id(
                         external_ids["xs-vif-uuid"])
                     edge_ports.add(iface_id)
             else:
                 LOG.warn(_("Found failed openvswitch port: %s"), row)
     return edge_ports