예제 #1
0
def main(argv):
    pp = pprint.PrettyPrinter(indent=4)

    if len(sys.argv) != 3:
        print "You need to give me the region and the zone. In that order."
        exit(1)

    region = sys.argv[1]
    zone = sys.argv[2]

    spinnaker_address = SPINNAKER_HOST
    
    cluster_json_file = '../files/gcp/spinnaker-and-jenkins/cluster_delete.json'
    load_balancer_json_file = '../files/gcp/spinnaker-and-jenkins/loadbalancer_delete.json'

    cluster = {}
    load_balancer = {}

    with open(cluster_json_file) as cluster_file:
        cluster = json.load(cluster_file)

    with open(load_balancer_json_file) as lb_file:
        load_balancer = json.load(lb_file)

    spin_tools = spinnaker(spinnaker_address=spinnaker_address,
                           spinnaker_port=SPINNAKER_PORT, gate_port=GATE_PORT)

    '''
    Set the cluster variables
    '''
    cluster['job'][0]['region'] = region
    cluster['job'][0]['regions'] = [ region ]
    cluster['job'][0]['zone'] = region + '-' + zone
    cluster['job'][0]['zones'] = [ region + '-' + zone ]

    '''
    Set the load_balancer variables
    '''
    load_balancer['job'][0]['region'] = region
    load_balancer['job'][0]['regions'] = [ region ]

    '''
    print '----'
    pp.pprint(cluster)
    print '----'
    pp.pprint(load_balancer)
    print '----'
    '''

    if spin_tools.cluster(cluster, action='delete'):
        print "Cluster deletion successful..."
    else:
        print "Cluster deletion failed."
        print spin_tools.error_response

    if spin_tools.load_balancer(load_balancer, action='delete'):
        print "Load Balancer deletion successful..."
    else:
        print "Load Balancer Deletion failed."
        print spin_tools.error_response
def main(argv):
    arguments = docopt(__doc__, version=str(os.path.basename(__file__)) + " " + VERSION, options_first=False)

    if arguments["--spinnaker_address"] is not None:
        spinnaker_address = arguments["--spinnaker_address"]
    else:
        spinnaker_address = SPINNAKER_HOST

    pp = pprint.PrettyPrinter(indent=4)

    app_name = arguments["--app_name"]
    pipeline_name = arguments["--pipeline_name"]
    sg_id = arguments["--sg_id"]
    aws_region = arguments["--aws_region"]
    vpc_id = arguments["--vpc_id"]
    vpc_sg_id = arguments["--vpc_sg_id"]
    mgmt_sg_id = arguments["--mgmt_sg_id"]
    vpc_name = arguments["--vpc_name"]
    iam_role = arguments["--iam_role"]

    pipeline_json_file = "pipeline_create.json"
    app_json_file = "application_create.json"
    lb_json_file = "loadbalancer_create.json"

    pipeline = {}
    application = {}
    loadbalancer = {}

    aws_conn = boto.vpc.connect_to_region(aws_region)

    spin_tools = spinnaker(spinnaker_address=spinnaker_address, spinnaker_port=SPINNAKER_PORT, gate_port=GATE_PORT)

    with open(pipeline_json_file) as pipeline_file:
        pipeline = json.load(pipeline_file)

    with open(app_json_file) as app_file:
        application = json.load(app_file)

    with open(lb_json_file) as lb_file:
        loadbalancer = json.load(lb_file)

    stack = "teststack"
    detail = "testdetail"

    """
    Get the subnet information
    """
    subnet_type = pipeline["stages"][1]["clusters"][0]["subnetType"]

    tag_name_filter = vpc_name + "." + re.sub("\ \(.*\)", "", subnet_type) + "." + aws_region

    try:
        all_subnets = aws_conn.get_all_subnets(filters={"vpc_id": vpc_id, "tag:Name": tag_name_filter})
    except Exception, e:
        print "ERROR: Could not connect to AWS. Check your aws keys."
        exit(1)
