Rename files and fix things.

This commit is contained in:
Devananda van der Veen 2013-05-03 14:01:05 -07:00
parent 05e9ce4c48
commit 0480834614
73 changed files with 487 additions and 391 deletions

5
.gitignore vendored
View File

@ -21,6 +21,7 @@ develop-eggs
.installed.cfg
# Other
*.DS_Store
.testrepository
.tox
.*.swp
@ -28,3 +29,7 @@ develop-eggs
cover
AUTHORS
ChangeLog
.testrepository/
.tox
.venv

6
etc/ironic/policy.json Normal file
View File

@ -0,0 +1,6 @@
{
"admin_api": "is_admin:True",
"admin_or_owner": "is_admin:True or project_id:%(project_id)s",
"context_is_admin": "role:admin",
"default": "rule:admin_or_owner",
}

16
ironic/__init__.py Normal file
View File

@ -0,0 +1,16 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2013 Hewlett-Packard Development Company, L.P.
# 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.

27
ironic/cmd/__init__.py Normal file
View File

@ -0,0 +1,27 @@
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
# 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.
# TODO(mikal): move eventlet imports to ironic.__init__ once we move to PBR
import os
import sys
os.environ['EVENTLET_NO_GREENDNS'] = 'yes'
import eventlet
eventlet.monkey_patch(os=False)
from ironic.openstack.common import gettextutils
gettextutils.install('ironic')

View File

@ -33,7 +33,7 @@ from wsgiref import simple_server
from nova import config
from nova import context as nova_context
from nova import exception
from nova.openstack.common import log as logging
from ironic.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import db

View File

@ -63,8 +63,8 @@ from oslo.config import cfg
gettext.install('nova', unicode=1)
from nova import config
from nova.openstack.common import cliutils
from nova.openstack.common import log as logging
from ironic.openstack.common import cliutils
from ironic.openstack.common import log as logging
from nova import version
from nova.virt.baremetal.db import migration as bmdb_migration

View File

@ -12,4 +12,5 @@
# 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 nova.tests.baremetal import *
from ironic.db.api import *

View File

