Example #1
0
    def mounted_on_same_shared_storage(self, context, instance_ref, dest):
        """Check if the src and dest host mount same shared storage.

        At first, dest host creates temp file, and src host can see
        it if they mounts same shared storage. Then src host erase it.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        src = instance_ref["host"]
        dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest)
        src_t = db.queue_get_for(context, FLAGS.compute_topic, src)

        filename = None

        try:
            # create tmpfile at dest host
            filename = rpc.call(context, dst_t, {"method": "create_shared_storage_test_file"})

            # make sure existence at src host.
            ret = rpc.call(context, src_t, {"method": "check_shared_storage_test_file", "args": {"filename": filename}})
            if not ret:
                raise exception.FileNotFound(file_path=filename)

        except exception.FileNotFound:
            raise

        finally:
            # Should only be None for tests?
            if filename is not None:
                rpc.call(context, dst_t, {"method": "cleanup_shared_storage_test_file", "args": {"filename": filename}})
    def test_live_migration_common_check_checking_cpuinfo_fail(self):
        """Raise excetion when original host doen't have compatible cpu."""

        dest = "dummydest"
        instance_id = self._create_instance()
        i_ref = db.instance_get(self.context, instance_id)

        # compute service for destination
        s_ref = self._create_compute_service(host=i_ref["host"])
        # compute service for original host
        s_ref2 = self._create_compute_service(host=dest)

        # mocks
        driver = self.scheduler.driver
        self.mox.StubOutWithMock(driver, "mounted_on_same_shared_storage")
        driver.mounted_on_same_shared_storage(mox.IgnoreArg(), i_ref, dest)
        self.mox.StubOutWithMock(rpc, "call", use_mock_anything=True)
        rpc.call(
            mox.IgnoreArg(),
            mox.IgnoreArg(),
            {"method": "compare_cpu", "args": {"cpu_info": s_ref2["compute_node"][0]["cpu_info"]}},
        ).AndRaise(rpc.RemoteError("doesn't have compatibility to", "", ""))

        self.mox.ReplayAll()
        try:
            self.scheduler.driver._live_migration_common_check(self.context, i_ref, dest, False)
        except rpc.RemoteError, e:
            c = e.message.find(_("doesn't have compatibility to")) >= 0
Example #3
0
    def mounted_on_same_shared_storage(self, context, instance_ref, dest):
        """Check if the src and dest host mount same shared storage.

        At first, dest host creates temp file, and src host can see
        it if they mounts same shared storage. Then src host erase it.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        src = instance_ref["host"]
        dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest)
        src_t = db.queue_get_for(context, FLAGS.compute_topic, src)

        try:
            # create tmpfile at dest host
            filename = rpc.call(context, dst_t, {"method": "create_shared_storage_test_file"})

            # make sure existence at src host.
            rpc.call(context, src_t, {"method": "check_shared_storage_test_file", "args": {"filename": filename}})

        except rpc.RemoteError:
            ipath = FLAGS.instances_path
            logging.error(
                _("Cannot confirm tmpfile at %(ipath)s is on " "same shared storage between %(src)s " "and %(dest)s.")
                % locals()
            )
            raise

        finally:
            rpc.call(context, dst_t, {"method": "cleanup_shared_storage_test_file", "args": {"filename": filename}})
Example #4
0
 def deallocate_for_instance(self, context, instance, **kwargs):
     """Deallocates all network structures related to instance."""
     args = kwargs
     args["instance_id"] = instance["id"]
     args["project_id"] = instance["project_id"]
     args["host"] = instance["host"]
     rpc.call(context, FLAGS.network_topic, {"method": "deallocate_for_instance", "args": args})
Example #5
0
    def mounted_on_same_shared_storage(self, context, instance_ref, dest):
        """Check if the src and dest host mount same shared storage.

        At first, dest host creates temp file, and src host can see
        it if they mounts same shared storage. Then src host erase it.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        src = instance_ref["host"]
        dst_t = db.queue_get_for(context, FLAGS.compute_topic, dest)
        src_t = db.queue_get_for(context, FLAGS.compute_topic, src)

        filename = rpc.call(context, dst_t, {"method": "create_shared_storage_test_file"})

        try:
            # make sure existence at src host.
            ret = rpc.call(context, src_t, {"method": "check_shared_storage_test_file", "args": {"filename": filename}})

        finally:
            rpc.cast(context, dst_t, {"method": "cleanup_shared_storage_test_file", "args": {"filename": filename}})

        return ret
