예제 #1
0
    def associate_floating_ip(self,
                              context,
                              instance,
                              floating_address,
                              fixed_address,
                              affect_auto_assigned=False):
        """Associates a floating IP with a fixed IP.

        Ensures floating IP is allocated to the project in context.
        Does not verify ownership of the fixed IP. Caller is assumed to have
        checked that the instance is properly owned.

        """
        orig_instance_uuid = self.floating_manager.associate_floating_ip(
            context, floating_address, fixed_address, affect_auto_assigned)

        if orig_instance_uuid:
            msg_dict = dict(address=floating_address,
                            instance_id=orig_instance_uuid)
            LOG.info(
                're-assign floating IP %(address)s from '
                'instance %(instance_id)s', msg_dict)
            orig_instance = objects.Instance.get_by_uuid(
                context, orig_instance_uuid, expected_attrs=['flavor'])

            # purge cached nw info for the original instance
            base_api.update_instance_cache_with_nw_info(
                self, context, orig_instance)
예제 #2
0
파일: test_api.py 프로젝트: sebrandon1/nova
 def test_update_nw_info_empty_list(self, db_mock, api_mock):
     api_mock._get_instance_nw_info.return_value = self.nw_info
     base_api.update_instance_cache_with_nw_info(
         api_mock, self.context, self.instance, network_model.NetworkInfo([])
     )
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid, {"network_info": "[]"})
예제 #3
0
파일: test_api.py 프로젝트: dbzhou2008/nova
 def test_update_nw_info_one_network(self, db_mock, api_mock):
     api_mock._get_instance_nw_info.return_value = self.nw_info
     base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                            self.instance, self.nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': self.nw_json})
예제 #4
0
파일: api.py 프로젝트: HybridCloud-dew/hws
 def get_instance_nw_info(self,
                          context,
                          instance,
                          networks=None,
                          port_ids=None,
                          use_slave=False,
                          pci_list=None):
     """Return network information for specified instance
        and update cache.
     """
     # NOTE(): It would be nice if use_slave had us call
     #                   special APIs that pummeled slaves instead of
     #                   the master. For now we just ignore this arg.
     with lockutils.lock('refresh_cache-%s' % instance['uuid']):
         instance = objects.Instance.get_by_uuid(
             context,
             instance['uuid'],
             expected_attrs=['system_metadata'],
             use_slave=use_slave)
         result = self._get_instance_nw_info(context, instance, networks,
                                             port_ids, pci_list)
         base_api.update_instance_cache_with_nw_info(self,
                                                     context,
                                                     instance,
                                                     nw_info=result,
                                                     update_cells=False)
     return result
예제 #5
0
파일: test_api.py 프로젝트: anantk/nova
 def test_update_nw_info_one_network(self, db_mock, api_mock):
     api_mock._get_instance_nw_info.return_value = self.nw_info
     base_api.update_instance_cache_with_nw_info(
         api_mock, self.context, self.instance, self.nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': self.nw_json})
예제 #6
0
 def test_update_nw_info_empty_list(self, db_mock, api_mock):
     api_mock._get_instance_nw_info.return_value = self.nw_info
     base_api.update_instance_cache_with_nw_info(
         api_mock, self.context, self.instance,
         network_model.NetworkInfo([]))
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance['uuid'],
                                     {'network_info': '[]'})
예제 #7
0
파일: test_api.py 프로젝트: mahak/nova
 def test_update_nw_info_empty_list(self, db_mock, api_mock):
     new_nw_info = network_model.NetworkInfo([])
     db_mock.return_value = fake_info_cache
     base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                             self.instance, new_nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': '[]'})
     self.assertEqual(new_nw_info, self.instance.info_cache.network_info)
예제 #8
0
 def get_instance_nw_info(self, context, instance, **kwargs):
     """Returns all network info related to an instance."""
     result = self._get_instance_nw_info(context, instance)
     # NOTE(comstud): Don't update API cell with new info_cache every
     # time we pull network info for an instance.  The periodic healing
     # of info_cache causes too many cells messages.  Healing the API
     # will happen separately.
     base_api.update_instance_cache_with_nw_info(self, context, instance, result, update_cells=False)
     return result
예제 #9
0
    def test_update_nw_info_none(self, db_mock, api_mock):
        api_mock._get_instance_nw_info.return_value = self.nw_info

        base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                                    self.instance, None)
        api_mock._get_instance_nw_info.assert_called_once_with(
            self.context, self.instance)
        db_mock.assert_called_once_with(self.context, self.instance['uuid'],
                                        {'network_info': self.nw_json})
예제 #10
0
 def test_update_nw_info_empty_list(self, db_mock, api_mock):
     new_nw_info = network_model.NetworkInfo([])
     db_mock.return_value = fake_info_cache
     base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                             self.instance, new_nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': '[]'})
     self.assertEqual(new_nw_info, self.instance.info_cache.network_info)
예제 #11
0
파일: test_api.py 프로젝트: MrDarcys/nova
    def test_update_nw_info_none(self, db_mock, api_mock):
        api_mock._get_instance_nw_info.return_value = self.nw_info

        base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                               self.instance, None)
        api_mock._get_instance_nw_info.assert_called_once_with(self.context,
                                                                self.instance)
        db_mock.assert_called_once_with(self.context, self.instance['uuid'],
                                        {'network_info': self.nw_json})
예제 #12
0
파일: test_api.py 프로젝트: mahak/nova
 def test_update_nw_info_one_network(self, db_mock, api_mock):
     info_cache = copy.deepcopy(fake_info_cache)
     info_cache.update({'network_info': self.nw_json})
     db_mock.return_value = info_cache
     base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                            self.instance, self.nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': self.nw_json})
     self.assertEqual(self.nw_info, self.instance.info_cache.network_info)
