예제 #1
0
    def run(self):
        """Entry point for the action execution."""
        client = self._get_client()
        metadata = self._metadata

        if str(metadata.get('cluster')) == str(self._cluster_id):
            return Result(data={'migrate': True, 'uuid': self._uuid})

        # Ether is no metadata for vm - check flavor.
        try:
            # Maybe this should be done in different action
            # only once per whole workflow.
            # In case there is ~100 VMs to cluster_id, there will be
            # the same amount of calls to nova API.
            flavor = filter(lambda f: f.id == self._flavor,
                            client.flavors.list())[0]
        except IndexError:
            raise FilterVmException('Flavor not found')

        cluster_id = flavor.get_keys().get('cluster_id:cluster_id')

        if str(cluster_id) == str(self._cluster_id):
            return Result(data={'migrate': True, 'uuid': self._uuid})

        return Result(data={'migrate': False, 'uuid': self._uuid})
예제 #2
0
    def run(self):
        client = self._get_client()

        if self._migrate:
            server = client.servers.find(id=self._uuid)
            if (server.flavor['id'] != str(self._flavor_id)):
                sys.exit("flavor not correct!")
            return Result(data={'uuid': self._uuid})
    def run(self):
        client = self._get_client()
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self._host,
                    22)  # make sure that ./ssh/authorized_keys is already set
        ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("virsh --version")
        remote_version = ssh_stdout.readline()

        local_version = os.popen("virsh --version").read()

        if (remote_version == local_version):
            return Result(data={
                "live_migrate": True,
                "migrate": self._migrate,
                "uuid": self._uuid
            })
        else:
            return Result(
                data={
                    "live_migrate": False,
                    "migrate": self._migrate,
                    "uuid": self._uuid
                })
예제 #4
0
    def run(self):
        """Entry point for the action execution."""
        client = self._get_client()
        vms = []

        try:
            for host in self._host_list:
                vms.extend(
                    client.servers.list(search_opts={
                        'host': host,
                        'all_tenants': 1
                    }))
        except Exception as e:
            raise ListVmsException("Failed to list servers:  " + e)

        return Result(data={'vms': vms})
예제 #5
0
    def run(self):
        """Entry point for the action execution."""
        client = self._get_client()
        hosts_list = []

        def is_nova_compute_down(service):
            return (service.state == 'down') and \
                   (service.binary == 'nova-compute')

        try:
            hosts = filter(is_nova_compute_down, client.services.list())

            if hosts:
                for i in hosts:
                    hosts_list.append(i.host)

        except Exception as e:
            raise CheckNovaComputeException("Failed to get services list" +
                                            ":   " + e)

        return Result(data={'host_list': hosts_list})
    def run(self):
        """Entry point for the action execution."""
        client = self._get_client()
        hosts_list = []

        def is_ovs_agent_down(agent):
            return (agent['binary'] == 'neutron-openvswitch-agent') and \
                   not agent['alive']

        try:
            hosts = filter(is_ovs_agent_down, client.list_agents()['agents'])

            if hosts:
                for i in hosts:
                    hosts_list.append(i['host'])

        except Exception as e:
            raise CheckNeutronAgentException("Failed to get services list" +
                                             ":   " + e)

        return Result(data={'host_list': hosts_list})
예제 #7
0
    def run(self):
        client = self._get_client()

        if self._migrate:
            return Result(data={'uuid': self._uuid})
예제 #8
0
    def run(self):
        """Get the host in both nova_down_list and neutron_down_list"""
        host_list = [host for host in self._nova_down_list \
                     if host in self._neutron_down_list]

        return Result(data={'host': host_list})