Example #6
0
 def remove_from_compute(self, context, instance_id, volume_id, host):
     """Remove volume from specified compute host."""
     rpc.call(
         context,
         self.db.queue_get_for(context, FLAGS.compute_topic, host),
         {"method": "remove_volume_connection", "args": {"instance_id": instance_id, "volume_id": volume_id}},
     )
Example #7
0
 def _check_shared_storage(self, dest, instance, check_result):
     tmp_filename = "test-filename"
     rpc.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn("dest_queue")
     rpc.call(
         self.context,
         "dest_queue",
         {
             "method": "create_shared_storage_test_file",
             "args": {},
             "version": compute_rpcapi.ComputeAPI.RPC_API_VERSION,
         },
         None,
     ).AndReturn(tmp_filename)
     rpc.queue_get_for(self.context, FLAGS.compute_topic, instance["host"]).AndReturn("src_queue")
     rpc.call(
         self.context,
         "src_queue",
         {
             "method": "check_shared_storage_test_file",
             "args": {"filename": tmp_filename},
             "version": compute_rpcapi.ComputeAPI.RPC_API_VERSION,
         },
         None,
     ).AndReturn(check_result)
     rpc.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn("dest_queue")
     rpc.cast(
         self.context,
         "dest_queue",
         {
             "method": "cleanup_shared_storage_test_file",
             "args": {"filename": tmp_filename},
             "version": compute_rpcapi.ComputeAPI.RPC_API_VERSION,
         },
     )
Example #8
0
    def assert_compute_node_has_enough_disk(self, context, instance_ref, dest, disk_over_commit):
        """Checks if destination host has enough disk for block migration.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host
        :param disk_over_commit: if True, consider real(not virtual)
                                 disk size.

        """

        # Libvirt supports qcow2 disk format,which is usually compressed
        # on compute nodes.
        # Real disk image (compressed) may enlarged to "virtual disk size",
        # that is specified as the maximum disk size.
        # (See qemu-img -f path-to-disk)
        # Scheduler recognizes destination host still has enough disk space
        # if real disk size < available disk size
        # if disk_over_commit is True,
        #  otherwise virtual disk size < available disk size.

        # Refresh compute_nodes table
        topic = db.queue_get_for(context, FLAGS.compute_topic, dest)
        rpc.call(context, topic, {"method": "update_available_resource"})

        # Getting total available disk of host
        available_gb = self._get_compute_info(context, dest, "disk_available_least")
        available = available_gb * (1024 ** 3)

        # Getting necessary disk size
        try:
            topic = db.queue_get_for(context, FLAGS.compute_topic, instance_ref["host"])
            ret = rpc.call(
                context, topic, {"method": "get_instance_disk_info", "args": {"instance_name": instance_ref["name"]}}
            )
            disk_infos = utils.loads(ret)
        except rpc.RemoteError:
            LOG.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals())
            raise

        necessary = 0
        if disk_over_commit:
            for info in disk_infos:
                necessary += int(info["disk_size"])
        else:
            for info in disk_infos:
                necessary += int(info["virt_disk_size"])

        # Check that available disk > necessary disk
        if (available - necessary) < 0:
            instance_id = ec2utils.id_to_ec2_id(instance_ref["id"])
            reason = _(
                "Unable to migrate %(instance_id)s to %(dest)s: "
                "Lack of disk(host:%(available)s "
                "<= instance:%(necessary)s)"
            )
            raise exception.MigrationError(reason=reason % locals())
