Esempio n. 1
0
def get_all_keys(clouds):
    """get all ssh keys from a dictionary of UserCloudInfo objects
    """
    pool = Pool(processes=10)
    key_dict = {}

    results = {}
    for cloud_name, cloud in clouds.iteritems():
        result = pool.apply_async(cloud.get_keys)
        results[cloud_name] = result

    pool.close()

    for cloud_name, result in results.iteritems():
        try:
            key_dict[cloud_name] = result.get(IAAS_TIMEOUT)
        except TimeoutError:
            log.exception("Timed out getting keys from %s" % cloud_name)
            key_dict[cloud_name] = []
        except Exception:
            log.exception("Unexpected error getting keys from %s" % cloud_name)
            key_dict[cloud_name] = []

    return key_dict
Esempio n. 2
0
    def get_possible_sites(self, details=False):
        site_client = DTRSClient(self._dashi_conn)
        site_names = site_client.list_sites(self.access_key)
        all_sites = {}
        for site in site_names:
            all_sites[site] = {'id': site, 'instance_types': INSTANCE_TYPES}

        if details is True:
            pool = Pool()

            instance_types_results = {}
            for site in site_names:
                instance_types_results[site] = pool.apply_async(
                    site_client.describe_site, [self.access_key, site])
            pool.close()

            for site in site_names:
                try:
                    site_description = instance_types_results[site].get(
                        IAAS_TIMEOUT)

                    instance_types = site_description.get("instance_types")
                    if instance_types is not None:
                        all_sites[site]['instance_types'] = instance_types

                    cloud_type = site_description.get("type")
                    if cloud_type is not None:
                        all_sites[site]['type'] = cloud_type

                    image_generation = site_description.get("image_generation")
                    if image_generation:
                        all_sites[site]['image_generation'] = True
                    else:
                        all_sites[site]['image_generation'] = False
                except TimeoutError:
                    log.exception(
                        "Timed out getting list of instance types for %s" %
                        site)
                except Exception:
                    log.exception(
                        "Unexpected error getting list of instance types for %s"
                        % site)

            pool = Pool()

            public_results = {}
            user_results = {}
            clouds = self.get_clouds()
            for cloud_name, cloud in clouds.iteritems():
                result = pool.apply_async(cloud.get_user_images)
                user_results[cloud_name] = result

                if cloud.site_desc["type"] != "ec2":
                    result = pool.apply_async(cloud.get_public_images)
                    public_results[cloud_name] = result

            pool.close()

            for cloud_name, result in user_results.iteritems():
                try:
                    all_sites[cloud_name]['user_images'] = result.get(
                        IAAS_TIMEOUT)
                except TimeoutError:
                    log.exception("Timed out getting images from %s" %
                                  cloud_name)
                    all_sites[cloud_name]['user_images'] = []
                except Exception:
                    log.exception("Unexpected error getting images from %s" %
                                  cloud_name)
                    all_sites[cloud_name]['user_images'] = []

            for cloud_name, result in public_results.iteritems():
                try:
                    all_sites[cloud_name]['public_images'] = result.get(
                        IAAS_TIMEOUT)
                except TimeoutError:
                    log.exception("Timed out getting images from %s" %
                                  cloud_name)
                    all_sites[cloud_name]['public_images'] = []
                except Exception:
                    log.exception("Unexpected error getting images from %s" %
                                  cloud_name)
                    all_sites[cloud_name]['public_images'] = []

        return all_sites