def main(argv):
    arguments = docopt(__doc__,
                       version=str(os.path.basename(__file__)) + " " + VERSION,
                       options_first=False)

    if arguments['--spinnaker_address'] is not None:
        spinnaker_address = arguments['--spinnaker_address']
    else:
        spinnaker_address = SPINNAKER_HOST

    pp = pprint.PrettyPrinter(indent=4)

    app_name = arguments['--app_name']
    pipeline_name = arguments['--pipeline_name']
    sg_id = arguments['--sg_id']
    aws_region = arguments['--aws_region']
    vpc_id = arguments['--vpc_id']
    vpc_sg_id = arguments['--vpc_sg_id']
    mgmt_sg_id = arguments['--mgmt_sg_id']
    vpc_name = arguments['--vpc_name']
    iam_role = arguments['--iam_role']

    pipeline_json_file = 'pipeline_create.json'
    app_json_file = 'application_create.json'
    lb_json_file = 'loadbalancer_create.json'

    pipeline = {}
    application = {}
    loadbalancer = {}

    aws_conn = boto.vpc.connect_to_region(aws_region)

    spin_tools = spinnaker(spinnaker_address=spinnaker_address,
                           spinnaker_port=SPINNAKER_PORT,
                           gate_port=GATE_PORT)

    with open(pipeline_json_file) as pipeline_file:
        pipeline = json.load(pipeline_file)

    with open(app_json_file) as app_file:
        application = json.load(app_file)

    with open(lb_json_file) as lb_file:
        loadbalancer = json.load(lb_file)

    stack = 'teststack'
    detail = 'testdetail'
    '''
    Get the subnet information
    '''
    subnet_type = pipeline['stages'][1]['clusters'][0]['subnetType']

    tag_name_filter = vpc_name + "." + \
        re.sub("\ \(.*\)", '', subnet_type) + "." + aws_region

    try:
        all_subnets = aws_conn.get_all_subnets(filters={
            'vpc_id': vpc_id,
            'tag:Name': tag_name_filter
        })
    except Exception, e:
        print "ERROR: Could not connect to AWS. Check your aws keys."
        exit(1)
def main(argv):
    arguments = docopt(__doc__, version=str(
        os.path.basename(__file__)) + " " + VERSION, options_first=False)

    if arguments['--spinnaker_address'] is not None:
        spinnaker_address = arguments['--spinnaker_address']
    else:
        spinnaker_address = SPINNAKER_HOST

    pp = pprint.PrettyPrinter(indent=4)

    app_name = arguments['--app_name']
    pipeline_name = arguments['--pipeline_name']
    region = arguments['--region']
    zone = arguments['--zone']
    network = arguments['--network']
    security_group = arguments['--security_group']

    pipeline_json_file = 'pipeline_create.json'
    app_json_file = 'application_create.json'
    lb_json_file = 'loadbalancer_create.json'

    pipeline = {}
    application = {}
    loadbalancer = {}

    spin_tools = spinnaker(spinnaker_address=spinnaker_address,
                           spinnaker_port=SPINNAKER_PORT, gate_port=GATE_PORT)

    with open(pipeline_json_file) as pipeline_file:
        pipeline = json.load(pipeline_file)

    with open(app_json_file) as app_file:
        application = json.load(app_file)

    with open(lb_json_file) as lb_file:
        loadbalancer = json.load(lb_file)

    stack = 'teststack'
    detail = 'testdetail'


    '''
    Configure the special lb vars
    '''
    loadbalancer['job'][0]['region'] = region
    loadbalancer['job'][0]['availabilityZones'][region] = []

    '''
    Configure the special pipeline vars
    '''
    pipeline['stages'][1]['clusters'][0]['zone'] = region + '-' + zone
    pipeline['stages'][1]['clusters'][0]['availabilityZones'][region] = [region + '-' + zone]
    pipeline['stages'][1]['clusters'][0]['network'] = network
    pipeline['stages'][1]['clusters'][0]['securityGroups'] = [security_group] 


    spin_tools.wait_for_8084()

    if spin_tools.create_application(application):
        print "Application Creation Successful..."

        if spin_tools.load_balancer(loadbalancer, action='create'):
            if spin_tools.create_pipeline(pipeline):
                print "Everything created successfully."
            else:
                print "Pipeline creation failed."
                pp.pprint(pipeline)
                print spin_tools.error_response
        else:
            print "Load Balancer Creation failed, not continuing."
            pp.pprint(loadbalancer)

    else:
        print "Application creation failed, not continuing."
        pp.pprint(application)
