diff options
| author | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-10-14 21:18:51 +0000 |
|---|---|---|
| committer | Tarmac <> | 2010-10-14 21:18:51 +0000 |
| commit | aec330b34def7158f590ce855d0cd4ff5d0ed41c (patch) | |
| tree | 28dc8ee0f4502b8f82e7843bd3f31905640baa61 /bin | |
| parent | 3363b133a927509432cb42d77abf18d3d5248abf (diff) | |
| parent | 81cdbc42d41509f629fe8ec0c7605958134e9ed0 (diff) | |
| download | nova-aec330b34def7158f590ce855d0cd4ff5d0ed41c.tar.gz nova-aec330b34def7158f590ce855d0cd4ff5d0ed41c.tar.xz nova-aec330b34def7158f590ce855d0cd4ff5d0ed41c.zip | |
This branch modifies the fixes all of the deprecation warnings about empty context. It does this by adding the following fixes/features
* promotes api/context.py to context.py because it is used by the whole system
* adds more information to the context object
* passes the context through rpc
* adds a helper method for promoting to admin context (elevate())
* modifies most checks to use context.project_id instead of context.project.id to avoid
trips to the database
This included a lot of merge fixing and backporting from the anso deploy branch so some stuff may be broken. Right now it throws an Exception('die') in addition to the deprecation warning so we get a stack trace and can find any other deprecated calls. This needs some testing, especially of the openstack api.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/nova-dhcpbridge | 26 | ||||
| -rwxr-xr-x | bin/nova-manage | 26 |
2 files changed, 31 insertions, 21 deletions
diff --git a/bin/nova-dhcpbridge b/bin/nova-dhcpbridge index a127ed03c..2b7a083d2 100755 --- a/bin/nova-dhcpbridge +++ b/bin/nova-dhcpbridge @@ -33,6 +33,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import context from nova import db from nova import flags from nova import rpc @@ -52,12 +53,14 @@ def add_lease(mac, ip_address, _hostname, _interface): if FLAGS.fake_rabbit: logging.debug("leasing ip") network_manager = utils.import_object(FLAGS.network_manager) - network_manager.lease_fixed_ip(None, mac, ip_address) + network_manager.lease_fixed_ip(context.get_admin_context(), + mac, + ip_address) else: - rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host), + rpc.cast(context.get_admin_context(), + "%s.%s" % (FLAGS.network_topic, FLAGS.host), {"method": "lease_fixed_ip", - "args": {"context": None, - "mac": mac, + "args": {"mac": mac, "address": ip_address}}) @@ -71,19 +74,22 @@ def del_lease(mac, ip_address, _hostname, _interface): if FLAGS.fake_rabbit: logging.debug("releasing ip") network_manager = utils.import_object(FLAGS.network_manager) - network_manager.release_fixed_ip(None, mac, ip_address) + network_manager.release_fixed_ip(context.get_admin_context(), + mac, + ip_address) else: - rpc.cast("%s.%s" % (FLAGS.network_topic, FLAGS.host), + rpc.cast(context.get_admin_context(), + "%s.%s" % (FLAGS.network_topic, FLAGS.host), {"method": "release_fixed_ip", - "args": {"context": None, - "mac": mac, + "args": {"mac": mac, "address": ip_address}}) def init_leases(interface): """Get the list of hosts for an interface.""" - network_ref = db.network_get_by_bridge(None, interface) - return linux_net.get_dhcp_hosts(None, network_ref['id']) + ctxt = context.get_admin_context() + network_ref = db.network_get_by_bridge(ctxt, interface) + return linux_net.get_dhcp_hosts(ctxt, network_ref['id']) def main(): diff --git a/bin/nova-manage b/bin/nova-manage index d36b0f53a..cf574c6b3 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -67,13 +67,13 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): sys.path.insert(0, possible_topdir) +from nova import context from nova import db from nova import exception from nova import flags from nova import quota from nova import utils from nova.auth import manager -from nova.network import manager as network_manager from nova.cloudpipe import pipelib @@ -121,7 +121,7 @@ class VpnCommands(object): def _vpn_for(self, project_id): """Get the VPN instance for a project ID.""" - for instance in db.instance_get_all(None): + for instance in db.instance_get_all(context.get_admin_context()): if (instance['image_id'] == FLAGS.vpn_image_id and not instance['state_description'] in ['shutting_down', 'shutdown'] @@ -323,13 +323,14 @@ class ProjectCommands(object): def quota(self, project_id, key=None, value=None): """Set or display quotas for project arguments: project_id [key] [value]""" + ctxt = context.get_admin_context() if key: quo = {'project_id': project_id, key: value} try: - db.quota_update(None, project_id, quo) + db.quota_update(ctxt, project_id, quo) except exception.NotFound: - db.quota_create(None, quo) - project_quota = quota.get_quota(None, project_id) + db.quota_create(ctxt, quo) + project_quota = quota.get_quota(ctxt, project_id) for key, value in project_quota.iteritems(): print '%s: %s' % (key, value) @@ -353,23 +354,26 @@ class FloatingIpCommands(object): """Creates floating ips for host by range arguments: host ip_range""" for address in IPy.IP(range): - db.floating_ip_create(None, {'address': str(address), - 'host': host}) + db.floating_ip_create(context.get_admin_context(), + {'address': str(address), + 'host': host}) def delete(self, ip_range): """Deletes floating ips by range arguments: range""" for address in IPy.IP(ip_range): - db.floating_ip_destroy(None, str(address)) + db.floating_ip_destroy(context.get_admin_context(), + str(address)) def list(self, host=None): """Lists all floating ips (optionally by host) arguments: [host]""" + ctxt = context.get_admin_context() if host == None: - floating_ips = db.floating_ip_get_all(None) + floating_ips = db.floating_ip_get_all(ctxt) else: - floating_ips = db.floating_ip_get_all_by_host(None, host) + floating_ips = db.floating_ip_get_all_by_host(ctxt, host) for floating_ip in floating_ips: instance = None if floating_ip['fixed_ip']: @@ -451,7 +455,7 @@ def main(): if FLAGS.verbose: logging.getLogger().setLevel(logging.DEBUG) - + script_name = argv.pop(0) if len(argv) < 1: print script_name + " category action [<args>]" |
