本文整理汇总了Python中nova.context.to_dict函数的典型用法代码示例。如果您正苦于以下问题:Python to_dict函数的具体用法?Python to_dict怎么用?Python to_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_dict函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create
def _create(self, req, body):
context = req.environ['nova.context']
context = context.elevated()
print "context!!"
print context.to_dict()
vals = body['network']
name = vals['name']
size = vals['size']
project_id=str(req.environ['HTTP_X_TENANT_ID'])
print FLAGS.network_manager
cidr = self.get_new_cidr(context, size)
print cidr
print"!!!!!!!!!!!!!!!!strat creating"
self.create_network(context=context, label=name, fixed_range_v4=cidr, num_networks=1,
network_size=size, multi_host=None, vlan_start=None,
vpn_start=None, fixed_range_v6=None, gateway=None,
gateway_v6=None, bridge=None, bridge_interface=None,
dns1=None, dns2=None, project_id=project_id, priority=None,
uuid=None, fixed_cidr=None)
print cidr
db_net = db.network_get_by_cidr(context, cidr)
net = dict(db_net.iteritems())
ret_net={}
ret_net['network']={'id':net['uuid'],'name':net['label'],'cidr':net['cidr']}
return ret_net
示例2: _inner
def _inner():
ctxt = RpcContext.from_dict(context.to_dict())
try:
rval = node_func(context=ctxt, **node_args)
res = []
# Caller might have called ctxt.reply() manually
for (reply, failure) in ctxt._response:
if failure:
raise failure[0], failure[1], failure[2]
res.append(reply)
# if ending not 'sent'...we might have more data to
# return from the function itself
if not ctxt._done:
if inspect.isgenerator(rval):
for val in rval:
res.append(val)
else:
res.append(rval)
done.send(res)
except Exception:
exc_info = sys.exc_info()
done.send_exception(
rpc_common.RemoteError(exc_info[0].__name__,
str(exc_info[1]),
''.join(traceback.format_exception(*exc_info))))
示例3: call
def call(self, context, method, args):
node_func = getattr(self.proxy, method)
node_args = dict((str(k), v) for k, v in args.iteritems())
ctxt = RpcContext.from_dict(context.to_dict())
try:
rval = node_func(context=ctxt, **node_args)
# Caller might have called ctxt.reply() manually
for (reply, failure) in ctxt._response:
if failure:
raise failure[0], failure[1], failure[2]
yield reply
# if ending not 'sent'...we might have more data to
# return from the function itself
if not ctxt._done:
if isinstance(rval, types.GeneratorType):
for val in rval:
yield val
else:
yield rval
except Exception:
exc_info = sys.exc_info()
raise rpc_common.RemoteError(exc_info[0].__name__,
str(exc_info[1]),
''.join(traceback.format_exception(*exc_info)))
示例4: trigger_security_group_rule_destroy_refresh
def trigger_security_group_rule_destroy_refresh(self, context, rule_ids):
LOG.debug('rule_ids=%r', rule_ids)
ctxt = context.elevated()
tenant_id = context.to_dict()['project_id']
for rule_id in rule_ids:
self.rule_manager.delete_for_sg(tenant_id, rule_id)
示例5: trigger_security_group_destroy_refresh
def trigger_security_group_destroy_refresh(self, context,
security_group_id):
LOG.debug('security_group_id=%r', security_group_id)
tenant_id = context.to_dict()['project_id']
# delete corresponding chain
self.chain_manager.delete_for_sg(tenant_id, security_group_id)
# delete the port group
self.pg_manager.delete(tenant_id, security_group_id, '')
示例6: pack_context
def pack_context(msg, context):
"""Pack context into msg.
Values for message keys need to be less than 255 chars, so we pull
context out into a bunch of separate keys. If we want to support
more arguments in rabbit messages, we may want to do the same
for args at some point.
"""
context_d = dict([("_context_%s" % key, value) for (key, value) in context.to_dict().iteritems()])
msg.update(context_d)
示例7: trigger_security_group_rule_create_refresh
def trigger_security_group_rule_create_refresh(self, context, rule_ids):
LOG.debug('rule_ids=%r', rule_ids)
ctxt = context.elevated()
tenant_id = context.to_dict()['project_id']
for rule_id in rule_ids:
rule = db.security_group_rule_get(ctxt, rule_id)
group = db.security_group_get(ctxt, rule['parent_group_id'])
sg_id = rule['parent_group_id']
sg_name = group['name']
self.rule_manager.create_for_sg(tenant_id, sg_id, sg_name, rule)
示例8: fake_create_networks
def fake_create_networks(obj, context, **kwargs):
self.assertTrue(context.to_dict()['is_admin'])
self.assertEqual(kwargs['label'], 'Test')
self.assertEqual(kwargs['cidr'], '10.2.0.0/24')
self.assertEqual(kwargs['multi_host'], False)
self.assertEqual(kwargs['num_networks'], 1)
self.assertEqual(kwargs['network_size'], 256)
self.assertEqual(kwargs['vlan_start'], 200)
self.assertEqual(kwargs['vpn_start'], 2000)
self.assertEqual(kwargs['cidr_v6'], 'fd00:2::/120')
self.assertEqual(kwargs['gateway_v6'], 'fd00:2::22')
self.assertEqual(kwargs['bridge'], 'br200')
self.assertEqual(kwargs['bridge_interface'], 'eth0')
self.assertEqual(kwargs['dns1'], '8.8.8.8')
self.assertEqual(kwargs['dns2'], '8.8.4.4')
示例9: fake_create_networks
def fake_create_networks(obj, context, **kwargs):
self.assertTrue(context.to_dict()["is_admin"])
self.assertEqual(kwargs["label"], "Test")
self.assertEqual(kwargs["cidr"], "10.2.0.0/24")
self.assertEqual(kwargs["multi_host"], False)
self.assertEqual(kwargs["num_networks"], 1)
self.assertEqual(kwargs["network_size"], 256)
self.assertEqual(kwargs["vlan_start"], 200)
self.assertEqual(kwargs["vpn_start"], 2000)
self.assertEqual(kwargs["cidr_v6"], "fd00:2::/120")
self.assertEqual(kwargs["gateway"], "10.2.0.1")
self.assertEqual(kwargs["gateway_v6"], "fd00:2::22")
self.assertEqual(kwargs["bridge"], "br200")
self.assertEqual(kwargs["bridge_interface"], "eth0")
self.assertEqual(kwargs["dns1"], "8.8.8.8")
self.assertEqual(kwargs["dns2"], "8.8.4.4")
示例10: trigger_security_group_create_refresh
def trigger_security_group_create_refresh(self, context, group):
"""Create a chain and port group for the security group."""
LOG.debug('group=%r', group)
ctxt = context.elevated()
sg_ref = db.security_group_get_by_name(ctxt, group['project_id'],
group['name'])
tenant_id = context.to_dict()['project_id']
sg_id = sg_ref['id']
sg_name = group['name']
# create a chain for the security group
self.chain_manager.create_for_sg(tenant_id, sg_id, sg_name)
# create a port group for the security group
self.pg_manager.create(tenant_id, sg_id, sg_name)
示例11: _inner
def _inner():
ctxt = RpcContext.from_dict(context.to_dict())
try:
rval = node_func(context=ctxt, **node_args)
res = []
# Caller might have called ctxt.reply() manually
for (reply, failure) in ctxt._response:
if failure:
raise failure[0], failure[1], failure[2]
res.append(reply)
# if ending not 'sent'...we might have more data to
# return from the function itself
if not ctxt._done:
if inspect.isgenerator(rval):
for val in rval:
res.append(val)
else:
res.append(rval)
done.send(res)
except Exception as e:
done.send_exception(e)
示例12: fake_network_get_by_uuid
def fake_network_get_by_uuid(context, uuid):
self.assertTrue(context.to_dict()['is_admin'])
self.assertEqual(uuid, self.fake_net['uuid'])
return db_fakes.FakeModel(dict(test_network.fake_network,
**self.fake_net))
示例13: fake_network_get_by_cidr
def fake_network_get_by_cidr(context, cidr):
self.assertTrue(context.to_dict()['is_admin'])
self.assertEqual(cidr, self.fake_net['cidr'])
return db_fakes.FakeModel(dict(test_network.fake_network,
**self.fake_net))
示例14: context
def context(context, value):
"""Returns dictionary version of context"""
LOG.debug(_("Received %s"), context)
return context.to_dict()
示例15: fake_network_get_by_cidr
def fake_network_get_by_cidr(context, cidr):
self.assertTrue(context.to_dict()["is_admin"])
self.assertEqual(cidr, self.fake_net["cidr"])
return db_fakes.FakeModel(self.fake_net)