Example #9
0
    def _live_migration_common_check(self, context, instance_ref, dest):
        """Live migration common check routine.

        Below checkings are followed by
        http://wiki.libvirt.org/page/TodoPreMigrationChecks

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        # Checking shared storage connectivity
        self.mounted_on_same_shared_storage(context, instance_ref, dest)

        # Checking dest exists.
        dservice_refs = db.service_get_all_compute_by_host(context, dest)
        dservice_ref = dservice_refs[0]["compute_node"][0]

        # Checking original host( where instance was launched at) exists.
        try:
            oservice_refs = db.service_get_all_compute_by_host(context, instance_ref["launched_on"])
        except exception.NotFound:
            raise exception.Invalid(
                _("host %s where instance was launched " "does not exist.") % instance_ref["launched_on"]
            )
        oservice_ref = oservice_refs[0]["compute_node"][0]

        # Checking hypervisor is same.
        orig_hypervisor = oservice_ref["hypervisor_type"]
        dest_hypervisor = dservice_ref["hypervisor_type"]
        if orig_hypervisor != dest_hypervisor:
            raise exception.Invalid(
                _("Different hypervisor type" "(%(orig_hypervisor)s->" "%(dest_hypervisor)s)')" % locals())
            )

        # Checkng hypervisor version.
        orig_hypervisor = oservice_ref["hypervisor_version"]
        dest_hypervisor = dservice_ref["hypervisor_version"]
        if orig_hypervisor > dest_hypervisor:
            raise exception.Invalid(
                _("Older hypervisor version" "(%(orig_hypervisor)s->" "%(dest_hypervisor)s)") % locals()
            )

        # Checking cpuinfo.
        try:
            rpc.call(
                context,
                db.queue_get_for(context, FLAGS.compute_topic, dest),
                {"method": "compare_cpu", "args": {"cpu_info": oservice_ref["cpu_info"]}},
            )

        except rpc.RemoteError:
            src = instance_ref["host"]
            logging.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals())
            raise
Example #10
0
 def release_floating_ip(self, context, address, affect_auto_assigned=False):
     """Removes floating ip with address from a project. (deallocates)"""
     rpc.call(
         context,
         FLAGS.network_topic,
         {
             "method": "deallocate_floating_ip",
             "args": {"address": address, "affect_auto_assigned": affect_auto_assigned},
         },
     )
Example #11
0
    def setup_networks_on_host(self, context, instance, host=None, teardown=False):
        """Setup or teardown the network structures on hosts related to
           instance"""
        host = host or instance["host"]
        # NOTE(tr3buchet): host is passed in cases where we need to setup
        # or teardown the networks on a host which has been migrated to/from
        # and instance['host'] is not yet or is no longer equal to
        args = {"instance_id": instance["id"], "host": host, "teardown": teardown}

        # NOTE(tr3buchet): the call is just to wait for completion
        rpc.call(context, FLAGS.network_topic, {"method": "setup_networks_on_host", "args": args})
Example #12
0
    def show_host_resources(self, context, host):
        """Shows the physical/usage resource given by hosts.

        :param context: security context
        :param host: hostname
        :returns:
            example format is below.
            {'resource':D, 'usage':{proj_id1:D, proj_id2:D}}
            D: {'vcpus': 3, 'memory_mb': 2048, 'local_gb': 2048,
                'vcpus_used': 12, 'memory_mb_used': 10240,
                'local_gb_used': 64}

        """
        # Update latest compute_node table
        topic = db.queue_get_for(context, FLAGS.compute_topic, host)
        rpc.call(context, topic, {"method": "update_available_resource"})

        # Getting compute node info and related instances info
        compute_ref = db.service_get_all_compute_by_host(context, host)
        compute_ref = compute_ref[0]
        instance_refs = db.instance_get_all_by_host(context, compute_ref["host"])

        # Getting total available/used resource
        compute_ref = compute_ref["compute_node"][0]
        resource = {
            "vcpus": compute_ref["vcpus"],
            "memory_mb": compute_ref["memory_mb"],
            "local_gb": compute_ref["local_gb"],
            "vcpus_used": compute_ref["vcpus_used"],
            "memory_mb_used": compute_ref["memory_mb_used"],
            "local_gb_used": compute_ref["local_gb_used"],
        }
        usage = dict()
        if not instance_refs:
            return {"resource": resource, "usage": usage}

        # Getting usage resource per project
        project_ids = [i["project_id"] for i in instance_refs]
        project_ids = list(set(project_ids))
        for project_id in project_ids:
            vcpus = [i["vcpus"] for i in instance_refs if i["project_id"] == project_id]

            mem = [i["memory_mb"] for i in instance_refs if i["project_id"] == project_id]

            disk = [i["local_gb"] for i in instance_refs if i["project_id"] == project_id]

            usage[project_id] = {
                "vcpus": reduce(lambda x, y: x + y, vcpus),
                "memory_mb": reduce(lambda x, y: x + y, mem),
                "local_gb": reduce(lambda x, y: x + y, disk),
            }

        return {"resource": resource, "usage": usage}
Example #13
0
 def _really_run_instance(self, user, launchstate, idx):
     launchstate["instance_id"] = generate_uid("i")
     launchstate["ami_launch_index"] = idx
     network = self.network.get_users_network(str(user.id))
     launchstate["network_str"] = network.to_dict()
     launchstate["bridge_name"] = network.bridge_name
     logging.debug(
         "Casting to node for %s's instance with IP of %s in the %s network"
         % (user.name, launchstate["private_dns_name"], launchstate["network_name"])
     )
     rpc.call(FLAGS.compute_topic, {"method": "run_instance", "args": launchstate})
     return launchstate
Example #14
0
 def disassociate_floating_ip(self, context, address, affect_auto_assigned=False):
     """Disassociates a floating ip from fixed ip it is associated with."""
     floating_ip = self.db.floating_ip_get_by_address(context, address)
     if not affect_auto_assigned and floating_ip.get("auto_assigned"):
         return
     if not floating_ip.get("fixed_ip"):
         raise exception.ApiError("Address is not associated.")
     host = floating_ip["fixed_ip"]["network"]["host"]
     rpc.call(
         context,
         self.db.queue_get_for(context, FLAGS.network_topic, host),
         {"method": "disassociate_floating_ip", "args": {"floating_address": floating_ip["address"]}},
     )
Example #15
0
    def test_call_exception(self):
        """Test that exception gets passed back properly

        rpc.call returns a RemoteError object.  The value of the
        exception is converted to a string, so we convert it back
        to an int in the test.
        """
        value = 42
        self.assertRaises(rpc.RemoteError, rpc.call, self.context, "test", {"method": "fail", "args": {"value": value}})
        try:
            rpc.call(self.context, "test", {"method": "fail", "args": {"value": value}})
            self.fail("should have thrown rpc.RemoteError")
        except rpc.RemoteError as exc:
            self.assertEqual(int(exc.value), value)
Example #16
0
    def test_block_migration_dest_check_service_lack_disk(self):
        """Confirms exception raises when dest doesn't have enough disk."""

        self.mox.StubOutWithMock(db, "instance_get")
        self.mox.StubOutWithMock(self.driver, "_live_migration_src_check")
        self.mox.StubOutWithMock(db, "service_get_all_compute_by_host")
        self.mox.StubOutWithMock(utils, "service_is_up")
        self.mox.StubOutWithMock(self.driver, "assert_compute_node_has_enough_memory")
        self.mox.StubOutWithMock(self.driver, "_get_compute_info")
        self.mox.StubOutWithMock(db, "instance_get_all_by_host")
        self.mox.StubOutWithMock(rpc, "queue_get_for")
        self.mox.StubOutWithMock(rpc, "call")

        dest = "fake_host2"
        block_migration = True
        disk_over_commit = True
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance["id"]).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(["fake_service3"])
        utils.service_is_up("fake_service3").AndReturn(True)

        # Enough memory
        self.driver.assert_compute_node_has_enough_memory(self.context, instance, dest)

        # Not enough disk
        self.driver._get_compute_info(self.context, dest, "disk_available_least").AndReturn(1023)
        rpc.queue_get_for(self.context, FLAGS.compute_topic, instance["host"]).AndReturn("src_queue")
        rpc.call(
            self.context,
            "src_queue",
            {
                "method": "get_instance_disk_info",
                "args": {"instance_name": instance["name"]},
                "version": compute_rpcapi.ComputeAPI.RPC_API_VERSION,
            },
            None,
        ).AndReturn(json.dumps([{"disk_size": 1024 * (1024 ** 3)}]))

        self.mox.ReplayAll()
        self.assertRaises(
            exception.MigrationError,
            self.driver.schedule_live_migration,
            self.context,
            instance_id=instance["id"],
            dest=dest,
            block_migration=block_migration,
            disk_over_commit=disk_over_commit,
        )
