Esempio n. 1
0
    def terminate_all_but_running_instances(self):

        for cloud_name in self.config.clouds.list:
            cloud = Cloud(cloud_name, self.config)
            cloud.terminate_all_but_running_instances()

        time.sleep(30)
Esempio n. 2
0
    def get_cloud_termination_list(self):

        condor_list = []
        command = "condor_status"
        rcmd = RemoteCommand(
            config = self.config,
            hostname = self.master.dns,
            ssh_private_key = self.config.globals.priv_path,
            user = self.config.workload.user,
            command = command)
        rcmd.execute()
        if rcmd.stdout:
            # condor status will be lines so split them
            all_lines = rcmd.stdout.split("\n")
            for line in all_lines:
                # line not empty
                if line.strip():
                # if its the first line then go to the next one
                    if line.strip().startswith("Name"):
                        continue
                    # if we find a line that starts with total then we are done, break out from the loop
                    elif line.strip().startswith("Total"):
                        break
                    # it must be a line of interest, parse it
                    else:
                        # split line by space :
                        #"vm-148-102.uc.futu LINUX      X86_64 Unclaimed Idle     0.150  2048  0+00:00:04"
                        line_columns = line.split()
                        try:
                            tmp_fqdn = line_columns[0].strip()
                            condor_list.append(tmp_fqdn)
                        except Exception as expt:
                            LOG.info("Error parsing condor status, line says : %s and the expt says : %s" % (line, str(expt)))
        LOG.info("Condor worker names: %s" % (str(condor_list)))

        # instances running in this cloud
        cloud = Cloud(self.cloud_name, self.config)
        vms = cloud.get_running_instances()

        # add to the termination list only workers (no master) that have checked in with the master:
        termination_list = []
        for instance in vms:

            # not a master
            if not instance.public_dns_name == self.master.dns:

                for worker_partial_name in condor_list:
                    if worker_partial_name in instance.public_dns_name:
                        termination_list.append(instance)
                        condor_list.remove(worker_partial_name)

        termination_list_names =[]
        for instance in termination_list:
            termination_list_names.append(instance.public_dns_name)
        LOG.info("Termination list for %s: %s" % (self.cloud_name, str(termination_list_names)))

        return termination_list