예제 #5
0
def main(argv):
    arguments = docopt(__doc__,
                       version=str(os.path.basename(__file__)) + " " + VERSION,
                       options_first=False)

    if arguments['--spinnaker_address'] is not None:
        spinnaker_address = arguments['--spinnaker_address']
    else:
        spinnaker_address = SPINNAKER_HOST

    pp = pprint.PrettyPrinter(indent=4)

    app_name = arguments['--app_name']
    pipeline_name = arguments['--pipeline_name']
    region = arguments['--region']
    zone = arguments['--zone']
    network = arguments['--network']
    security_group = arguments['--security_group']

    pipeline_json_file = 'pipeline_create.json'
    app_json_file = 'application_create.json'
    lb_json_file = 'loadbalancer_create.json'

    pipeline = {}
    application = {}
    loadbalancer = {}

    spin_tools = spinnaker(spinnaker_address=spinnaker_address,
                           spinnaker_port=SPINNAKER_PORT,
                           gate_port=GATE_PORT)

    with open(pipeline_json_file) as pipeline_file:
        pipeline = json.load(pipeline_file)

    with open(app_json_file) as app_file:
        application = json.load(app_file)

    with open(lb_json_file) as lb_file:
        loadbalancer = json.load(lb_file)

    stack = 'teststack'
    detail = 'testdetail'
    '''
    Configure the special lb vars
    '''
    loadbalancer['job'][0]['region'] = region
    loadbalancer['job'][0]['availabilityZones'][region] = []
    '''
    Configure the special pipeline vars
    '''
    pipeline['stages'][1]['clusters'][0]['zone'] = region + '-' + zone
    pipeline['stages'][1]['clusters'][0]['availabilityZones'][region] = [
        region + '-' + zone
    ]
    pipeline['stages'][1]['clusters'][0]['network'] = network
    pipeline['stages'][1]['clusters'][0]['securityGroups'] = [security_group]

    spin_tools.wait_for_8084()

    if spin_tools.create_application(application):
        print "Application Creation Successful..."

        if spin_tools.load_balancer(loadbalancer, action='create'):
            if spin_tools.create_pipeline(pipeline):
                print "Everything created successfully."
            else:
                print "Pipeline creation failed."
                pp.pprint(pipeline)
                print spin_tools.error_response
        else:
            print "Load Balancer Creation failed, not continuing."
            pp.pprint(loadbalancer)

    else:
        print "Application creation failed, not continuing."
        pp.pprint(application)