Example #17
0
    def test_live_migration_different_hypervisor_type_raises(self):
        self.mox.StubOutWithMock(db, "instance_get")
        self.mox.StubOutWithMock(self.driver, "_live_migration_src_check")
        self.mox.StubOutWithMock(self.driver, "_live_migration_dest_check")
        self.mox.StubOutWithMock(db, "queue_get_for")
        self.mox.StubOutWithMock(rpc, "call")
        self.mox.StubOutWithMock(rpc, "cast")
        self.mox.StubOutWithMock(db, "service_get_all_compute_by_host")

        dest = "fake_host2"
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance["id"]).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance, dest, block_migration, disk_over_commit)

        db.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn("dest_queue")
        db.queue_get_for(self.context, FLAGS.compute_topic, instance["host"]).AndReturn("src_queue")
        tmp_filename = "test-filename"
        rpc.call(self.context, "dest_queue", {"method": "create_shared_storage_test_file"}).AndReturn(tmp_filename)
        rpc.call(
            self.context, "src_queue", {"method": "check_shared_storage_test_file", "args": {"filename": tmp_filename}}
        ).AndReturn(True)
        rpc.cast(
            self.context,
            "dest_queue",
            {"method": "cleanup_shared_storage_test_file", "args": {"filename": tmp_filename}},
        )
        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
            [{"compute_node": [{"hypervisor_type": "xen", "hypervisor_version": 1}]}]
        )
        # different hypervisor type
        db.service_get_all_compute_by_host(self.context, instance["host"]).AndReturn(
            [{"compute_node": [{"hypervisor_type": "not-xen", "hypervisor_version": 1}]}]
        )

        self.mox.ReplayAll()
        self.assertRaises(
            exception.InvalidHypervisorType,
            self.driver.schedule_live_migration,
            self.context,
            instance_id=instance["id"],
            dest=dest,
            block_migration=block_migration,
            disk_over_commit=disk_over_commit,
        )
