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
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))))
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)))
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)
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, '')
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)
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)
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')
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")
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)
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)
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))
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))
def context(context, value): """Returns dictionary version of context""" LOG.debug(_("Received %s"), context) return context.to_dict()
def fake_network_update(context, network_id, values): self.assertTrue(context.to_dict()['is_admin']) self.assertEqual(network_id, self.fake_net['id']) self.assertEqual(values, self.fake_update_value)
def serialize_context(self, context): return context.to_dict()
def fake_network_delete_safe(context, network_id): self.assertTrue(context.to_dict()['is_admin']) self.assertEqual(network_id, self.fake_net['id'])
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)
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(self.fake_net)