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 _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 _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 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_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_post_live_migration_working_correctly(self): """Confirm post_live_migration() works as expected correctly.""" dest = 'desthost' flo_addr = '1.2.1.2' # Preparing datas c = context.get_admin_context() instance_id = self._create_instance() i_ref = db.instance_get(c, instance_id) db.instance_update(c, i_ref['id'], { 'state_description': 'migrating', 'state': power_state.PAUSED }) v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id}) fix_addr = db.fixed_ip_create(c, { 'address': '1.1.1.1', 'instance_id': instance_id }) fix_ref = db.fixed_ip_get_by_address(c, fix_addr) flo_ref = db.floating_ip_create(c, { 'address': flo_addr, 'fixed_ip_id': fix_ref['id'] }) # reload is necessary before setting mocks i_ref = db.instance_get(c, instance_id) # Preparing mocks self.mox.StubOutWithMock(self.compute.volume_manager, 'remove_compute_volume') for v in i_ref['volumes']: self.compute.volume_manager.remove_compute_volume(c, v['id']) self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance') self.compute.driver.unfilter_instance(i_ref, []) # executing self.mox.ReplayAll() ret = self.compute.post_live_migration(c, i_ref, dest) # make sure every data is rewritten to dest i_ref = db.instance_get(c, i_ref['id']) c1 = (i_ref['host'] == dest) flo_refs = db.floating_ip_get_all_by_host(c, dest) c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr) # post operaton self.assertTrue(c1 and c2) db.instance_destroy(c, instance_id) db.volume_destroy(c, v_ref['id']) db.floating_ip_destroy(c, flo_addr)
def test_post_live_migration_working_correctly(self): """Confirm post_live_migration() works as expected correctly.""" dest = 'desthost' flo_addr = '1.2.1.2' # Preparing datas c = context.get_admin_context() instance_id = self._create_instance() i_ref = db.instance_get(c, instance_id) db.instance_update(c, i_ref['id'], {'state_description': 'migrating', 'state': power_state.PAUSED}) v_ref = db.volume_create(c, {'size': 1, 'instance_id': instance_id}) fix_addr = db.fixed_ip_create(c, {'address': '1.1.1.1', 'instance_id': instance_id}) fix_ref = db.fixed_ip_get_by_address(c, fix_addr) flo_ref = db.floating_ip_create(c, {'address': flo_addr, 'fixed_ip_id': fix_ref['id']}) # reload is necessary before setting mocks i_ref = db.instance_get(c, instance_id) # Preparing mocks self.mox.StubOutWithMock(self.compute.volume_manager, 'remove_compute_volume') for v in i_ref['volumes']: self.compute.volume_manager.remove_compute_volume(c, v['id']) self.mox.StubOutWithMock(self.compute.driver, 'unfilter_instance') self.compute.driver.unfilter_instance(i_ref, []) # executing self.mox.ReplayAll() ret = self.compute.post_live_migration(c, i_ref, dest) # make sure every data is rewritten to dest i_ref = db.instance_get(c, i_ref['id']) c1 = (i_ref['host'] == dest) flo_refs = db.floating_ip_get_all_by_host(c, dest) c2 = (len(flo_refs) != 0 and flo_refs[0]['address'] == flo_addr) # post operaton self.assertTrue(c1 and c2) db.instance_destroy(c, instance_id) db.volume_destroy(c, v_ref['id']) db.floating_ip_destroy(c, flo_addr)
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_by_host(cls, context, host): db_floatingips = db.floating_ip_get_all_by_host(context, host) return obj_base.obj_make_list(context, cls(context), objects.FloatingIP, db_floatingips)