示例#1
0
def get_instances(ids=None, state=None, tags=None, filters=None):
    ''' Get ec2 instances based on filters. '''

    # apply filters based on arguments
    filter_list = []
    if state:
        filter_list.append({'Name': 'instance-state-name', 'Values': utils.str_to_list(state)})
    if tags:
        utils.add_tag_filters(tags, filter_list)
    if filters:
        utils.add_filters(filters, filter_list)

    # build collection filter arguments
    kwargs = {}
    if filter_list:
        kwargs['Filters'] = filter_list
    if ids:
        kwargs['InstanceIds'] = utils.str_to_list(ids)

    #return a collection of ec2 instances
    return CONN.instances.filter(**kwargs)
示例#2
0
def get_snapshots(owner_id, snapshot_ids=None, volume_ids=None, status=None, tags=None):
    ''' Get ec2 snapshots based on filters '''

    # apply filters based on arguments
    filter_list = []
    filter_list.append({'Name': 'owner-id', 'Values': utils.str_to_list(owner_id)})
    if volume_ids:
        filter_list.append({'Name': 'volume-id', 'Values': utils.str_to_list(volume_ids)})
    if status:
        filter_list.append({'Name': 'status', 'Values': utils.str_to_list(status)})
    if tags:
        utils.add_tag_filters(tags, filter_list)

    kwargs = {}
    if filter_list:
        kwargs['Filters'] = filter_list
    if snapshot_ids:
        kwargs['SnapshotIds'] = utils.str_to_list(snapshot_ids)

    #return a collection of ec2 snapshots
    return CONN.snapshots.filter(**kwargs)
示例#3
0
def get_amis(owner_ids, image_ids=None, tags=None, state=None, filters=None):
    ''' get AMIs based on filters '''

    # apply filters based on arguments
    filter_list = []
    if state:
        filter_list.append({'Name': 'state', 'Values': utils.str_to_list(state)})
    if tags:
        utils.add_tag_filters(tags, filter_list)
    if filters:
        utils.add_filters(filters, filter_list)

    # build collection filter arguments
    kwargs = {}
    if filter_list:
        kwargs['Filters'] = filter_list
    if image_ids:
        kwargs['ImageIds'] = utils.str_to_list(image_ids)
    if owner_ids:
        kwargs['Owners'] = utils.str_to_list(owner_ids)

    #return a collection of ec2 instances
    return CONN.images.filter(**kwargs)