Exemplo n.º 1
0
    def deploy_instance_on_random_host(self, one_instance, availability_zone):
        one_instance = copy.deepcopy(one_instance)
        dst_compute = self.dst_cloud.resources[utils.COMPUTE_RESOURCE]

        _instance = list(one_instance[utils.INSTANCES_TYPE].values())[0]
        instance_body = _instance[utils.INSTANCE_BODY]
        hosts = dst_compute.get_compute_hosts(availability_zone)
        if not hosts:
            message = ("No hosts in availability zone '{az}' "
                       "found on destination.").format(az=availability_zone)
            raise DestinationCloudNotOperational(message)

        random.shuffle(hosts)

        while hosts:
            # Recreate ports and check floating ips
            one_instance = network_utils.prepare_networks(
                one_instance, self.cfg.migrate.keep_ip,
                self.dst_cloud.resources[utils.NETWORK_RESOURCE],
                self.dst_cloud.resources[utils.IDENTITY_RESOURCE])

            # Associate floating ips with ports again
            if self.cfg.migrate.keep_floatingip:
                network_utils.associate_floatingip(
                    one_instance,
                    self.dst_cloud.resources[utils.NETWORK_RESOURCE])

            next_host = hosts.pop()
            host_az = ':'.join([availability_zone, next_host])
            _updated_instance = list(
                one_instance[utils.INSTANCES_TYPE].values())[0]
            updated_instance_body = _updated_instance[utils.INSTANCE_BODY]

            try:
                new_id = dst_compute.deploy(updated_instance_body,
                                            availability_zone=host_az)
                self.state_notifier.success(objects.MigrationObjectType.VM,
                                            instance_body, new_id)
                return one_instance, new_id
            except exception.TimeoutException:
                msg = 'Failed to boot VM on node {}'.format(next_host)
                self.state_notifier.append_message(
                    objects.MigrationObjectType.VM, instance_body, msg)

        message = ("Unable to schedule VM '{vm}' on any of available compute "
                   "nodes.").format(vm=instance_body['name'])
        self.state_notifier.fail(objects.MigrationObjectType.VM, one_instance,
                                 message)
        LOG.error(message)
        raise DestinationCloudNotOperational(message)
Exemplo n.º 2
0
    def deploy_instance_on_random_host(self, one_instance, availability_zone):
        one_instance = copy.deepcopy(one_instance)
        dst_compute = self.dst_cloud.resources[utils.COMPUTE_RESOURCE]

        _instance = one_instance[utils.INSTANCES_TYPE].values()[0]
        instance_body = _instance[utils.INSTANCE_BODY]
        hosts = dst_compute.get_compute_hosts(availability_zone)
        if not hosts:
            message = ("No hosts in availability zone '{az}' "
                       "found on destination.").format(az=availability_zone)
            raise DestinationCloudNotOperational(message)

        random.shuffle(hosts)

        while hosts:
            # Recreate ports and check floating ips
            one_instance = network_utils.prepare_networks(
                one_instance,
                self.cfg.migrate.keep_ip,
                self.dst_cloud.resources[utils.NETWORK_RESOURCE],
                self.dst_cloud.resources[utils.IDENTITY_RESOURCE]
            )

            # Associate floating ips with ports again
            if self.cfg.migrate.keep_floatingip:
                network_utils.associate_floatingip(
                    one_instance,
                    self.dst_cloud.resources[utils.NETWORK_RESOURCE]
                )

            next_host = hosts.pop()
            host_az = ':'.join([availability_zone, next_host])
            _updated_instance = one_instance[utils.INSTANCES_TYPE].values()[0]
            updated_instance_body = _updated_instance[utils.INSTANCE_BODY]

            try:
                new_id = dst_compute.deploy(
                    updated_instance_body, availability_zone=host_az)
                return one_instance, new_id
            except exception.TimeoutException:
                pass

        message = ("Unable to schedule VM '{vm}' on any of available compute "
                   "nodes.").format(vm=instance_body['name'])
        LOG.error(message)
        raise DestinationCloudNotOperational(message)
    def run(self, info=None, **kwargs):
        if self.cfg.migrate.keep_floatingip:
            network_resource = self.cloud.resources[utl.NETWORK_RESOURCE]
            network_utils.associate_floatingip(info, network_resource)

        return {}
    def run(self, info=None, **kwargs):
        if self.cfg.migrate.keep_floatingip:
            network_resource = self.cloud.resources[utl.NETWORK_RESOURCE]
            network_utils.associate_floatingip(info, network_resource)

        return {}