Пример #1
0
def get_image(request, image_id):
    try:
        response = ec2_client(request).describe_images(ImageIds=[image_id])
    except ClientError as e:
        if e.response['Error']['Code'] == 'InvalidImage.NotFound':
            return None
        else:
            return None
    return to_wrapping_list(response, "Images", Image)[0]
Пример #2
0
def get_security_group(request, sg_name):
    """Get security groups."""
    try:
        response = ec2_client(request).describe_security_groups(
            GroupNames=[sg_name])
    except ClientError as e:
        if e.response['Error']['Code'] == 'InvalidGroup.NotFound':
            return None
        else:
            return None
    return to_wrapping_list(response, "SecurityGroups", SecurityGroup)[0]
Пример #3
0
def list_image(request, params=[]):
    # TODO Need a more detailed implementation of list lookup
    if len(params):
        filters = params
    else:
        filters = [
            {
                "Name":
                "name",
                "Values": [
                    "RHEL-7*",
                    "suse-sles-12-*",
                    "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*",
                    "amzn-ami-hvm-*",
                    "Windows_Server-2016*",
                    "import*",
                    "export*",
                ]
            },
        ]
    response = ec2_client(request).describe_images(Filters=filters)
    return to_wrapping_list(response, "Images", Image)
Пример #4
0
def list_import_image_task(request):
    response = ec2_client(request).describe_import_image_tasks()
    return to_wrapping_list(response, "ImportImageTasks", ImportTask)
Пример #5
0
def list_export_task(request):
    response = ec2_client(request).describe_export_tasks()
    return to_wrapping_list(response, "ExportTasks", ExportTask)
Пример #6
0
def list_availability_zones(request):
    """Get the list of availability zone."""
    response = ec2_client(request).describe_availability_zones()
    return to_wrapping_list(response, "AvailabilityZones", AvailabilityZone)
Пример #7
0
def list_regions(request):
    """Get the list of region."""
    response = ec2_client(request).describe_regions()
    return to_wrapping_list(response, "Regions", Region)
Пример #8
0
def get_keypair(request, key_name):
    """Get ssh key."""
    response = ec2_client(request).describe_key_pairs(KeyNames=[key_name])
    return to_wrapping_list(response, "KeyPairs", KeyPair)[0]
Пример #9
0
def list_keypairs(request):
    """Get the list of ssh key."""
    response = ec2_client(request).describe_key_pairs()
    return to_wrapping_list(response, "KeyPairs", KeyPair)
Пример #10
0
def list_security_groups(request):
    """Get the list of available security groups."""
    response = ec2_client(request).describe_security_groups()
    return to_wrapping_list(response, "SecurityGroups", SecurityGroup)