af276eb0b2
The cfg API is now available via the oslo-config library, so switch to it and remove the copied-and-pasted version. Add the 2013.1b4 tarball to tools/pip-requires - this will be changed to 'oslo-config>=2013.1' when oslo-config is published to pypi. This will happen in time for grizzly final. Add dependency_links to setup.py so that oslo-config can be installed from the tarball URL specified in pip-requires. Remove the 'deps = pep8==1.3.3' from tox.ini as it means all the other deps get installed with easy_install which can't install oslo-config from the URL. Make tools/hacking.py include oslo in IMPORT_EXCEPTIONS like it already does for paste. It turns out imp.find_module() doesn't correct handle namespace packages. Retain dummy cfg.py file until keystoneclient middleware has been updated (I18c450174277c8e2d15ed93879da6cd92074c27a). Change-Id: I4815aeb8a9341a31a250e920157f15ee15cfc5bc
76 lines
3.0 KiB
Python
76 lines
3.0 KiB
Python
# Copyright (c) 2012 NTT DOCOMO, INC.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from oslo.config import cfg
|
|
|
|
from nova import context
|
|
from nova import exception
|
|
from nova.openstack.common import log as logging
|
|
from nova.virt.baremetal import db as bmdb
|
|
|
|
CONF = cfg.CONF
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class BareMetalVIFDriver(object):
|
|
|
|
def _after_plug(self, instance, network, mapping, pif):
|
|
pass
|
|
|
|
def _after_unplug(self, instance, network, mapping, pif):
|
|
pass
|
|
|
|
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 = context.get_admin_context()
|
|
node = bmdb.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 = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
|
|
for pif in pifs:
|
|
if not pif['vif_uuid']:
|
|
bmdb.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})
|
|
|
|
def unplug(self, instance, vif):
|
|
LOG.debug(_("unplug: instance_uuid=%(uuid)s vif=%(vif)s"),
|
|
{'uuid': instance['uuid'], 'vif': vif})
|
|
network, mapping = vif
|
|
vif_uuid = mapping['vif_uuid']
|
|
ctx = context.get_admin_context()
|
|
try:
|
|
pif = bmdb.bm_interface_get_by_vif_uuid(ctx, vif_uuid)
|
|
bmdb.bm_interface_set_vif_uuid(ctx, pif['id'], None)
|
|
LOG.debug(_("pif:%(id)s is unplugged (vif_uuid=%(vif_uuid)s)")
|
|
% {'id': pif['id'], 'vif_uuid': vif_uuid})
|
|
self._after_unplug(instance, network, mapping, pif)
|
|
except exception.NovaException:
|
|
LOG.warn(_("no pif for vif_uuid=%s") % vif_uuid)
|