예제 #13
0
 def test_update_nw_info_one_network(self, db_mock, api_mock):
     info_cache = copy.deepcopy(fake_info_cache)
     info_cache.update({'network_info': self.nw_json})
     db_mock.return_value = info_cache
     base_api.update_instance_cache_with_nw_info(api_mock, self.context,
                                            self.instance, self.nw_info)
     self.assertFalse(api_mock._get_instance_nw_info.called)
     db_mock.assert_called_once_with(self.context, self.instance.uuid,
                                     {'network_info': self.nw_json})
     self.assertEqual(self.nw_info, self.instance.info_cache.network_info)
예제 #14
0
 def get_instance_nw_info(self, context, instance, **kwargs):
     """Returns all network info related to an instance."""
     result = self._get_instance_nw_info(context, instance)
     # NOTE(comstud): Don't update API cell with new info_cache every
     # time we pull network info for an instance.  The periodic healing
     # of info_cache causes too many cells messages.  Healing the API
     # will happen separately.
     base_api.update_instance_cache_with_nw_info(self, context, instance,
                                                 result, update_cells=False)
     return result
예제 #15
0
파일: api.py 프로젝트: nash-x/hws
 def get_instance_nw_info(self, context, instance, networks=None, port_ids=None, use_slave=False, pci_list=None):
     """Return network information for specified instance
        and update cache.
     """
     # NOTE(): It would be nice if use_slave had us call
     #                   special APIs that pummeled slaves instead of
     #                   the master. For now we just ignore this arg.
     with lockutils.lock("refresh_cache-%s" % instance["uuid"]):
         instance = objects.Instance.get_by_uuid(
             context, instance["uuid"], expected_attrs=["system_metadata"], use_slave=use_slave
         )
         result = self._get_instance_nw_info(context, instance, networks, port_ids, pci_list)
         base_api.update_instance_cache_with_nw_info(self, context, instance, nw_info=result, update_cells=False)
     return result
예제 #16
0
    def associate_floating_ip(self, context, instance, floating_address, fixed_address, affect_auto_assigned=False):
        """Associates a floating ip with a fixed ip.

        Ensures floating ip is allocated to the project in context.
        Does not verify ownership of the fixed ip. Caller is assumed to have
        checked that the instance is properly owned.

        """
        orig_instance_uuid = self.floating_manager.associate_floating_ip(
            context, floating_address, fixed_address, affect_auto_assigned
        )

        if orig_instance_uuid:
            msg_dict = dict(address=floating_address, instance_id=orig_instance_uuid)
            LOG.info(_LI("re-assign floating IP %(address)s from " "instance %(instance_id)s"), msg_dict)
            orig_instance = objects.Instance.get_by_uuid(context, orig_instance_uuid)

            # purge cached nw info for the original instance
            base_api.update_instance_cache_with_nw_info(self, context, orig_instance)
예제 #17
0
파일: api.py 프로젝트: iawells/gluon-nova
    def deallocate_for_instance(self, context, instance, **kwargs):
        """Deallocate all network resources related to the instance."""
        LOG.debug('deallocate_for_instance()', instance=instance)
        # This used to get a list of ports matching this device from Neutron and free them all.
	# We could instead list the port IDs of the VIFs and unbound the ones we know about.
        #search_opts = {'device_id': instance.uuid}
        client = self.client
        data = client.list_ports(owner=SERVICE_NAME, device=instance.uuid)
	ports = data.keys()

        # Reset device_id and device_owner for ports
        self._unbind_ports(context, ports)

        # NOTE(arosen): This clears out the network_cache only if the instance
        # hasn't already been deleted. This is needed when an instance fails to
        # launch and is rescheduled onto another compute node. If the instance
        # has already been deleted this call does nothing.
        base_api.update_instance_cache_with_nw_info(self, context, instance,
                                            network_model.NetworkInfo([]))
예제 #18
0
    def deallocate_for_instance(self, context, instance, **kwargs):
        """Deallocate all network resources related to the instance."""
        LOG.debug('deallocate_for_instance()', instance=instance)
        # This used to get a list of ports matching this device from Neutron and free them all.
        # We could instead list the port IDs of the VIFs and unbound the ones we know about.
        #search_opts = {'device_id': instance.uuid}
        client = self.client
        data = client.list_ports(owner=SERVICE_NAME, device=instance.uuid)
        ports = data.keys()

        # Reset device_id and device_owner for ports
        self._unbind_ports(context, ports)

        # NOTE(arosen): This clears out the network_cache only if the instance
        # hasn't already been deleted. This is needed when an instance fails to
        # launch and is rescheduled onto another compute node. If the instance
        # has already been deleted this call does nothing.
        base_api.update_instance_cache_with_nw_info(
            self, context, instance, network_model.NetworkInfo([]))
예제 #19
0
파일: test_api.py 프로젝트: mahak/nova
 def test_update_nw_info_none_instance_deleted(self, db_mock, api_mock):
     instance = objects.Instance(uuid=FAKE_UUID, deleted=True)
     base_api.update_instance_cache_with_nw_info(
         api_mock, self.context, instance)
     self.assertFalse(api_mock.called)
예제 #20
0
 def test_update_nw_info_none_instance_deleted(self, db_mock, api_mock):
     instance = objects.Instance(uuid=FAKE_UUID, deleted=True)
     base_api.update_instance_cache_with_nw_info(
         api_mock, self.context, instance)
     self.assertFalse(api_mock.called)