summaryrefslogtreecommitdiff
path: root/nova/virt
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2013-01-25 12:10:16 -0500
committerJoe Gordon <jogo@cloudscaling.com>2013-01-25 12:11:54 -0500
commit8f394ee71619f099de45e8c33455c141c2f33286 (patch)
tree2a412967fd8fcf1e9d9ec1759d74184e0024a30f /nova/virt
parentf9012e39ee5582192db9289d34df3adaddda2ad1 (diff)
downloadnova-8f394ee71619f099de45e8c33455c141c2f33286.tar.gz
Enable N302: Import modules only
Fix all N302 issues, and re-enable. Change-Id: Ic94d144c915b228b7ff2fd9c5951875e159ffcdd
Diffstat (limited to 'nova/virt')
-rw-r--r--nova/virt/baremetal/__init__.py4
-rw-r--r--nova/virt/baremetal/db/sqlalchemy/api.py71
-rw-r--r--nova/virt/baremetal/db/sqlalchemy/migration.py15
-rw-r--r--nova/virt/baremetal/fake.py4
-rw-r--r--nova/virt/baremetal/ipmi.py14
-rw-r--r--nova/virt/baremetal/pxe.py3
-rw-r--r--nova/virt/libvirt/__init__.py4
-rw-r--r--nova/virt/powervm/__init__.py4
-rw-r--r--nova/virt/vmwareapi/__init__.py4
-rw-r--r--nova/virt/xenapi/__init__.py4
10 files changed, 71 insertions, 56 deletions
diff --git a/nova/virt/baremetal/__init__.py b/nova/virt/baremetal/__init__.py
index e3ecef8215..9c8318660f 100644
--- a/nova/virt/baremetal/__init__.py
+++ b/nova/virt/baremetal/__init__.py
@@ -12,4 +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.driver import BareMetalDriver
+from nova.virt.baremetal import driver
+
+BareMetalDriver = driver.BareMetalDriver
diff --git a/nova/virt/baremetal/db/sqlalchemy/api.py b/nova/virt/baremetal/db/sqlalchemy/api.py
index e2240053c5..34bcd12290 100644
--- a/nova/virt/baremetal/db/sqlalchemy/api.py
+++ b/nova/virt/baremetal/db/sqlalchemy/api.py
@@ -23,14 +23,13 @@
from sqlalchemy.sql.expression import asc
from sqlalchemy.sql.expression import literal_column
-from nova.db.sqlalchemy.api import is_user_context
-from nova.db.sqlalchemy.api import require_admin_context
+from nova.db.sqlalchemy import api as sqlalchemy_api
from nova import exception
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
from nova.virt.baremetal.db.sqlalchemy import models
-from nova.virt.baremetal.db.sqlalchemy.session import get_session
+from nova.virt.baremetal.db.sqlalchemy import session as db_session
LOG = logging.getLogger(__name__)
@@ -44,7 +43,7 @@ def model_query(context, *args, **kwargs):
:param project_only: if present and context is user-type, then restrict
query to match the context's project_id.
"""
- session = kwargs.get('session') or get_session()
+ session = kwargs.get('session') or db_session.get_session()
read_deleted = kwargs.get('read_deleted') or context.read_deleted
project_only = kwargs.get('project_only')
@@ -60,7 +59,7 @@ def model_query(context, *args, **kwargs):
raise Exception(
_("Unrecognized read_deleted value '%s'") % read_deleted)
- if project_only and is_user_context(context):
+ if project_only and sqlalchemy_api.is_user_context(context):
query = query.filter_by(project_id=context.project_id)
return query
@@ -68,7 +67,7 @@ def model_query(context, *args, **kwargs):
def _save(ref, session=None):
if not session:
- session = get_session()
+ session = db_session.get_session()
# We must not call ref.save() with session=None, otherwise NovaBase
# uses nova-db's session, which cannot access bm-db.
ref.save(session=session)
@@ -81,7 +80,7 @@ def _build_node_order_by(query):
return query
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_get_all(context, service_host=None):
query = model_query(context, models.BareMetalNode, read_deleted="no")
if service_host:
@@ -89,7 +88,7 @@ def bm_node_get_all(context, service_host=None):
return query.all()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_find_free(context, service_host=None,
cpus=None, memory_mb=None, local_gb=None):
query = model_query(context, models.BareMetalNode, read_deleted="no")
@@ -106,7 +105,7 @@ def bm_node_find_free(context, service_host=None,
return query.first()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_get(context, bm_node_id):
# bm_node_id may be passed as a string. Convert to INT to improve DB perf.
bm_node_id = int(bm_node_id)
@@ -120,7 +119,7 @@ def bm_node_get(context, bm_node_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_get_by_instance_uuid(context, instance_uuid):
if not uuidutils.is_uuid_like(instance_uuid):
raise exception.InstanceNotFound(instance_id=instance_uuid)
@@ -135,7 +134,7 @@ def bm_node_get_by_instance_uuid(context, instance_uuid):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_create(context, values):
bm_node_ref = models.BareMetalNode()
bm_node_ref.update(values)
@@ -143,14 +142,14 @@ def bm_node_create(context, values):
return bm_node_ref
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_update(context, bm_node_id, values):
model_query(context, models.BareMetalNode, read_deleted="no").\
filter_by(id=bm_node_id).\
update(values)
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_set_uuid_safe(context, bm_node_id, values):
"""Associate an instance to a node safely
@@ -164,7 +163,7 @@ def bm_node_set_uuid_safe(context, bm_node_id, values):
raise exception.NovaException(_(
"instance_uuid must be supplied to bm_node_set_uuid_safe"))
- session = get_session()
+ session = db_session.get_session()
with session.begin():
query = model_query(context, models.BareMetalNode,
session=session, read_deleted="no").\
@@ -181,7 +180,7 @@ def bm_node_set_uuid_safe(context, bm_node_id, values):
return ref
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_node_destroy(context, bm_node_id):
model_query(context, models.BareMetalNode).\
filter_by(id=bm_node_id).\
@@ -190,13 +189,13 @@ def bm_node_destroy(context, bm_node_id):
'updated_at': literal_column('updated_at')})
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_get_all(context):
query = model_query(context, models.BareMetalPxeIp, read_deleted="no")
return query.all()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_create(context, address, server_address):
ref = models.BareMetalPxeIp()
ref.address = address
@@ -205,7 +204,7 @@ def bm_pxe_ip_create(context, address, server_address):
return ref
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_create_direct(context, bm_pxe_ip):
ref = bm_pxe_ip_create(context,
address=bm_pxe_ip['address'],
@@ -213,7 +212,7 @@ def bm_pxe_ip_create_direct(context, bm_pxe_ip):
return ref
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_destroy(context, ip_id):
# Delete physically since it has unique columns
model_query(context, models.BareMetalPxeIp, read_deleted="no").\
@@ -221,7 +220,7 @@ def bm_pxe_ip_destroy(context, ip_id):
delete()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_destroy_by_address(context, address):
# Delete physically since it has unique columns
model_query(context, models.BareMetalPxeIp, read_deleted="no").\
@@ -229,7 +228,7 @@ def bm_pxe_ip_destroy_by_address(context, address):
delete()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_get(context, ip_id):
result = model_query(context, models.BareMetalPxeIp, read_deleted="no").\
filter_by(id=ip_id).\
@@ -238,7 +237,7 @@ def bm_pxe_ip_get(context, ip_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_get_by_bm_node_id(context, bm_node_id):
result = model_query(context, models.BareMetalPxeIp, read_deleted="no").\
filter_by(bm_node_id=bm_node_id).\
@@ -250,9 +249,9 @@ def bm_pxe_ip_get_by_bm_node_id(context, bm_node_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_associate(context, bm_node_id):
- session = get_session()
+ session = db_session.get_session()
with session.begin():
# Check if the node really exists
node_ref = model_query(context, models.BareMetalNode,
@@ -288,14 +287,14 @@ def bm_pxe_ip_associate(context, bm_node_id):
return ip_ref.id
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_pxe_ip_disassociate(context, bm_node_id):
model_query(context, models.BareMetalPxeIp, read_deleted="no").\
filter_by(bm_node_id=bm_node_id).\
update({'bm_node_id': None})
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_get(context, if_id):
result = model_query(context, models.BareMetalInterface,
read_deleted="no").\
@@ -309,14 +308,14 @@ def bm_interface_get(context, if_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_get_all(context):
query = model_query(context, models.BareMetalInterface,
read_deleted="no")
return query.all()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_destroy(context, if_id):
# Delete physically since it has unique columns
model_query(context, models.BareMetalInterface, read_deleted="no").\
@@ -324,7 +323,7 @@ def bm_interface_destroy(context, if_id):
delete()
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_create(context, bm_node_id, address, datapath_id, port_no):
ref = models.BareMetalInterface()
ref.bm_node_id = bm_node_id
@@ -335,9 +334,9 @@ def bm_interface_create(context, bm_node_id, address, datapath_id, port_no):
return ref.id
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_set_vif_uuid(context, if_id, vif_uuid):
- session = get_session()
+ session = db_session.get_session()
with session.begin():
bm_interface = model_query(context, models.BareMetalInterface,
read_deleted="no", session=session).\
@@ -361,7 +360,7 @@ def bm_interface_set_vif_uuid(context, if_id, vif_uuid):
raise e
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_get_by_vif_uuid(context, vif_uuid):
result = model_query(context, models.BareMetalInterface,
read_deleted="no").\
@@ -375,7 +374,7 @@ def bm_interface_get_by_vif_uuid(context, vif_uuid):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_interface_get_all_by_bm_node_id(context, bm_node_id):
result = model_query(context, models.BareMetalInterface,
read_deleted="no").\
@@ -388,7 +387,7 @@ def bm_interface_get_all_by_bm_node_id(context, bm_node_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_deployment_create(context, key, image_path, pxe_config_path, root_mb,
swap_mb):
ref = models.BareMetalDeployment()
@@ -401,7 +400,7 @@ def bm_deployment_create(context, key, image_path, pxe_config_path, root_mb,
return ref.id
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_deployment_get(context, dep_id):
result = model_query(context, models.BareMetalDeployment,
read_deleted="no").\
@@ -410,7 +409,7 @@ def bm_deployment_get(context, dep_id):
return result
-@require_admin_context
+@sqlalchemy_api.require_admin_context
def bm_deployment_destroy(context, dep_id):
model_query(context, models.BareMetalDeployment).\
filter_by(id=dep_id).\
diff --git a/nova/virt/baremetal/db/sqlalchemy/migration.py b/nova/virt/baremetal/db/sqlalchemy/migration.py
index 929793e70d..cfc26c04c4 100644
--- a/nova/virt/baremetal/db/sqlalchemy/migration.py
+++ b/nova/virt/baremetal/db/sqlalchemy/migration.py
@@ -25,7 +25,7 @@ import sqlalchemy
from nova import exception
from nova.openstack.common import log as logging
from nova.virt.baremetal.db import migration
-from nova.virt.baremetal.db.sqlalchemy.session import get_engine
+from nova.virt.baremetal.db.sqlalchemy import session
LOG = logging.getLogger(__name__)
@@ -71,24 +71,25 @@ def db_sync(version=None):
current_version = db_version()
repository = _find_migrate_repo()
if version is None or version > current_version:
- return versioning_api.upgrade(get_engine(), repository, version)
+ return versioning_api.upgrade(session.get_engine(), repository,
+ version)
else:
- return versioning_api.downgrade(get_engine(), repository,
+ return versioning_api.downgrade(session.get_engine(), repository,
version)
def db_version():
repository = _find_migrate_repo()
try:
- return versioning_api.db_version(get_engine(), repository)
+ return versioning_api.db_version(session.get_engine(), repository)
except versioning_exceptions.DatabaseNotControlledError:
meta = sqlalchemy.MetaData()
- engine = get_engine()
+ engine = session.get_engine()
meta.reflect(bind=engine)
tables = meta.tables
if len(tables) == 0:
db_version_control(migration.INIT_VERSION)
- return versioning_api.db_version(get_engine(), repository)
+ return versioning_api.db_version(session.get_engine(), repository)
else:
# Some pre-Essex DB's may not be version controlled.
# Require them to upgrade using Essex first.
@@ -98,7 +99,7 @@ def db_version():
def db_version_control(version=None):
repository = _find_migrate_repo()
- versioning_api.version_control(get_engine(), repository, version)
+ versioning_api.version_control(session.get_engine(), repository, version)
return version
diff --git a/nova/virt/baremetal/fake.py b/nova/virt/baremetal/fake.py
index 7a400af6fa..b3f39fdc3d 100644
--- a/nova/virt/baremetal/fake.py
+++ b/nova/virt/baremetal/fake.py
@@ -17,7 +17,7 @@
# under the License.
from nova.virt.baremetal import base
-from nova.virt.firewall import NoopFirewallDriver
+from nova.virt import firewall
class FakeDriver(base.NodeDriver):
@@ -52,7 +52,7 @@ class FakePowerManager(base.PowerManager):
super(FakePowerManager, self).__init__(**kwargs)
-class FakeFirewallDriver(NoopFirewallDriver):
+class FakeFirewallDriver(firewall.NoopFirewallDriver):
def __init__(self):
super(FakeFirewallDriver, self).__init__()
diff --git a/nova/virt/baremetal/ipmi.py b/nova/virt/baremetal/ipmi.py
index 393b3657b9..5d4a87625d 100644
--- a/nova/virt/baremetal/ipmi.py
+++ b/nova/virt/baremetal/ipmi.py
@@ -25,7 +25,7 @@ import os
import stat
import tempfile
-from nova.exception import InvalidParameterValue
+from nova import exception
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova import paths
@@ -104,13 +104,17 @@ class IPMI(base.PowerManager):
self.port = node['terminal_port']
if self.node_id == None:
- raise InvalidParameterValue(_("Node id not supplied to IPMI"))
+ raise exception.InvalidParameterValue(_("Node id not supplied "
+ "to IPMI"))
if self.address == None:
- raise InvalidParameterValue(_("Address not supplied to IPMI"))
+ raise exception.InvalidParameterValue(_("Address not supplied "
+ "to IPMI"))
if self.user == None:
- raise InvalidParameterValue(_("User not supplied to IPMI"))
+ raise exception.InvalidParameterValue(_("User not supplied "
+ "to IPMI"))
if self.password == None:
- raise InvalidParameterValue(_("Password not supplied to IPMI"))
+ raise exception.InvalidParameterValue(_("Password not supplied "
+ "to IPMI"))
def _exec_ipmitool(self, command):
args = ['ipmitool',
diff --git a/nova/virt/baremetal/pxe.py b/nova/virt/baremetal/pxe.py
index 0daac1d463..91de43dd1a 100644
--- a/nova/virt/baremetal/pxe.py
+++ b/nova/virt/baremetal/pxe.py
@@ -67,7 +67,8 @@ CHEETAH = None
def _get_cheetah():
global CHEETAH
if CHEETAH is None:
- from Cheetah.Template import Template as CHEETAH
+ from Cheetah import Template
+ CHEETAH = Template.Template
return CHEETAH
diff --git a/nova/virt/libvirt/__init__.py b/nova/virt/libvirt/__init__.py
index 00f4fd6b02..535d6c7297 100644
--- a/nova/virt/libvirt/__init__.py
+++ b/nova/virt/libvirt/__init__.py
@@ -14,4 +14,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-from nova.virt.libvirt.driver import LibvirtDriver
+from nova.virt.libvirt import driver
+
+LibvirtDriver = driver.LibvirtDriver
diff --git a/nova/virt/powervm/__init__.py b/nova/virt/powervm/__init__.py
index 83bbcd2899..1b63f83109 100644
--- a/nova/virt/powervm/__init__.py
+++ b/nova/virt/powervm/__init__.py
@@ -26,4 +26,6 @@ refer to the IBM Redbook[1] publication.
May 2011. <http://www.redbooks.ibm.com/abstracts/sg247940.html>
"""
-from nova.virt.powervm.driver import PowerVMDriver
+from nova.virt.powervm import driver
+
+PowerVMDriver = driver.PowerVMDriver
diff --git a/nova/virt/vmwareapi/__init__.py b/nova/virt/vmwareapi/__init__.py
index 66e7d9b027..37d816f8c0 100644
--- a/nova/virt/vmwareapi/__init__.py
+++ b/nova/virt/vmwareapi/__init__.py
@@ -18,4 +18,6 @@
:mod:`vmwareapi` -- Nova support for VMware ESX/ESXi Server through VMware API.
"""
# NOTE(sdague) for nicer compute_driver specification
-from nova.virt.vmwareapi.driver import VMwareESXDriver
+from nova.virt.vmwareapi import driver
+
+VMwareESXDriver = driver.VMwareESXDriver
diff --git a/nova/virt/xenapi/__init__.py b/nova/virt/xenapi/__init__.py
index 6a56a918c0..3853f09f2c 100644
--- a/nova/virt/xenapi/__init__.py
+++ b/nova/virt/xenapi/__init__.py
@@ -18,4 +18,6 @@
:mod:`xenapi` -- Nova support for XenServer and XCP through XenAPI
==================================================================
"""
-from nova.virt.xenapi.driver import XenAPIDriver
+from nova.virt.xenapi import driver
+
+XenAPIDriver = driver.XenAPIDriver