Beispiel #1
0
    def plug(self, instance, vif):
        LOG.debug(
            _("plug: instance_uuid=%(uuid)s vif=%(vif)s") % {
                'uuid': instance['uuid'],
                'vif': vif
            })
        network, mapping = vif
        vif_uuid = mapping['vif_uuid']
        ctx = nova_context.get_admin_context()
        node = db.bm_node_get_by_instance_uuid(ctx, instance['uuid'])

        # TODO(deva): optimize this database query
        #             this is just searching for a free physical interface
        pifs = db.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
        for pif in pifs:
            if not pif['vif_uuid']:
                db.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
                LOG.debug(
                    _("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)") % {
                        'id': pif['id'],
                        'vif_uuid': vif_uuid
                    })
                self._after_plug(instance, network, mapping, pif)
                return

        # NOTE(deva): should this really be raising an exception
        #             when there are no physical interfaces left?
        raise exception.NovaException(
            _("Baremetal node: %(id)s has no available physical interface"
              " for virtual interface %(vif_uuid)s") % {
                  'id': node['id'],
                  'vif_uuid': vif_uuid
              })
Beispiel #2
0
    def plug(self, instance, vif):
        LOG.debug(_("plug: instance_uuid=%(uuid)s vif=%(vif)s")
                  % {'uuid': instance['uuid'], 'vif': vif})
        network, mapping = vif
        vif_uuid = mapping['vif_uuid']
        ctx = nova_context.get_admin_context()
        node = db.bm_node_get_by_instance_uuid(ctx, instance['uuid'])

        # TODO(deva): optimize this database query
        #             this is just searching for a free physical interface
        pifs = db.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
        for pif in pifs:
            if not pif['vif_uuid']:
                db.bm_interface_set_vif_uuid(ctx, pif['id'], vif_uuid)
                LOG.debug(_("pif:%(id)s is plugged (vif_uuid=%(vif_uuid)s)")
                          % {'id': pif['id'], 'vif_uuid': vif_uuid})
                self._after_plug(instance, network, mapping, pif)
                return

        # NOTE(deva): should this really be raising an exception
        #             when there are no physical interfaces left?
        raise exception.NovaException(_(
                "Baremetal node: %(id)s has no available physical interface"
                " for virtual interface %(vif_uuid)s")
                % {'id': node['id'], 'vif_uuid': vif_uuid})
Beispiel #3
0
 def _plug_vifs(self, instance, network_info, context=None):
     if not context:
         context = nova_context.get_admin_context()
     node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
     if node:
         pifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
         for pif in pifs:
             if pif['vif_uuid']:
                 db.bm_interface_set_vif_uuid(context, pif['id'], None)
     for (network, mapping) in network_info:
         self.vif_driver.plug(instance, (network, mapping))
Beispiel #4
0
 def _plug_vifs(self, instance, network_info, context=None):
     if not context:
         context = nova_context.get_admin_context()
     node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
     if node:
         pifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
         for pif in pifs:
             if pif['vif_uuid']:
                 db.bm_interface_set_vif_uuid(context, pif['id'], None)
     for (network, mapping) in network_info:
         self.vif_driver.plug(instance, (network, mapping))
Beispiel #5
0
    def __init__(self, **kwargs):
        global _conn
        global _virtual_power_settings
        global _cmds

        if _cmds is None:
            LOG.debug("Setting up %s commands." % CONF.virtual_power_type)
            _vpc = "ironic.virtual_power_driver_settings.%s" % CONF.virtual_power_type
            _cmds = importutils.import_class(_vpc)
        self._vp_cmd = _cmds()
        self.connection_data = _conn
        node = kwargs.pop("node", {})
        instance = kwargs.pop("instance", {})
        self._node_name = instance.get("hostname", "")
        context = nova_context.get_admin_context()
        ifs = db.bm_interface_get_all_by_bm_node_id(context, node["id"])
        self._mac_addresses = [_normalize_mac(i["address"]) for i in ifs]
        self._connection = None
        self._matched_name = ""
        self.state = None
Beispiel #6
0
    def __init__(self, **kwargs):
        global _conn
        global _virtual_power_settings
        global _cmds

        if _cmds is None:
            LOG.debug("Setting up %s commands." %
                    CONF.virtual_power_type)
            _vpc = 'ironic.virtual_power_driver_settings.%s' % \
                    CONF.virtual_power_type
            _cmds = importutils.import_class(_vpc)
        self._vp_cmd = _cmds()
        self.connection_data = _conn
        node = kwargs.pop('node', {})
        instance = kwargs.pop('instance', {})
        self._node_name = instance.get('hostname', "")
        context = nova_context.get_admin_context()
        ifs = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
        self._mac_addresses = [_normalize_mac(i['address']) for i in ifs]
        self._connection = None
        self._matched_name = ''
        self.state = None
Beispiel #7
0
 def _collect_mac_addresses(self, context, node):
     macs = set()
     for nic in db.bm_interface_get_all_by_bm_node_id(context, node['id']):
         if nic['address']:
             macs.add(nic['address'])
     return sorted(macs)
Beispiel #8
0
 def macs_for_instance(self, instance):
     context = nova_context.get_admin_context()
     node_uuid = self._require_node(instance)
     node = db.bm_node_get_by_node_uuid(context, node_uuid)
     ifaces = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
     return set(iface['address'] for iface in ifaces)
Beispiel #9
0
 def macs_for_instance(self, instance):
     context = nova_context.get_admin_context()
     node_uuid = self._require_node(instance)
     node = db.bm_node_get_by_node_uuid(context, node_uuid)
     ifaces = db.bm_interface_get_all_by_bm_node_id(context, node['id'])
     return set(iface['address'] for iface in ifaces)