Example #18
0
 def terminate_connection(self, context, volume_id, address):
     volume = self.get(context, volume_id)
     host = volume["host"]
     queue = self.db.queue_get_for(context, FLAGS.volume_topic, host)
     return rpc.call(
         context, queue, {"method": "terminate_connection", "args": {"volume_id": volume_id, "address": address}}
     )
Example #19
0
    def _allocate_fixed_ips(self, context, instance_id, host, networks, **kwargs):
        """Calls allocate_fixed_ip once for each network."""
        green_pool = greenpool.GreenPool()

        vpn = kwargs.pop("vpn")
        for network in networks:
            # NOTE(vish): if we are not multi_host pass to the network host
            if not network["multi_host"]:
                host = network["host"]
            # NOTE(vish): if there is no network host, set one
            if host == None:
                host = rpc.call(
                    context, FLAGS.network_topic, {"method": "set_network_host", "args": {"network_ref": network}}
                )
            if host != self.host:
                # need to call allocate_fixed_ip to correct network host
                topic = self.db.queue_get_for(context, FLAGS.network_topic, host)
                args = {}
                args["instance_id"] = instance_id
                args["network_id"] = network["id"]
                args["vpn"] = vpn

                green_pool.spawn_n(rpc.call, context, topic, {"method": "_rpc_allocate_fixed_ip", "args": args})
            else:
                # i am the correct host, run here
                self.allocate_fixed_ip(context, instance_id, network, vpn=vpn)

        # wait for all of the allocates (if any) to finish
        green_pool.waitall()
