fix context in bin files

This commit is contained in:
Vishvananda Ishaya
2010-10-13 23:44:04 -07:00
parent a69d03cbf3
commit 8395ee7464
2 changed files with 17 additions and 15 deletions

View File

@@ -60,8 +60,7 @@ def add_lease(mac, ip_address, _hostname, _interface):
rpc.cast(context.get_admin_context(), rpc.cast(context.get_admin_context(),
"%s.%s" % (FLAGS.network_topic, FLAGS.host), "%s.%s" % (FLAGS.network_topic, FLAGS.host),
{"method": "lease_fixed_ip", {"method": "lease_fixed_ip",
"args": {"context": None, "args": {"mac": mac,
"mac": mac,
"address": ip_address}}) "address": ip_address}})
@@ -82,8 +81,7 @@ def del_lease(mac, ip_address, _hostname, _interface):
rpc.cast(context.get_admin_context(), rpc.cast(context.get_admin_context(),
"%s.%s" % (FLAGS.network_topic, FLAGS.host), "%s.%s" % (FLAGS.network_topic, FLAGS.host),
{"method": "release_fixed_ip", {"method": "release_fixed_ip",
"args": {"context": None, "args": {"mac": mac,
"mac": mac,
"address": ip_address}}) "address": ip_address}})

View File

@@ -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')): if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
sys.path.insert(0, possible_topdir) sys.path.insert(0, possible_topdir)
from nova import context
from nova import db from nova import db
from nova import exception from nova import exception
from nova import flags from nova import flags
from nova import quota from nova import quota
from nova import utils from nova import utils
from nova.auth import manager from nova.auth import manager
from nova.network import manager as network_manager
from nova.cloudpipe import pipelib from nova.cloudpipe import pipelib
@@ -121,7 +121,7 @@ class VpnCommands(object):
def _vpn_for(self, project_id): def _vpn_for(self, project_id):
"""Get the VPN instance for a 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 if (instance['image_id'] == FLAGS.vpn_image_id
and not instance['state_description'] in and not instance['state_description'] in
['shutting_down', 'shutdown'] ['shutting_down', 'shutdown']
@@ -323,13 +323,14 @@ class ProjectCommands(object):
def quota(self, project_id, key=None, value=None): def quota(self, project_id, key=None, value=None):
"""Set or display quotas for project """Set or display quotas for project
arguments: project_id [key] [value]""" arguments: project_id [key] [value]"""
ctxt = context.get_admin_context()
if key: if key:
quo = {'project_id': project_id, key: value} quo = {'project_id': project_id, key: value}
try: try:
db.quota_update(None, project_id, quo) db.quota_update(ctxt, project_id, quo)
except exception.NotFound: except exception.NotFound:
db.quota_create(None, quo) db.quota_create(ctxt, quo)
project_quota = quota.get_quota(None, project_id) project_quota = quota.get_quota(ctxt, project_id)
for key, value in project_quota.iteritems(): for key, value in project_quota.iteritems():
print '%s: %s' % (key, value) print '%s: %s' % (key, value)
@@ -353,23 +354,26 @@ class FloatingIpCommands(object):
"""Creates floating ips for host by range """Creates floating ips for host by range
arguments: host ip_range""" arguments: host ip_range"""
for address in IPy.IP(range): for address in IPy.IP(range):
db.floating_ip_create(None, {'address': str(address), db.floating_ip_create(context.get_admin_context(),
'host': host}) {'address': str(address),
'host': host})
def delete(self, ip_range): def delete(self, ip_range):
"""Deletes floating ips by range """Deletes floating ips by range
arguments: range""" arguments: range"""
for address in IPy.IP(ip_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): def list(self, host=None):
"""Lists all floating ips (optionally by host) """Lists all floating ips (optionally by host)
arguments: [host]""" arguments: [host]"""
ctxt = context.get_admin_context()
if host == None: if host == None:
floating_ips = db.floating_ip_get_all(None) floating_ips = db.floating_ip_get_all(ctxt)
else: 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: for floating_ip in floating_ips:
instance = None instance = None
if floating_ip['fixed_ip']: if floating_ip['fixed_ip']:
@@ -451,7 +455,7 @@ def main():
if FLAGS.verbose: if FLAGS.verbose:
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
script_name = argv.pop(0) script_name = argv.pop(0)
if len(argv) < 1: if len(argv) < 1:
print script_name + " category action [<args>]" print script_name + " category action [<args>]"