Пример #1
0
def main():
    arguments_list = [['--profile', '-p'], ['--region',
                                            '-r'], ['--rds', '-rds'],
                      ['--create', '-c'], ['--delete', '-d'],
                      ['--delete-name', '-dn'], ['--protocol', '-pr'],
                      ['--ip', '-i'], ['--port', '-po'],
                      ['--rules-from', '-rf'], ['--fields', '-f']]

    parser = argparse.ArgumentParser()
    parser = fast_add_arguments(arguments_list, parser)
    args = parser.parse_args()

    client_config = Client_Config()

    if args.profile:
        client_config.set_profile(args.profile)
    if args.region:
        client_config.set_region(args.region)
    if args.create:
        create_sg(args)
    elif args.delete:
        ec2 = Client()
        sgclient = SG_Client()
        sgs_to_delete = args.delete.split(",")
        for sg_to_delete in sgs_to_delete:
            sgclient.set_client(ec2).set_group_id(sg_to_delete).delete_sg()
    elif args.delete_name:
        ec2 = Client()
        sgclient = SG_Client()
        sgsnames_to_delete = args.delete_name.split(",")
        for sgname_to_delete in sgsnames_to_delete:
            sgclient.set_client(ec2).set_group_name(
                sgname_to_delete).delete_sg()
    elif args.rules_from:
        get_rules_from(client_config, args)
    else:
        list_sg(args, client_config)
from awssg.Client_Config import Client_Config
from awssg.VPC_Client import VPC_Client
from danilocgsilvame_python_helpers.DcgsPythonHelpers import DcgsPythonHelpers
import os

args = DcgsPythonHelpers().command_line_argument_names(
    'region', 'r',
    'profile', 'p'
)

if not args.region:
    print("You need to specify a region with --region <region-name> or -r <region-name> after script.")
    exit()

if not args.profile:
    print("You need to specify a profile with --profile <profile-name> or -p <profile-name> after script.")
    exit()

os.environ["AWS_PROFILE"] = args.profile

Client_Config().set_region(args.region)

client = VPC_Client()
results = client.fetch_vpcs_list_names()

for result in results:
    print(" * " + result)
Пример #3
0
def readable_loop_regions_securities_groups(client_config: Client_Config,
                                            fields: str) -> str:
    regions = get_regions(client_config.get_client())
    for region in regions:
        print("Region: " + region)
        print(readable_single_region_data(region, client_config))
Пример #4
0
import sys
import argparse
sys.path.insert(1, '..')
from awssg.Client_Config import Client_Config
from awssg.Fetcher import Fetcher
from awssg.Helpers import fast_add_arguments

client_config = Client_Config()

arguments_list = [
    ['--profile', '-p'],
    ['--region', '-r']
]
parser = argparse.ArgumentParser()
parser = fast_add_arguments(arguments_list, parser)
args = parser.parse_args()


if args.profile is not None:
    client_config.set_profile(args.profile)

if args.region is not None:
    client_config.set_region(args.region)

fetcher = Fetcher()
fetcher.set_client(client_config.get_client())
print(fetcher.get_all_regions_data())
Пример #5
0
        "The command has been stoped. You need to provides a name for security group thorugh -n or --name parameter."
    )
    exit()

print(
    "This action will create a real security group in your infraestructure, just to show the output results."
)
response = input(
    "Are you sure to do so? Type yes. Otherwise, the action will be canceled: "
)

if not response == "yes":
    print("Cancelling...")
    exit()

client_config = Client_Config()

if args.region:
    client_config.set_region(args.region)

ec2 = Client()
sg_client = SG_Client()
sg_client.set_client(ec2).set_group_name(args.name)
if sg_client.is_multiples_vpcs():
    ask = Ask(sg_client.fetch_vpcs_list_names())
    vpc_choosed = None
    try:
        vpc_choosed = ask.ask(
            "Which vpc do you would like to setup the security group?:")
    except AskException:
        print("You choosed an invalid option. Quiting, nothing done.")
Пример #6
0
import argparse
import os

sys.path.insert(1, '..')
from awssg.Client_Config import Client_Config
from awssg.Helpers import fast_add_arguments
from awssg.Client import Client
from danilocgsilvame_python_helpers.DcgsPythonHelpers import DcgsPythonHelpers

args = DcgsPythonHelpers().command_line_argument_names('region', 'r',
                                                       'profile', 'p')

if not args.profile:
    print(
        "You must specify a profile name with --profile or -p argument in commando line."
    )
    exit()

os.environ["AWS_PROFILE"] = args.profile

client_config = Client_Config()

if args.profile is not None:
    client_config.set_profile(args.profile)

if args.region is not None:
    client_config.set_region(args.region)

vpcs_data = Client().describe_vpcs()

print(vpcs_data)