@ -22,9 +22,9 @@
The underlying driver is loaded as a :class:`LazyPluggable`.
Functions in this module are imported into the nova.virt.baremetal.db
namespace. Call these functions from nova.virt.baremetal.db namespace, not
the nova.virt.baremetal.db.api namespace.
Functions in this module are imported into the ironic.db
namespace. Call these functions from ironic.db namespace, not
the ironic.db.api namespace.
All functions in this module return objects that implement a dictionary-like
interface. Currently, many of these objects are sqlalchemy objects that
@ -34,38 +34,30 @@ these objects be simple dictionaries.
**Related Flags**
:baremetal_db_backend: string to lookup in the list of LazyPluggable backends.
`sqlalchemy` is the only supported backend right now.
:db_backend: string to lookup in the list of LazyPluggable backends.
`sqlalchemy` is the only supported backend right now.
:[BAREMETAL] sql_connection: string specifying the sqlalchemy connection to
use, like: `sqlite:///var/lib/nova/nova.sqlite`.
:sql_connection: string specifying the sqlalchemy connection to
use, like: `sqlite:///var/lib/ironic/ironic.sqlite`.
"""
from oslo.config import cfg
from nova import utils
from ironic import utils
# NOTE(deva): we can't move baremetal_db_backend into an OptGroup yet
# because utils.LazyPluggable doesn't support reading from
# option groups. See bug #1093043.
db_opts = [
cfg.StrOpt('db_backend',
default='sqlalchemy',
help='The backend to use for bare-metal database'),
help='The backend to use for the ironic database'),
]
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(db_opts, baremetal_group)
CONF.register_opts(db_opts)
IMPL = utils.LazyPluggable(
'db_backend',
config_group='baremetal',
sqlalchemy='nova.virt.baremetal.db.sqlalchemy.api')
sqlalchemy='ironic.db.sqlalchemy.api')
def bm_node_get_all(context, service_host=None):

View File

@ -18,13 +18,12 @@
"""Database setup and migration commands."""
from nova import utils
from ironic import utils
IMPL = utils.LazyPluggable(
'db_backend',
config_group='baremetal',
sqlalchemy='nova.virt.baremetal.db.sqlalchemy.migration')
sqlalchemy='ironic.db.sqlalchemy.migration')
INIT_VERSION = 0

View File

@ -28,9 +28,9 @@ from sqlalchemy.sql.expression import literal_column
import nova.context
from nova.db.sqlalchemy import api as sqlalchemy_api
from nova import exception
from nova.openstack.common.db import exception as db_exc
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
from ironic.openstack.common.db import exception as db_exc
from ironic.openstack.common import timeutils
from ironic.openstack.common import uuidutils
from nova.virt.baremetal.db.sqlalchemy import models
from nova.virt.baremetal.db.sqlalchemy import session as db_session

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.openstack.common import log as logging
from ironic.openstack.common import log as logging
from sqlalchemy import and_, MetaData, select, Table, exists
from sqlalchemy import exc

View File

@ -22,9 +22,9 @@ from migrate.versioning import util as migrate_util
import os
import sqlalchemy
from nova import exception
from nova.virt.baremetal.db import migration
from nova.virt.baremetal.db.sqlalchemy import session
from ironic import exception
from ironic.db import migration
from ironic.db.sqlalchemy import session
@migrate_util.decorator

View File

@ -21,7 +21,7 @@
from oslo.config import cfg
from nova.openstack.common.db.sqlalchemy import session as nova_session
from ironic.openstack.common.db.sqlalchemy import session as nova_session
from nova import paths
opts = [
@ -39,7 +39,7 @@ CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(opts, baremetal_group)
CONF.import_opt('sqlite_db', 'nova.openstack.common.db.sqlalchemy.session')
CONF.import_opt('sqlite_db', 'ironic.openstack.common.db.sqlalchemy.session')
_ENGINE = None
_MAKER = None

View File

@ -16,9 +16,9 @@
# License for the specific language governing permissions and limitations
# under the License.
"""Nova base exception handling.
"""Ironic base exception handling.
Includes decorator for re-raising Nova-type exceptions.
Includes decorator for re-raising Ironic-type exceptions.
SHOULD include dedicated exception logging.
@ -27,11 +27,11 @@ SHOULD include dedicated exception logging.
import functools
from oslo.config import cfg
import webob.exc
from nova.openstack.common import excutils
from nova.openstack.common import log as logging
from nova import safe_utils
from ironic.openstack.common import excutils
from ironic.openstack.common import log as logging
from ironic import safe_utils
LOG = logging.getLogger(__name__)
@ -45,14 +45,6 @@ CONF = cfg.CONF
CONF.register_opts(exc_log_opts)
class ConvertedException(webob.exc.WSGIHTTPException):
def __init__(self, code=0, title="", explanation=""):
self.code = code
self.title = title
self.explanation = explanation
super(ConvertedException, self).__init__()
class ProcessExecutionError(IOError):
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
description=None):

View File

@ -12,6 +12,6 @@
# 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 nova.virt.baremetal import driver
from ironic.manager import driver
BareMetalDriver = driver.BareMetalDriver

View File

@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.virt.baremetal import baremetal_states
from ironic import states
class NodeDriver(object):
@ -51,19 +51,19 @@ class NodeDriver(object):
class PowerManager(object):
def __init__(self, **kwargs):
self.state = baremetal_states.DELETED
self.state = states.DELETED
pass
def activate_node(self):
self.state = baremetal_states.ACTIVE
self.state = states.ACTIVE
return self.state
def reboot_node(self):
self.state = baremetal_states.ACTIVE
self.state = states.ACTIVE
return self.state
def deactivate_node(self):
self.state = baremetal_states.DELETED
self.state = states.DELETED
return self.state
def is_power_on(self):

View File

@ -24,14 +24,14 @@ A driver for Bare-metal platform.
from oslo.config import cfg
from nova.compute import power_state
from nova import context as nova_context
from nova import exception
from nova.openstack.common import excutils
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from ironic import context as ironic_context
from ironic import exception
from ironic.openstack.common import excutils
from ironic.openstack.common import importutils
from ironic.openstack.common import log as logging
from nova import paths
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import db
from ironic import states
from ironic import db
from nova.virt import driver
from nova.virt import firewall
from nova.virt.libvirt import imagecache
@ -70,13 +70,9 @@ opts = [
LOG = logging.getLogger(__name__)
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(opts, baremetal_group)
CONF.import_opt('host', 'nova.netconf')
CONF.register_opts(opts)
CONF.import_opt('host', 'ironic.netconf')
DEFAULT_FIREWALL_DRIVER = "%s.%s" % (
firewall.__name__,
@ -107,7 +103,7 @@ def _update_state(context, node, instance, state):
def get_power_manager(**kwargs):
cls = importutils.import_class(CONF.baremetal.power_manager)
cls = importutils.import_class(CONF.power_manager)
return cls(**kwargs)
@ -122,18 +118,18 @@ class BareMetalDriver(driver.ComputeDriver):
super(BareMetalDriver, self).__init__(virtapi)
self.driver = importutils.import_object(
CONF.baremetal.driver, virtapi)
CONF.driver, virtapi)
self.vif_driver = importutils.import_object(
CONF.baremetal.vif_driver)
CONF.vif_driver)
self.firewall_driver = firewall.load_driver(
default=DEFAULT_FIREWALL_DRIVER)
self.volume_driver = importutils.import_object(
CONF.baremetal.volume_driver, virtapi)
CONF.volume_driver, virtapi)
self.image_cache_manager = imagecache.ImageCacheManager()
extra_specs = {}
extra_specs["baremetal_driver"] = CONF.baremetal.driver
for pair in CONF.baremetal.instance_type_extra_specs:
extra_specs["baremetal_driver"] = CONF.driver
for pair in CONF.instance_type_extra_specs:
keyval = pair.split(':', 1)
keyval[0] = keyval[0].strip()
keyval[1] = keyval[1].strip()
@ -234,7 +230,7 @@ class BareMetalDriver(driver.ComputeDriver):
node = db.bm_node_associate_and_update(context, node_uuid,
{'instance_uuid': instance['uuid'],
'instance_name': instance['hostname'],
'task_state': baremetal_states.BUILDING})
'task_state': states.BUILDING})
try:
self._plug_vifs(instance, network_info, context=context)
@ -251,7 +247,7 @@ class BareMetalDriver(driver.ComputeDriver):
self.driver.activate_bootloader(context, node, instance)
self.power_on(instance, node)
self.driver.activate_node(context, node, instance)
_update_state(context, node, instance, baremetal_states.ACTIVE)
_update_state(context, node, instance, states.ACTIVE)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_("Error deploying instance %(instance)s "
@ -261,7 +257,7 @@ class BareMetalDriver(driver.ComputeDriver):
# Do not set instance=None yet. This prevents another
# spawn() while we are cleaning up.
_update_state(context, node, instance, baremetal_states.ERROR)
_update_state(context, node, instance, states.ERROR)
self.driver.deactivate_node(context, node, instance)
self.power_off(instance, node)
@ -272,7 +268,7 @@ class BareMetalDriver(driver.ComputeDriver):
self._stop_firewall(instance, network_info)
self._unplug_vifs(instance, network_info)
_update_state(context, node, None, baremetal_states.DELETED)
_update_state(context, node, None, states.DELETED)
def reboot(self, context, instance, network_info, reboot_type,
block_device_info=None, bad_volumes_callback=None):
@ -280,7 +276,7 @@ class BareMetalDriver(driver.ComputeDriver):
ctx = nova_context.get_admin_context()
pm = get_power_manager(node=node, instance=instance)
state = pm.reboot_node()
if pm.state != baremetal_states.ACTIVE:
if pm.state != states.ACTIVE:
raise exception.InstanceRebootFailure(_(
"Baremetal power manager failed to restart node "
"for instance %r") % instance['uuid'])
@ -306,14 +302,14 @@ class BareMetalDriver(driver.ComputeDriver):
self._stop_firewall(instance, network_info)
self._unplug_vifs(instance, network_info)
_update_state(context, node, None, baremetal_states.DELETED)
_update_state(context, node, None, states.DELETED)
except Exception as e:
with excutils.save_and_reraise_exception():
try:
LOG.error(_("Error from baremetal driver "
"during destroy: %s") % e)
_update_state(context, node, instance,
baremetal_states.ERROR)
states.ERROR)
except Exception:
LOG.error(_("Error while recording destroy failure in "
"baremetal database: %s") % e)
@ -324,7 +320,7 @@ class BareMetalDriver(driver.ComputeDriver):
node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
pm = get_power_manager(node=node, instance=instance)
pm.deactivate_node()
if pm.state != baremetal_states.DELETED:
if pm.state != states.DELETED:
raise exception.InstancePowerOffFailure(_(
"Baremetal power manager failed to stop node "
"for instance %r") % instance['uuid'])
@ -336,7 +332,7 @@ class BareMetalDriver(driver.ComputeDriver):
node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
pm = get_power_manager(node=node, instance=instance)
pm.activate_node()
if pm.state != baremetal_states.ACTIVE:
if pm.state != states.ACTIVE:
raise exception.InstancePowerOnFailure(_(
"Baremetal power manager failed to start node "
"for instance %r") % instance['uuid'])

View File

@ -16,7 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.virt.baremetal import base
from ironic.manager import base
from nova.virt import firewall

View File

@ -27,14 +27,14 @@ import tempfile
from oslo.config import cfg
from nova import exception
from nova.openstack.common import log as logging
from nova.openstack.common import loopingcall
from ironic import exception
from ironic.openstack.common import log as logging
from ironic.openstack.common import loopingcall
from nova import paths
from nova import utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import base
from nova.virt.baremetal import utils as bm_utils
from ironic import utils
from ironic import states
from ironic.manager import base
from ironic import utils as bm_utils
opts = [
cfg.StrOpt('terminal',
@ -51,12 +51,8 @@ opts = [
help='maximal number of retries for IPMI operations'),
]
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(opts, baremetal_group)
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)
@ -71,7 +67,7 @@ def _make_password_file(password):
def _get_console_pid_path(node_id):
name = "%s.pid" % node_id
path = os.path.join(CONF.baremetal.terminal_pid_dir, name)
path = os.path.join(CONF.terminal_pid_dir, name)
return path
@ -149,10 +145,10 @@ class IPMI(base.PowerManager):
"""Called at an interval until the node's power is on."""
if self._is_power("on"):
self.state = baremetal_states.ACTIVE
self.state = states.ACTIVE
raise loopingcall.LoopingCallDone()
if self.retries > CONF.baremetal.ipmi_power_retry:
self.state = baremetal_states.ERROR
if self.retries > CONF.ipmi_power_retry:
self.state = states.ERROR
raise loopingcall.LoopingCallDone()
try:
self.retries += 1
@ -171,10 +167,10 @@ class IPMI(base.PowerManager):
"""Called at an interval until the node's power is off."""
if self._is_power("off"):
self.state = baremetal_states.DELETED
self.state = states.DELETED
raise loopingcall.LoopingCallDone()
if self.retries > CONF.baremetal.ipmi_power_retry:
self.state = baremetal_states.ERROR
if self.retries > CONF.ipmi_power_retry:
self.state = states.ERROR
raise loopingcall.LoopingCallDone()
try:
self.retries += 1
@ -194,7 +190,7 @@ class IPMI(base.PowerManager):
def activate_node(self):
"""Turns the power to node ON."""
if self._is_power("on") and self.state == baremetal_states.ACTIVE:
if self._is_power("on") and self.state == states.ACTIVE:
LOG.warning(_("Activate node called, but node %s "
"is already active") % self.address)
self._set_pxe_for_next_boot()
@ -220,10 +216,10 @@ class IPMI(base.PowerManager):
if not self.port:
return
args = []
args.append(CONF.baremetal.terminal)
if CONF.baremetal.terminal_cert_dir:
args.append(CONF.terminal)
if CONF.terminal_cert_dir:
args.append("-c")
args.append(CONF.baremetal.terminal_cert_dir)
args.append(CONF.terminal_cert_dir)
else:
args.append("-t")
args.append("-p")