Example #20
0
 def get_instance_nw_info(self, context, instance):
     """Returns all network info related to an instance."""
     args = {
         "instance_id": instance["id"],
         "instance_uuid": instance["uuid"],
         "rxtx_factor": instance["instance_type"]["rxtx_factor"],
         "host": instance["host"],
         "project_id": instance["project_id"],
     }
     try:
         nw_info = rpc.call(context, FLAGS.network_topic, {"method": "get_instance_nw_info", "args": args})
         return network_model.NetworkInfo.hydrate(nw_info)
     # FIXME(comstud) rpc calls raise RemoteError if the remote raises
     # an exception.  In the case here, because of a race condition,
     # it's possible the remote will raise a InstanceNotFound when
     # someone deletes the instance while this call is in progress.
     #
     # Unfortunately, we don't have access to the original exception
     # class now.. but we do have the exception class's name.  So,
     # we're checking it here and raising a new exception.
     #
     # Ultimately we need RPC to be able to serialize more things like
     # classes.
     except rpc_common.RemoteError as err:
         if err.exc_type == "InstanceNotFound":
             raise exception.InstanceNotFound(instance_id=instance["id"])
         raise
Example #21
0
 def get_console_output(self, context, instance_id, **kwargs):
     # instance_id is passed in as a list of instances
     instance = self._get_instance(context, instance_id[0])
     return rpc.call(
         "%s.%s" % (FLAGS.compute_topic, instance["node_name"]),
         {"method": "get_console_output", "args": {"instance_id": instance_id[0]}},
     )
Example #22
0
    def test_live_migration_dest_host_incompatable_cpu_raises(self):
        self.mox.StubOutWithMock(db, "instance_get")
        self.mox.StubOutWithMock(self.driver, "_live_migration_src_check")
        self.mox.StubOutWithMock(self.driver, "_live_migration_dest_check")
        self.mox.StubOutWithMock(rpc, "queue_get_for")
        self.mox.StubOutWithMock(rpc, "call")
        self.mox.StubOutWithMock(rpc, "cast")
        self.mox.StubOutWithMock(db, "service_get_all_compute_by_host")

        dest = "fake_host2"
        block_migration = False
        disk_over_commit = False
        instance = self._live_migration_instance()
        db.instance_get(self.context, instance["id"]).AndReturn(instance)

        self.driver._live_migration_src_check(self.context, instance)
        self.driver._live_migration_dest_check(self.context, instance, dest, block_migration, disk_over_commit)

        self._check_shared_storage(dest, instance, True)

        db.service_get_all_compute_by_host(self.context, dest).AndReturn(
            [{"compute_node": [{"hypervisor_type": "xen", "hypervisor_version": 1}]}]
        )
        db.service_get_all_compute_by_host(self.context, instance["host"]).AndReturn(
            [{"compute_node": [{"hypervisor_type": "xen", "hypervisor_version": 1, "cpu_info": "fake_cpu_info"}]}]
        )
        rpc.queue_get_for(self.context, FLAGS.compute_topic, dest).AndReturn("dest_queue")
        rpc.call(
            self.context,
            "dest_queue",
            {
                "method": "compare_cpu",
                "args": {"cpu_info": "fake_cpu_info"},
                "version": compute_rpcapi.ComputeAPI.RPC_API_VERSION,
            },
            None,
        ).AndRaise(rpc_common.RemoteError())

        self.mox.ReplayAll()
        self.assertRaises(
            rpc_common.RemoteError,
            self.driver.schedule_live_migration,
            self.context,
            instance_id=instance["id"],
            dest=dest,
            block_migration=block_migration,
        )
