Пример #1
0
def deletekeypair(keypair_choices):
    #print("deleting keypair")
    progressbar("Deleting Keypair")
    keypairname = keypair_choices['keypair'][0]
    try:
        ec2.delete_key_pair(KeyName=str(keypairname))
        print("\n \n Keypair " + keypairname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting keypair: \n\n\n")
        print(e)
Пример #2
0
def deletevpc(vpc_choices):
    #print("deleting vpc")
    progressbar("Deleting VPC")
    vpcname = vpc_choices['vpc'][0]
    try:
        ec2.delete_vpc(VpcId=str(vpcname))
        print("\n \n vpc " + vpcname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting vpc: \n\n\n")
        print(e)
Пример #3
0
def deletesecuritygroup(securitygroup_choices):
    #print("deleting securitygroup")
    progressbar("Deleting Security Group")
    securitygroupname = securitygroup_choices['securitygroup'][0]
    try:

        print("\n \n securitygroup " + securitygroupname +
              " has been deleted \n \n")
        ec2.delete_security_group(GroupId=str(securitygroupname))
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting security group: \n\n\n")
        print(e)
Пример #4
0
def deleteuser(user_choices):
    """
    This function is used to delete user by giving/selecting parameters
    """
    progressbar("Deleting user")
    username = user_choices['user'][0]
    try:
        iam.delete_user(UserName=str(username))
        print("\n \n User " + username + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting user: \n\n\n")
        print(e)
Пример #5
0
def terminateinstance(instance_choices):
    #print("Terminating Instance")
    progressbar("Terminating Instance")
    instancename = instance_choices['instance'][0]
    try:
        ec2.terminate_instances(InstanceIds=[
            str(instancename),
        ])
        print("\n \n Instance " + instancename + " has been terminated \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while terminating instance: \n\n\n")
        print(e)
Пример #6
0
def deletegroup(group_choices):
    """
    This function is used to delete group by giving/selecting parameters
    """
    progressbar("Deleting Group")
    groupname = group_choices['group'][0]
    try:
        iam.delete_group(GroupName=str(groupname))
        print("\n \n Group " + groupname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting group: \n\n\n")
        print(e)
Пример #7
0
def deleteaccesskey(accesskey_choices):
    """
    This function is used to delete accesskey by giving/selecting parameters
    """
    progressbar("Deleting Access Key")
    accesskeyname = accesskey_choices['accesskey'][0]
    try:

        iam.delete_access_key(AccessKeyId=str(accesskeyname))
        print("\n \n Accesskey " + accesskeyname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting access key: \n\n\n")
        print(e)
Пример #8
0
def deleteobject(bucket_choices, object_choices):
    """
    This function is used to delete the objects/s in S3

    """
    progressbar("Deleting Object")
    bucketname = bucket_choices['bucket'][0]
    objectnames = object_choices['object']
    try:
        for objectname in objectnames:
            s3.delete_object(Bucket=str(bucketname), Key=str(objectname))
            print("\n \n Object " + objectname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting object: \n\n\n")
        print(e)
Пример #9
0
def deletebucket(bucket_choices):
    """
    This function is used to delete the bucket/s in S3

    """
    progressbar("Deleting Bucket")

    bucketnames = bucket_choices['bucket']
    try:
        for bucketname in bucketnames:
            s3.delete_bucket(Bucket=str(bucketname))
            print("\n \n Bucket " + bucketname + " has been deleted \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting Bucket: \n\n\n")
        print(e)
Пример #10
0
def download_object(bucket_choices, object_choices):
    ### ERROR : Getting file not found error

    progressbar("Downloading Object")
    bucketname = bucket_choices['bucket'][0]
    objectnames = object_choices['object']
    try:
        for objectname in objectnames:
            print(objectname)
            s3r.Bucket(str(bucketname)).download_file(
                str(objectname), '/~/buckets' + str(objectname))
            #s3r.meta.client.download_file(str(bucketname), str(objectname), '~/')

            print("\n \n Object " + objectname + " has been downloaded \n \n")
    except botocore.exceptions.ClientError as e:
        coloredtext("There was an error while deleting object: \n\n\n")
        print(e)
Пример #11
0
def s3actions(action):
    # TODO : resolve Location constraint error (ap-south working)
    if action == 'Create Bucket':

        bucket_name = input(
            "What is the name of the bucket you want to create ( Use comma if you want to create multiple buckets): "
        )  ###Need to add this functionality later (from mobile app script)
        region_choices = prompt(region_choice, style=custom_style_2)
        pprint(region_choices)
        region = region_choices['region']

        if getconfirmation():

            progressbar("Creating Bucket")
            try:
                s3.create_bucket(Bucket=str(bucket_name),
                                 CreateBucketConfiguration={
                                     'LocationConstraint': str(region)
                                 })
                print("\n \n Bucket " + bucket_name +
                      " has been created \n \n")
            except botocore.exceptions.ClientError as e:
                coloredtext("There was an error while creating Bucket: \n\n\n")
                print(e)

        confirm_or_exit('S3')

    if action == 'Delete Bucket':

        bucket_choices = prompt(bucket_choice, style=custom_style_2)
        pprint(bucket_choices)
        if getconfirmation():

            s3class.deletebucket(bucket_choices)

        confirm_or_exit('S3')

    if action == 'List Bucket Objects':

        bucket_choices = prompt(bucket_choice, style=custom_style_2)
        pprint(bucket_choices)

        s3class.listobjects(bucket_choices)

        s3objectquestions = [{
            'type':
            'list',
            'name':
            'objectaction',
            'message':
            'Which action do you want to make ?',
            'choices': [
                'Upload object to bucket', 'Delete Object from Bucket',
                'Download object from Bucket', 'Go Back'
            ]
        }]

        def delete_object(
                bucket_choices):  # inner function Hidden from outer code
            print(bucket_choices['bucket'][0])
            object_list = s3class.listobjects(bucket_choices)
            object_choice = [{
                'type': 'checkbox',
                'qmark': '😃',
                'message': 'Select objects',
                'name': 'object',
                #'choices': ['test1','test2'],
                'choices': object_list
            }]
            object_choices = prompt(object_choice, style=custom_style_2)
            pprint(object_choices)
            s3class.deleteobject(bucket_choices, object_choices)
            confirm_or_exit('S3')

        def download_object(
                bucket_choices):  # inner function Hidden from outer code
            print(bucket_choices['bucket'][0])
            object_list = s3class.listobjects(bucket_choices)
            object_choice = [{
                'type': 'checkbox',
                'qmark': '😃',
                'message': 'Select objects',
                'name': 'object',
                #'choices': ['test1','test2'],
                'choices': object_list
            }]
            object_choices = prompt(object_choice, style=custom_style_2)
            pprint(object_choices)
            s3class.download_object(bucket_choices, object_choices)
            confirm_or_exit('S3')

        s3objectprompt = prompt(s3objectquestions, style=custom_style_2)
        s3objectaction = s3objectprompt['objectaction']
        if s3objectaction == 'Go Back':
            main()
        elif s3objectaction == 'Delete Object from Bucket':

            delete_object(bucket_choices)

        elif s3objectaction == 'Download object from Bucket':

            download_object(bucket_choices)

    if action == 'Delete Object from Bucket':
        print("test")