def _get_floating_ip_info(self, context, host=None): floating_ip_info = {"floating_ip_info": []} if host is None: try: floating_ips = db.floating_ip_get_all(context) except exception.NoFloatingIpsDefined: return floating_ip_info else: try: floating_ips = db.floating_ip_get_all_by_host(context, host) except exception.FloatingIpNotFoundForHost as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) for floating_ip in floating_ips: instance_uuid = None if floating_ip['fixed_ip_id']: fixed_ip = db.fixed_ip_get(context, floating_ip['fixed_ip_id']) instance_uuid = fixed_ip['instance_uuid'] result = {'address': floating_ip['address'], 'pool': floating_ip['pool'], 'interface': floating_ip['interface'], 'project_id': floating_ip['project_id'], 'instance_uuid': instance_uuid} floating_ip_info['floating_ip_info'].append(result) return floating_ip_info
def _get_floating_ip_info(self, context, host=None): floating_ip_info = {"floating_ip_info": []} try: if host is None: floating_ips = db.floating_ip_get_all(context) else: floating_ips = db.floating_ip_get_all_by_host(context, host) except exception.NoFloatingIpsDefined: return floating_ip_info for floating_ip in floating_ips: instance_uuid = None if floating_ip['fixed_ip_id']: fixed_ip = db.fixed_ip_get(context, floating_ip['fixed_ip_id']) instance_uuid = fixed_ip['instance_uuid'] result = {'address': floating_ip['address'], 'pool': floating_ip['pool'], 'interface': floating_ip['interface'], 'project_id': floating_ip['project_id'], 'instance_uuid': instance_uuid} floating_ip_info['floating_ip_info'].append(result) return floating_ip_info
def list(self, host=None): """Lists all floating ips (optionally by host) Note: if host is given, only active floating IPs are returned""" ctxt = context.get_admin_context() try: if host is None: floating_ips = db.floating_ip_get_all(ctxt) else: floating_ips = db.floating_ip_get_all_by_host(ctxt, host) except exception.NoFloatingIpsDefined: print _("No floating IP addresses have been defined.") return for floating_ip in floating_ips: instance_id = None if floating_ip['fixed_ip_id']: fixed_ip = db.fixed_ip_get(ctxt, floating_ip['fixed_ip_id']) try: instance = db.instance_get(ctxt, fixed_ip['instance_id']) instance_id = instance.get('uuid', "none") except exception.InstanceNotFound: msg = _('Missing instance %s') instance_id = msg % fixed_ip['instance_id'] print "%s\t%s\t%s\t%s\t%s" % (floating_ip['project_id'], floating_ip['address'], instance_id, floating_ip['pool'], floating_ip['interface'])
def list(self, host=None): """Lists all floating ips (optionally by host) Note: if host is given, only active floating IPs are returned""" ctxt = context.get_admin_context() try: if host is None: floating_ips = db.floating_ip_get_all(ctxt) else: floating_ips = db.floating_ip_get_all_by_host(ctxt, host) except exception.NoFloatingIpsDefined: print _("No floating IP addresses have been defined.") return for floating_ip in floating_ips: instance_uuid = None if floating_ip["fixed_ip_id"]: fixed_ip = db.fixed_ip_get(ctxt, floating_ip["fixed_ip_id"]) instance_uuid = fixed_ip["instance_uuid"] print "%s\t%s\t%s\t%s\t%s" % ( floating_ip["project_id"], floating_ip["address"], instance_uuid, floating_ip["pool"], floating_ip["interface"], )
def _get_floating_ips(self, context): ''' [ { "fixed_ip": "10.0.0.0", "id": 2, "instance_id": "xxx", "ip": "10.120.32.162", "pool": "nova", "host": "host1", "type": "public", "project_id": "xxx" }] ''' ips = [] try: floating_ips_refs = db.floating_ip_get_all(context) except exception.NoFloatingIpsDefined: return ips for floating_ip in floating_ips_refs: ip = self._make_floating_ip(floating_ip) self._set_floating_ip_metadata(context, ip) ips.append(ip) return ips
def _get_floating_ip_info(self, context, host=None): floating_ip_info = {"floating_ip_info": []} try: if host is None: floating_ips = db.floating_ip_get_all(context) else: floating_ips = db.floating_ip_get_all_by_host(context, host) except exception.NoFloatingIpsDefined: return floating_ip_info for floating_ip in floating_ips: instance_uuid = None if floating_ip["fixed_ip_id"]: fixed_ip = db.fixed_ip_get(context, floating_ip["fixed_ip_id"]) instance_uuid = fixed_ip["instance_uuid"] result = { "address": floating_ip["address"], "pool": floating_ip["pool"], "interface": floating_ip["interface"], "project_id": floating_ip["project_id"], "instance_uuid": instance_uuid, } floating_ip_info["floating_ip_info"].append(result) return floating_ip_info
def test_fail_floating_ip_in_bulk_creation(self): self.assertRaises(exception.FloatingIpExists, self._create_floating_ips, [self.floating_ip, self.floating_ip_2]) all_ips = db.floating_ip_get_all(self.context) ip_list = [ip['address'] for ip in all_ips] self.assertIn(self.floating_ip, ip_list) self.assertNotIn(self.floating_ip_2, ip_list)
def test_floating_ip_in_bulk_creation(self): self._delete_floating_ip() self._create_floating_ips([self.floating_ip, self.floating_ip_2]) all_ips = db.floating_ip_get_all(self.context) ip_list = [ip['address'] for ip in all_ips] self.assertIn(self.floating_ip, ip_list) self.assertIn(self.floating_ip_2, ip_list)
def format_addresses(self, context): addresses = [] if context.is_admin: iterator = db.floating_ip_get_all(context) else: iterator = db.floating_ip_get_all_by_project(context, context.project_id) for floating_ip_ref in iterator: address = floating_ip_ref['address'] ec2_id = None if (floating_ip_ref['fixed_ip'] and floating_ip_ref['fixed_ip']['instance']): instance_id = floating_ip_ref['fixed_ip']['instance']['id'] ec2_id = id_to_ec2_id(instance_id) address_rv = {'public_ip': address, 'instance_id': ec2_id} if context.is_admin: details = "%s (%s)" % (address_rv['instance_id'], floating_ip_ref['project_id']) address_rv['instance_id'] = details addresses.append(address_rv) return {'addressesSet': addresses}
def list(self, host=None): """Lists all floating ips (optionally by host) Note: if host is given, only active floating IPs are returned""" ctxt = context.get_admin_context() try: if host is None: floating_ips = db.floating_ip_get_all(ctxt) else: floating_ips = db.floating_ip_get_all_by_host(ctxt, host) except exception.NoFloatingIpsDefined: print _("No floating IP addresses have been defined.") return for floating_ip in floating_ips: instance_uuid = None if floating_ip['fixed_ip_id']: fixed_ip = db.fixed_ip_get(ctxt, floating_ip['fixed_ip_id']) instance_uuid = fixed_ip['instance_uuid'] print "%s\t%s\t%s\t%s\t%s" % (floating_ip['project_id'], floating_ip['address'], instance_uuid, floating_ip['pool'], floating_ip['interface'])
def format_addresses(self, context): addresses = [] if context.is_admin: iterator = db.floating_ip_get_all(context) else: iterator = db.floating_ip_get_all_by_project( context, context.project_id) for floating_ip_ref in iterator: if floating_ip_ref['project_id'] is None: continue address = floating_ip_ref['address'] ec2_id = None if (floating_ip_ref['fixed_ip'] and floating_ip_ref['fixed_ip']['instance']): instance_id = floating_ip_ref['fixed_ip']['instance']['id'] ec2_id = ec2utils.id_to_ec2_id(instance_id) address_rv = {'public_ip': address, 'instance_id': ec2_id} if context.is_admin: details = "%s (%s)" % (address_rv['instance_id'], floating_ip_ref['project_id']) address_rv['instance_id'] = details addresses.append(address_rv) return {'addressesSet': addresses}
def get_all(cls, context): db_floatingips = db.floating_ip_get_all(context) return obj_base.obj_make_list(context, cls(context), objects.FloatingIP, db_floatingips)