Ejemplo n.º 1
0
def run_instance_fitter_test(profile=None, provider=None, credentials=None):
    """
    Test that we get the proper instance sizes for the given provider.
    """

    # Get the client for this test
    client = cloudless.Client(profile, provider, credentials)

    # If no memory, cpu, or storage is passed in, find the cheapest.
    if client.provider == "aws":
        assert get_fitting_instance(client.service,
                                    ServiceBlueprint(SMALL_INSTANCE_BLUEPRINT)) == "t2.small"
        assert get_fitting_instance(client.service,
                                    ServiceBlueprint(LARGE_INSTANCE_BLUEPRINT)) == "m5.xlarge"
    if client.provider == "gce":
        assert get_fitting_instance(client.service,
                                    ServiceBlueprint(SMALL_INSTANCE_BLUEPRINT)) == "n1-highcpu-4"
        assert get_fitting_instance(client.service,
                                    ServiceBlueprint(LARGE_INSTANCE_BLUEPRINT)) == "n1-highmem-4"
Ejemplo n.º 2
0
 def create_launch_configuration(asg_name, service_blueprint,
                                 runtime_scripts):
     ami_id = lookup_ami(service_blueprint.image())
     associate_public_ip = service_blueprint.public_ip()
     instance_type = get_fitting_instance(self, service_blueprint)
     autoscaling = self.driver.client("autoscaling")
     autoscaling.create_launch_configuration(
         LaunchConfigurationName=str(asg_name),
         ImageId=ami_id,
         SecurityGroups=[security_group_id],
         UserData=runtime_scripts,
         AssociatePublicIpAddress=associate_public_ip,
         InstanceType=instance_type)
Ejemplo n.º 3
0
    def create(self, network, service_name, blueprint, template_vars, count):
        """
        Create a service in "network" named "service_name" with blueprint file at "blueprint".
        """
        logger.debug(
            'Creating service %s, %s with blueprint %s and '
            'template_vars %s', network.name, service_name, blueprint,
            template_vars)
        self.subnetwork.create(network.name, service_name, blueprint=blueprint)
        instances_blueprint = ServiceBlueprint.from_file(blueprint)
        az_count = instances_blueprint.availability_zone_count()
        availability_zones = list(
            itertools.islice(self._get_availability_zones(), az_count))
        if len(availability_zones) < az_count:
            raise DisallowedOperationException(
                "Do not have %s availability zones: %s" %
                (az_count, availability_zones))
        instance_count = az_count
        if count:
            instance_count = count

        def get_image(image_specifier):
            images = [
                image for image in self.driver.list_images()
                if re.match(image_specifier, image.name)
            ]
            if not images:
                raise DisallowedOperationException(
                    "Could not find image named %s" % image_specifier)
            if len(images) > 1:
                raise DisallowedOperationException(
                    "Found multiple images for specifier %s: %s" %
                    (image_specifier, images))
            return images[0]

        image = get_image(instances_blueprint.image())
        instance_type = get_fitting_instance(self, instances_blueprint)
        for availability_zone, instance_num in zip(
                itertools.cycle(availability_zones), range(0, instance_count)):
            full_subnetwork_name = "%s-%s" % (network.name, service_name)
            instance_name = "%s-%s" % (full_subnetwork_name, instance_num)
            metadata = [{
                "key":
                "startup-script",
                "value":
                instances_blueprint.runtime_scripts(template_vars)
            }, {
                "key": "network",
                "value": network.name
            }, {
                "key": "subnetwork",
                "value": service_name
            }]
            logger.info('Creating instance %s in zone %s', instance_name,
                        availability_zone.name)
            self.driver.create_node(instance_name,
                                    instance_type,
                                    image,
                                    location=availability_zone,
                                    ex_network=network.name,
                                    ex_subnetwork=full_subnetwork_name,
                                    external_ip="ephemeral",
                                    ex_metadata=metadata,
                                    ex_tags=[full_subnetwork_name])
        return self.get(network, service_name)