Example #1
0
 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})
Example #2
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)
Example #3
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': '[]'})
Example #4
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
Example #5
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
Example #6
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)