View File

@ -26,16 +26,16 @@ import os
from oslo.config import cfg
from nova.compute import instance_types
from nova import exception
from nova.openstack.common.db import exception as db_exc
from nova.openstack.common import fileutils
from nova.openstack.common import log as logging
from nova.openstack.common import loopingcall
from nova.openstack.common import timeutils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import base
from nova.virt.baremetal import db
from nova.virt.baremetal import utils as bm_utils
from ironic import exception
from ironic.openstack.common.db import exception as db_exc
from ironic.openstack.common import fileutils
from ironic.openstack.common import log as logging
from ironic.openstack.common import loopingcall
from ironic.openstack.common import timeutils
from ironic import states
from ironic.manager import base
from ironic import db
from ironic import utils as bm_utils
pxe_opts = [
cfg.StrOpt('deploy_kernel',
@ -43,13 +43,12 @@ pxe_opts = [
cfg.StrOpt('deploy_ramdisk',
help='Default ramdisk image ID used in deployment phase'),
cfg.StrOpt('net_config_template',
default='$pybasedir/nova/virt/baremetal/'
'net-dhcp.ubuntu.template',
default='$pybasedir/ironic/net-dhcp.ubuntu.template',
help='Template file for injected network config'),
cfg.StrOpt('pxe_append_params',
help='additional append parameters for baremetal PXE boot'),
cfg.StrOpt('pxe_config_template',
default='$pybasedir/nova/virt/baremetal/pxe_config.template',
default='$pybasedir/ironic/pxe_config.template',
help='Template file for PXE configuration'),
cfg.IntOpt('pxe_deploy_timeout',
help='Timeout for PXE deployments. Default: 0 (unlimited)',
@ -58,13 +57,9 @@ pxe_opts = [
LOG = logging.getLogger(__name__)
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(pxe_opts, baremetal_group)
CONF.import_opt('use_ipv6', 'nova.netconf')
CONF.register_opts(pxe_opts)
CONF.import_opt('use_ipv6', 'ironic.netconf')
CHEETAH = None
@ -98,11 +93,11 @@ def build_pxe_config(deployment_id, deployment_key, deployment_iscsi_iqn,
'deployment_ari_path': deployment_ari_path,
'aki_path': aki_path,
'ari_path': ari_path,
'pxe_append_params': CONF.baremetal.pxe_append_params,
'pxe_append_params': CONF.pxe_append_params,
}
cheetah = _get_cheetah()
pxe_config = str(cheetah(
open(CONF.baremetal.pxe_config_template).read(),
open(CONF.pxe_config_template).read(),
searchList=[{'pxe_options': pxe_options,
'ROOT': '${ROOT}',
}]))
@ -139,7 +134,7 @@ def build_network_config(network_info):
cheetah = _get_cheetah()
network_config = str(cheetah(
open(CONF.baremetal.net_config_template).read(),
open(CONF.net_config_template).read(),
searchList=[
{'interfaces': interfaces,
'use_ipv6': CONF.use_ipv6,
@ -150,12 +145,12 @@ def build_network_config(network_info):
def get_deploy_aki_id(instance_type):
return instance_type.get('extra_specs', {}).\
get('baremetal:deploy_kernel_id', CONF.baremetal.deploy_kernel)
get('baremetal:deploy_kernel_id', CONF.deploy_kernel)
def get_deploy_ari_id(instance_type):
return instance_type.get('extra_specs', {}).\
get('baremetal:deploy_ramdisk_id', CONF.baremetal.deploy_ramdisk)
get('baremetal:deploy_ramdisk_id', CONF.deploy_ramdisk)
def get_image_dir_path(instance):
@ -170,7 +165,7 @@ def get_image_file_path(instance):
def get_pxe_config_file_path(instance):
"""Generate the path for an instances PXE config file."""
return os.path.join(CONF.baremetal.tftp_root, instance['uuid'], 'config')
return os.path.join(CONF.tftp_root, instance['uuid'], 'config')
def get_partition_sizes(instance):
@ -190,7 +185,7 @@ def get_partition_sizes(instance):
def get_pxe_mac_path(mac):
"""Convert a MAC address into a PXE config file name."""
return os.path.join(
CONF.baremetal.tftp_root,
CONF.tftp_root,
'pxelinux.cfg',
"01-" + mac.replace(":", "-").lower()
)
@ -225,7 +220,7 @@ def get_tftp_image_info(instance, instance_type):
if not uuid:
missing_labels.append(label)
else:
image_info[label][1] = os.path.join(CONF.baremetal.tftp_root,
image_info[label][1] = os.path.join(CONF.tftp_root,
instance['uuid'], label)
if missing_labels:
raise exception.NovaException(_(
@ -250,7 +245,7 @@ class PXE(base.NodeDriver):
def _cache_tftp_images(self, context, instance, image_info):
"""Fetch the necessary kernels and ramdisks for the instance."""
fileutils.ensure_tree(
os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
os.path.join(CONF.tftp_root, instance['uuid']))
LOG.debug(_("Fetching kernel and ramdisk for instance %s") %
instance['name'])
@ -272,7 +267,7 @@ class PXE(base.NodeDriver):
to the appropriate places on local disk.
Both sets of kernel and ramdisk are needed for PXE booting, so these
are stored under CONF.baremetal.tftp_root.
are stored under CONF.tftp_root.
At present, the AMI is cached and certain files are injected.
Debian/ubuntu-specific assumptions are made regarding the injected
@ -444,7 +439,7 @@ class PXE(base.NodeDriver):
bm_utils.unlink_without_raise(get_pxe_mac_path(mac))
bm_utils.rmtree_without_raise(
os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
os.path.join(CONF.tftp_root, instance['uuid']))
def activate_node(self, context, node, instance):
"""Wait for PXE deployment to complete."""
@ -461,23 +456,23 @@ class PXE(base.NodeDriver):
raise loopingcall.LoopingCallDone()
status = row.get('task_state')
if (status == baremetal_states.DEPLOYING
if (status == states.DEPLOYING
and locals['started'] is False):
LOG.info(_("PXE deploy started for instance %s")
% instance['uuid'])
locals['started'] = True
elif status in (baremetal_states.DEPLOYDONE,
baremetal_states.ACTIVE):
elif status in (states.DEPLOYDONE,
states.ACTIVE):
LOG.info(_("PXE deploy completed for instance %s")
% instance['uuid'])
raise loopingcall.LoopingCallDone()
elif status == baremetal_states.DEPLOYFAIL:
elif status == states.DEPLOYFAIL:
locals['error'] = _("PXE deploy failed for instance %s")
except exception.NodeNotFound:
locals['error'] = _("Baremetal node deleted while waiting "
"for deployment of instance %s")
if (CONF.baremetal.pxe_deploy_timeout and
if (CONF.pxe_deploy_timeout and
timeutils.utcnow() > expiration):
locals['error'] = _("Timeout reached while waiting for "
"PXE deploy of instance %s")
@ -485,7 +480,7 @@ class PXE(base.NodeDriver):
raise loopingcall.LoopingCallDone()
expiration = timeutils.utcnow() + datetime.timedelta(
seconds=CONF.baremetal.pxe_deploy_timeout)
seconds=CONF.pxe_deploy_timeout)
timer = loopingcall.FixedIntervalLoopingCall(_wait_for_deploy)
timer.start(interval=1).wait()

View File

@ -25,32 +25,27 @@ import os
from oslo.config import cfg
from nova.compute import instance_types
from nova import exception
from nova.openstack.common.db import exception as db_exc
from nova.openstack.common import fileutils
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import base
from nova.virt.baremetal import db
from nova.virt.baremetal import utils as bm_utils
from ironic import exception
from ironic.openstack.common.db import exception as db_exc
from ironic.openstack.common import fileutils
from ironic.openstack.common import log as logging
from ironic import utils
from ironic import states
from ironic.manager import base
from ironic import db
from ironic import utils as bm_utils
tilera_opts = [
cfg.StrOpt('net_config_template',
default='$pybasedir/nova/virt/baremetal/'
'net-dhcp.ubuntu.template',
default='$pybasedir/ironic/net-dhcp.ubuntu.template',
help='Template file for injected network config'),
]
LOG = logging.getLogger(__name__)
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(tilera_opts, baremetal_group)
CONF.import_opt('use_ipv6', 'nova.netconf')
CONF.register_opts(tilera_opts)
CONF.import_opt('use_ipv6', 'ironic.netconf')
CHEETAH = None
@ -91,7 +86,7 @@ def build_network_config(network_info):
cheetah = _get_cheetah()
network_config = str(cheetah(
open(CONF.baremetal.net_config_template).read(),
open(CONF.net_config_template).read(),
searchList=[
{'interfaces': interfaces,
'use_ipv6': CONF.use_ipv6,
@ -113,7 +108,7 @@ def get_image_file_path(instance):
def get_tilera_nfs_path(node_id):
"""Generate the path for an instances Tilera nfs."""
tilera_nfs_dir = "fs_" + str(node_id)
return os.path.join(CONF.baremetal.tftp_root, tilera_nfs_dir)
return os.path.join(CONF.tftp_root, tilera_nfs_dir)
def get_partition_sizes(instance):
@ -147,7 +142,7 @@ def get_tftp_image_info(instance):
if not uuid:
missing_labels.append(label)
else:
image_info[label][1] = os.path.join(CONF.baremetal.tftp_root,
image_info[label][1] = os.path.join(CONF.tftp_root,
instance['uuid'], label)
if missing_labels:
raise exception.NovaException(_(
@ -173,7 +168,7 @@ class Tilera(base.NodeDriver):
def _cache_tftp_images(self, context, instance, image_info):
"""Fetch the necessary kernels and ramdisks for the instance."""
fileutils.ensure_tree(
os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
os.path.join(CONF.tftp_root, instance['uuid']))
LOG.debug(_("Fetching kernel and ramdisk for instance %s") %
instance['name'])
@ -195,7 +190,7 @@ class Tilera(base.NodeDriver):
to the appropriate places on local disk.
Both sets of kernel and ramdisk are needed for Tilera booting, so these
are stored under CONF.baremetal.tftp_root.
are stored under CONF.tftp_root.
At present, the AMI is cached and certain files are injected.
Debian/ubuntu-specific assumptions are made regarding the injected
@ -335,10 +330,10 @@ class Tilera(base.NodeDriver):
except db_exc.DBError:
pass
if os.path.exists(os.path.join(CONF.baremetal.tftp_root,
if os.path.exists(os.path.join(CONF.tftp_root,
instance['uuid'])):
bm_utils.rmtree_without_raise(
os.path.join(CONF.baremetal.tftp_root, instance['uuid']))
os.path.join(CONF.tftp_root, instance['uuid']))
def _iptables_set(self, node_ip, user_data):
"""Sets security setting (iptables:port) if needed.
@ -346,7 +341,7 @@ class Tilera(base.NodeDriver):
iptables -A INPUT -p tcp ! -s $IP --dport $PORT -j DROP
/tftpboot/iptables_rule script sets iptables rule on the given node.
"""
rule_path = CONF.baremetal.tftp_root + "/iptables_rule"
rule_path = CONF.tftp_root + "/iptables_rule"
if user_data is not None:
open_ip = base64.b64decode(user_data)
utils.execute(rule_path, node_ip, open_ip)
@ -363,14 +358,14 @@ class Tilera(base.NodeDriver):
" while waiting for deploy of %s")
status = row.get('task_state')
if (status == baremetal_states.DEPLOYING and
if (status == states.DEPLOYING and
locals['started'] is False):
LOG.info(_('Tilera deploy started for instance %s')
% instance['uuid'])
locals['started'] = True
elif status in (baremetal_states.DEPLOYDONE,
baremetal_states.BUILDING,
baremetal_states.ACTIVE):
elif status in (states.DEPLOYDONE,
states.BUILDING,
states.ACTIVE):
LOG.info(_("Tilera deploy completed for instance %s")
% instance['uuid'])
node_ip = node['pm_address']
@ -381,7 +376,7 @@ class Tilera(base.NodeDriver):
self.deactivate_bootloader(context, node, instance)
raise exception.NovaException(_("Node is "
"unknown error state."))
elif status == baremetal_states.DEPLOYFAIL:
elif status == states.DEPLOYFAIL:
locals['error'] = _("Tilera deploy failed for instance %s")
except exception.NodeNotFound:
locals['error'] = _("Baremetal node deleted while waiting "

View File

@ -24,11 +24,11 @@ import time
from oslo.config import cfg
from nova import exception
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import base
from ironic import exception
from ironic.openstack.common import log as logging
from ironic import utils
from ironic import states
from ironic.manager import base
opts = [
cfg.StrOpt('tile_pdu_ip',
@ -52,12 +52,8 @@ opts = [
'after tilera power operations'),
]
baremetal_group = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_group)
CONF.register_opts(opts, baremetal_group)
CONF.register_opts(opts)
LOG = logging.getLogger(__name__)
@ -98,56 +94,56 @@ class Pdu(base.PowerManager):
changed. /tftpboot/pdu_mgr script handles power management of
PDU (Power Distribution Unit).
"""
if mode == CONF.baremetal.tile_pdu_status:
if mode == CONF.tile_pdu_status:
try:
utils.execute('ping', '-c1', self.address,
check_exit_code=True)
return CONF.baremetal.tile_pdu_on
return CONF.tile_pdu_on
except exception.ProcessExecutionError:
return CONF.baremetal.tile_pdu_off
return CONF.tile_pdu_off
else:
try:
utils.execute(CONF.baremetal.tile_pdu_mgr,
CONF.baremetal.tile_pdu_ip, mode)
time.sleep(CONF.baremetal.tile_power_wait)
utils.execute(CONF.tile_pdu_mgr,
CONF.tile_pdu_ip, mode)
time.sleep(CONF.tile_power_wait)
return mode
except exception.ProcessExecutionError:
LOG.exception(_("PDU failed"))
def _is_power(self, state):
out_err = self._exec_pdutool(CONF.baremetal.tile_pdu_status)
out_err = self._exec_pdutool(CONF.tile_pdu_status)
return out_err == state
def _power_on(self):
"""Turn the power to this node ON."""
try:
self._exec_pdutool(CONF.baremetal.tile_pdu_on)
if self._is_power(CONF.baremetal.tile_pdu_on):
self.state = baremetal_states.ACTIVE
self._exec_pdutool(CONF.tile_pdu_on)
if self._is_power(CONF.tile_pdu_on):
self.state = states.ACTIVE
else:
self.state = baremetal_states.ERROR
self.state = states.ERROR
except Exception:
self.state = baremetal_states.ERROR
self.state = states.ERROR
LOG.exception(_("PDU power on failed"))
def _power_off(self):
"""Turn the power to this node OFF."""
try:
self._exec_pdutool(CONF.baremetal.tile_pdu_off)
if self._is_power(CONF.baremetal.tile_pdu_off):
self.state = baremetal_states.DELETED
self._exec_pdutool(CONF.tile_pdu_off)
if self._is_power(CONF.tile_pdu_off):
self.state = states.DELETED
else:
self.state = baremetal_states.ERROR
self.state = states.ERROR
except Exception:
self.state = baremetal_states.ERROR
self.state = states.ERROR
LOG.exception(_("PDU power off failed"))
def activate_node(self):
"""Turns the power to node ON."""
if (self._is_power(CONF.baremetal.tile_pdu_on)
and self.state == baremetal_states.ACTIVE):
if (self._is_power(CONF.tile_pdu_on)
and self.state == states.ACTIVE):
LOG.warning(_("Activate node called, but node %s "
"is already active") % self.address)
self._power_on()
@ -165,7 +161,7 @@ class Pdu(base.PowerManager):
return self.state
def is_power_on(self):
return self._is_power(CONF.baremetal.tile_pdu_on)
return self._is_power(CONF.tile_pdu_on)
def start_console(self):
pass

View File

@ -19,7 +19,7 @@ import errno
import os
import shutil
from nova.openstack.common import log as logging
from ironic.openstack.common import log as logging
from nova.virt.disk import api as disk_api
from nova.virt.libvirt import utils as libvirt_utils

View File

@ -15,10 +15,10 @@
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
from ironic import context as nova_context
from ironic import exception
from ironic.openstack.common import log as logging
from ironic import db
CONF = cfg.CONF
@ -38,15 +38,15 @@ class BareMetalVIFDriver(object):
% {'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'])
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 = bmdb.bm_interface_get_all_by_bm_node_id(ctx, node['id'])
pifs = db.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)
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)
@ -64,10 +64,10 @@ class BareMetalVIFDriver(object):
{'uuid': instance['uuid'], 'vif': vif})
network, mapping = vif
vif_uuid = mapping['vif_uuid']
ctx = context.get_admin_context()
ctx = nova_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)
pif = db.bm_interface_get_by_vif_uuid(ctx, vif_uuid)
db.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)

View File

@ -19,14 +19,14 @@
from oslo.config import cfg
from nova import context as nova_context
from nova import exception
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova import utils
from nova.virt.baremetal import baremetal_states
from nova.virt.baremetal import base
from nova.virt.baremetal import db
from ironic import context as nova_context
from ironic import exception
from ironic.openstack.common import importutils
from ironic.openstack.common import log as logging
from ironic import utils
from ironic import states
from ironic.manager import base
from ironic import db
import nova.virt.powervm.common as connection
opts = [
@ -51,12 +51,8 @@ opts = [
]
baremetal_vp = cfg.OptGroup(name='baremetal',
title='Baremetal Options')
CONF = cfg.CONF
CONF.register_group(baremetal_vp)
CONF.register_opts(opts, baremetal_vp)
CONF.register_opts(opts)
_conn = None
_virtual_power_settings = None
@ -89,9 +85,9 @@ class VirtualPowerManager(base.PowerManager):
if _cmds is None:
LOG.debug("Setting up %s commands." %
CONF.baremetal.virtual_power_type)
_vpc = 'nova.virt.baremetal.virtual_power_driver_settings.%s' % \
CONF.baremetal.virtual_power_type
CONF.virtual_power_type)
_vpc = 'ironic.virtual_power_driver_settings.%s' % \