def main(argv):
    arguments = docopt(__doc__, version=str(
        os.path.basename(__file__)) + " " + VERSION, options_first=False)

    if arguments['--spinnaker_address'] is not None:
        spinnaker_address = arguments['--spinnaker_address']
    else:
        spinnaker_address = SPINNAKER_HOST

    pp = pprint.PrettyPrinter(indent=4)

    app_name = arguments['--app_name']
    pipeline_name = arguments['--pipeline_name']
    sg_id = arguments['--sg_id']
    aws_region = arguments['--aws_region']
    vpc_id = arguments['--vpc_id']
    vpc_sg_id = arguments['--vpc_sg_id']
    mgmt_sg_id = arguments['--mgmt_sg_id']
    vpc_name = arguments['--vpc_name']

    pipeline_json_file = 'pipeline.json'
    app_json_file = 'application.json'
    lb_json_file = 'loadbalancer.json'

    pipeline = {}
    application = {}
    loadbalancer = {}

    aws_conn = boto.vpc.connect_to_region(aws_region)

    spin_tools = spinnaker(spinnaker_address=spinnaker_address,
                           spinnaker_port=SPINNAKER_PORT, gate_port=GATE_PORT)

    with open(pipeline_json_file) as pipeline_file:
        pipeline = json.load(pipeline_file)

    with open(app_json_file) as app_file:
        application = json.load(app_file)

    with open(lb_json_file) as lb_file:
        loadbalancer = json.load(lb_file)

    stack = 'teststack'
    detail = 'testdetail'


    '''
    Get the subnet information
    '''
    subnet_type = pipeline['stages'][1]['clusters'][0]['subnetType']

    tag_name_filter = vpc_name + "." + \
        re.sub("\ \(.*\)", '', subnet_type) + "." + aws_region

    '''
    print "Tag Name Filter: " + tag_name_filter
    print "VPC_ID: " + vpc_id
    '''
    
    all_subnets = aws_conn.get_all_subnets(
        filters={'vpc_id': vpc_id, 'tag:Name': tag_name_filter})

    subnet_azs = [s.availability_zone for s in all_subnets]

    if len(subnet_azs) == 1:
        print "No subnets found!"
        exit(1)

    '''
    print "Subnet AZs:" 
    pp.pprint(all_subnets)
    pp.pprint(subnet_azs)
    '''

    '''
    Configure the special load balancer vars
    '''
    loadbalancer['job'][0]['stack'] = stack
    loadbalancer['job'][0]['detail'] = detail

    loadbalancer['job'][0]['vpcId'] = vpc_id
    loadbalancer['job'][0]['region'] = aws_region
    loadbalancer['job'][0]['name'] = app_name + '-' + stack + '-' + detail
    loadbalancer['job'][0]['subnetType'] = "eelb_public (" + vpc_name + ")"

    loadbalancer['job'][0]['availabilityZones'][aws_region] = subnet_azs
    loadbalancer['job'][0]['regionZones'] = subnet_azs

    loadbalancer['application'] = app_name
    loadbalancer['description'] = 'Create Load Balancer: ' + loadbalancer['job'][0]['name']

    '''
    Configure the special pipeline vars
    '''

    pipeline['name'] = pipeline_name

    pipeline['stages'][1]['clusters'][0]['subnetType'] = "ec2_public (" + vpc_name + ")"
    
    pipeline['stages'][1]['clusters'][0][
        'securityGroups'] = [sg_id, vpc_sg_id, mgmt_sg_id]

    pipeline['stages'][1]['clusters'][0][
        'loadBalancers'] = [ app_name + '-' + stack + '-' + detail]

    pipeline['stages'][1]['clusters'][0]['application'] = app_name
    pipeline['stages'][1]['clusters'][0]['stack'] = stack

    pipeline['stages'][0]['regions'] = [aws_region]

    pipeline['stages'][1]['clusters'][0][
        'availabilityZones'][aws_region] = subnet_azs

    pipeline['name'] = pipeline_name
    pipeline['application'] = app_name


    '''
    Configure the special application vars
    '''
    application['app_name'] = app_name


    
    if spin_tools.create_application(application):
        if spin_tools.create_load_balancer(loadbalancer):
            if spin_tools.create_pipeline(pipeline):
                print "Everything created successfully."
            else:
                print "Pipeline creation failed."
                pp.pprint(pipeline)
                print spin_tools.error_response
        else:
            print "Load Balancer Creation failed, not continuing."
            pp.pprint(loadbalancer)
    else:
        print "Application creation failed, not continuing."
        pp.pprint(application)