Example #23
0
 def get_instance_nw_info(self, context, instance):
     """Returns all network info related to an instance."""
     args = {'instance_id': instance['id'],
             'instance_type_id': instance['instance_type_id'],
             'host': instance['host']}
     return rpc.call(context, FLAGS.network_topic,
                     {'method': 'get_instance_nw_info',
                      'args': args})
Example #24
0
def test_raising_from_service_to_nova(connection):
    with connection as conn:

        class Controller(object):
            def error_method(self, context, **kwargs):
                raise Exception("foo")

        srvobj = service.Service(Controller, conn, flags.FLAGS.control_exchange, "test")
        srvobj.start()
        eventlet.sleep(0)
        try:
            with pytest.raises(novacommon.RemoteError):
                rpc.call(
                    novacontext.get_admin_context(), topic="test", msg={"method": "error_method", "args": {}}, timeout=2
                )
        finally:
            srvobj.kill()
Example #25
0
 def echo(context, queue, value):
     """Calls echo in the passed queue"""
     LOG.debug(_("Nested received %(queue)s, %(value)s") % locals())
     # TODO: so, it will replay the context and use the same REQID?
     # that's bizarre.
     ret = rpc.call(context, queue, {"method": "echo", "args": {"value": value}})
     LOG.debug(_("Nested return %s"), ret)
     return value
Example #26
0
File: api.py Project: russellb/nova
 def terminate_connection(self, context, volume, connector):
     host = volume["host"]
     queue = self.db.queue_get_for(context, FLAGS.volume_topic, host)
     return rpc.call(
         context,
         queue,
         {"method": "terminate_connection", "args": {"volume_id": volume["id"], "connector": connector}},
     )
Example #27
0
    def associate_floating_ip(self, context, 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
        """
        rpc.call(
            context,
            FLAGS.network_topic,
            {
                "method": "associate_floating_ip",
                "args": {
                    "floating_address": floating_address,
                    "fixed_address": fixed_address,
                    "affect_auto_assigned": affect_auto_assigned,
                },
            },
        )
Example #28
0
 def get_instance_nw_info(self, context, instance):
     """Returns all network info related to an instance."""
     args = {
         "instance_id": instance["id"],
         "instance_type_id": instance["instance_type_id"],
         "host": instance["host"],
     }
     return rpc.call(context, FLAGS.network_topic, {"method": "get_instance_nw_info", "args": args})
Example #29
0
 def disassociate_floating_ip(self, context, address,
                              affect_auto_assigned=False):
     """Disassociates a floating ip from fixed ip it is associated with."""
     floating_ip = self.db.floating_ip_get_by_address(context, address)
     if not affect_auto_assigned and floating_ip.get('auto_assigned'):
         return
     if not floating_ip.get('fixed_ip'):
         raise exception.ApiError('Address is not associated.')
     # NOTE(vish): if we are multi_host, send to the instances host
     if floating_ip['fixed_ip']['network']['multi_host']:
         host = floating_ip['fixed_ip']['instance']['host']
     else:
         host = floating_ip['fixed_ip']['network']['host']
     rpc.call(context,
              self.db.queue_get_for(context, FLAGS.network_topic, host),
              {'method': 'disassociate_floating_ip',
               'args': {'floating_address': floating_ip['address']}})
Example #30
0
 def validate_networks(self, context, requested_networks):
     """validate the networks passed at the time of creating
     the server
     """
     args = {'networks': requested_networks}
     return rpc.call(context, FLAGS.network_topic,
                     {'method': 'validate_networks',
                      'args': args})