def delete_everything(my_settings: Settings):
    if my_settings.resources_created and om_manager.is_opsman_configured(
            my_settings):
        cmd = om_manager.get_om_with_auth(my_settings) + [
            "delete-installation"
        ]
        # delete blocks on apply-changes, but if other apply changes in progress, doesn't queue up its own
        util.exponential_backoff_cmd(cmd)
        out, err, return_code = util.exponential_backoff_cmd(cmd)
        if return_code != 0:
            print(
                "OM cmd failed to delete installation {}".format(return_code))
            return out, err, return_code

    delete_keypair(my_settings)

    buckets = [
        my_settings.pcf_opsmanagers3bucket,
        my_settings.pcf_elasticruntimes3buildpacksbucket,
        my_settings.pcf_elasticruntimes3dropletsbucket,
        my_settings.pcf_elasticruntimes3packagesbucket,
        my_settings.pcf_elasticruntimes3resourcesbucket
    ]
    for bucket_name in buckets:
        try:
            expire_bucket(my_settings, bucket_name)
        except Exception as e:
            print(e)
    return "", "", 0
 def test_get_om_with_auth(self):
     expected_om_command = ["om",
                            "-k",
                            "--target", "https://cf.example.com",
                            "--username", "admin",
                            "--password", "monkey-123"]
     om_command = om_manager.get_om_with_auth(self.settings)
     self.assertEqual(om_command, expected_om_command)
def upload_stemcell(my_settings: settings.Settings, path: str):
    for stemcell in os.listdir(path):
        if stemcell.endswith(".tgz"):
            print("uploading stemcell {0}".format(stemcell))
            cmd = "{om_with_auth} upload-stemcell -s '{path}'".format(
                om_with_auth=om_manager.get_om_with_auth(my_settings),
                path=os.path.join(path, stemcell))
            out, err, exit_code = util.exponential_backoff_cmd(cmd)
            if exit_code != 0:
                return out, err, exit_code

    return "", "", 0
Beispiel #4
0
def configure_ert_multiaz_resources(my_settings: Settings):
    if my_settings.pcf_pcfdeploymentsize == "Multi-AZ":
        with open("templates/ert_multiaz_resources_config.j2.json", 'r') as f:
            template = f.read()
    else:
        with open("templates/ert_singleaz_resources_config.j2.json", 'r') as f:
            template = f.read()

    ert_resource_config = om_manager.format_om_json_str(template)
    cmd = "{om_with_auth} configure-product -n cf -pr '{ert_resources}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings),
        ert_resources=ert_resource_config)
    return util.exponential_backoff_cmd(cmd)
Beispiel #5
0
def configure_tile_az(my_settings: Settings, tile_name: str):
    az_template_ctx = {
        "singleton_availability_zone": my_settings.zones[0],
        "zones": my_settings.zones
    }
    with open("templates/tile_az_config.j2.json", 'r') as f:
        az_template = Template(f.read())
    az_config = om_manager.format_om_json_str(
        az_template.render(az_template_ctx))
    cmd = om_manager.get_om_with_auth(my_settings) + [
        "configure-product", "-n", tile_name, "-pn", az_config
    ]

    return util.exponential_backoff_cmd(cmd)
def upload_assets(my_settings: settings.Settings, path: str):
    for tile in os.listdir(path):
        if tile.endswith(".pivotal"):
            print("uploading product {0}".format(tile))

            cmd = om_manager.get_om_with_auth(my_settings) + [
                "-r", "3600", "upload-product", "-p",
                os.path.join(path, tile)
            ]
            out, err, exit_code = util.exponential_backoff_cmd(cmd)
            if exit_code != 0:
                return out, err, exit_code

    return "", "", 0
Beispiel #7
0
def configure_ert_resources(my_settings: Settings):
    ert_resource_ctx = {
        "pcf_elb_tcp_name": my_settings.pcf_pcfelbtcpname,
        "pcf_elb_ssh_name": my_settings.pcf_pcfelbsshname,
        "pcf_elb_web_name": my_settings.pcf_pcfelbwebname,
    }
    with open("templates/ert_resources_config.j2.json", 'r') as f:
        ert_resource_template = Template(f.read())
    ert_resource_config = om_manager.format_om_json_str(
        ert_resource_template.render(ert_resource_ctx))
    cmd = "{om_with_auth} configure-product -n cf -pr '{ert_resources}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings),
        ert_resources=ert_resource_config)
    return util.exponential_backoff_cmd(cmd)
def configure_opsman_director(my_settings: Settings):
    keyname, keybytes = generate_ssh_keypair(my_settings)

    template_ctx = {
        "zones": my_settings.zones,
        "access_key_id": my_settings.pcf_iamuseraccesskey,
        "secret_access_key": my_settings.pcf_iamusersecretaccesskey,
        "vpc_id": my_settings.pcf_vpc,
        "security_group": my_settings.pcf_vmssecuritygroupid,
        "key_pair_name": keyname,
        "ssh_private_key": keybytes.replace("\n", "\\n"),
        "region": my_settings.region,
        "encrypted": "false",
        "pcf_management_subnet_az1": my_settings.pcf_pcfmanagementsubnetaz1,
        "pcf_management_subnet_az2": my_settings.pcf_pcfmanagementsubnetaz2,
        "pcf_management_subnet_az3": my_settings.pcf_pcfmanagementsubnetaz3,
        "pcf_ert_subnet_az1": my_settings.pcf_pcfertsubnetaz1,
        "pcf_ert_subnet_az2": my_settings.pcf_pcfertsubnetaz2,
        "pcf_ert_subnet_az3": my_settings.pcf_pcfertsubnetaz3,
        "pcf_services_subnet_az1": my_settings.pcf_pcfservicessubnetaz1,
        "pcf_services_subnet_az2": my_settings.pcf_pcfservicessubnetaz2,
        "pcf_services_subnet_az3": my_settings.pcf_pcfservicessubnetaz3,
        "az1": my_settings.pcf_pcfavailabilityzone1,
        "az2": my_settings.pcf_pcfavailabilityzone2,
        "az3": my_settings.pcf_pcfavailabilityzone3,
        "singleton_availability_zone": my_settings.pcf_pcfavailabilityzone1
    }
    with open("templates/director_config.j2.yml", 'r') as f:
        director_template = Template(f.read())

    director_config = director_template.render(template_ctx)
    with tempfile.NamedTemporaryFile(mode='w') as f:
        f.write(director_config)
        f.flush()

        cmd = om_manager.get_om_with_auth(my_settings) + [
            "configure-director",
            "--config", f.name
        ]
        out, err, exit_code = util.run_command(cmd)
        if out != "":
            print(out)
        if err != "":
            print(err)
        if exit_code != 0:
            return out, err, exit_code

    return out, err, 0
Beispiel #9
0
def configure_ert_multiaz_resources(my_settings: Settings):
    if my_settings.pcf_pcfdeploymentsize == "SmallFootPrint":
        with open("templates/ert_smallfootprint_resources_config.j2.json",
                  'r') as f:
            template = f.read()
    elif my_settings.pcf_pcfdeploymentsize == "Multi-AZ":
        with open("templates/ert_multiaz_resources_config.j2.json", 'r') as f:
            template = f.read()
    else:
        with open("templates/ert_singleaz_resources_config.j2.json", 'r') as f:
            template = f.read()

    ert_resource_config = om_manager.format_om_json_str(template)
    cmd = om_manager.get_om_with_auth(my_settings) + [
        "configure-product", "-n", "cf", "-pr", ert_resource_config
    ]
    return util.exponential_backoff_cmd(cmd)
Beispiel #10
0
def configure_ert_resources(my_settings: Settings):
    ert_resource_ctx = {
        "pcf_elb_tcp_name": my_settings.pcf_pcfelbtcpname,
        "pcf_elb_ssh_name": my_settings.pcf_pcfelbsshname,
        "pcf_elb_web_name": my_settings.pcf_pcfelbwebname,
    }
    if my_settings.pcf_pcfdeploymentsize == "SmallFootPrint":
        with open("templates/ert_resources_smallfootprint_config.j2.json",
                  'r') as f:
            ert_resource_template = Template(f.read())
    else:
        with open("templates/ert_resources_config.j2.json", 'r') as f:
            ert_resource_template = Template(f.read())

    ert_resource_config = om_manager.format_om_json_str(
        ert_resource_template.render(ert_resource_ctx))
    cmd = om_manager.get_om_with_auth(my_settings) + [
        "configure-product", "-n", "cf", "-pr", ert_resource_config
    ]
    return util.exponential_backoff_cmd(cmd)
Beispiel #11
0
def configure_aws_service_broker_config(my_settings: Settings):
    cert, key = generate_ssl_cert(my_settings)
    aws_config_template_ctx = {
        "aws_region": my_settings.region,
        "aws_service_bucket": my_settings.pcf_elasticruntimes3buildpacksbucket,
        "aws_s3_region": my_settings.region,
        "aws_iam_access_key_id": my_settings.broker_iamuseraccesskey,
        "aws_iam_secret_access_key": my_settings.broker_iamusersecretaccesskey,
        "pcf_skipsslvalidation": my_settings.pcf_input_skipsslvalidation,
        "cert": cert.replace("\n", "\\n"),
        "key": key.replace("\n", "\\n")
    }
    with open("templates/aws_service_broker_config.j2.json", 'r') as f:
        aws_broker_template = Template(f.read())
    aws_config = om_manager.format_om_json_str(
        aws_broker_template.render(aws_config_template_ctx))
    cmd = om_manager.get_om_with_auth(my_settings) + [
        "configure-product", "-n", "aws-service-broker", "-p", aws_config
    ]
    return util.exponential_backoff_cmd(cmd)
Beispiel #12
0
def configure_ert_config(my_settings: Settings):
    cert, key = generate_ssl_cert(my_settings)
    credhub_encryption_key = ''.join(
        random.choice(string.ascii_uppercase + string.ascii_lowercase +
                      string.digits) for _ in range(32))
    ert_config_template_ctx = {
        "pcf_rds_address": my_settings.pcf_rdsaddress,
        "pcf_rds_username": my_settings.pcf_rdsusername,
        "dns_suffix": my_settings.pcf_input_domain,
        "pcf_rds_password": my_settings.pcf_rdspassword,
        "admin_email": my_settings.pcf_input_adminemail,
        "pcf_elastic_runtime_s3_buildpacks_bucket":
        my_settings.pcf_elasticruntimes3buildpacksbucket,
        "pcf_elastic_runtime_s3_droplets_bucket":
        my_settings.pcf_elasticruntimes3dropletsbucket,
        "pcf_elastic_runtime_s3_packages_bucket":
        my_settings.pcf_elasticruntimes3packagesbucket,
        "pcf_elastic_runtime_s3_resources_bucket":
        my_settings.pcf_elasticruntimes3resourcesbucket,
        "pcf_iam_access_key_id": my_settings.pcf_iamuseraccesskey,
        "pcf_iam_secret_access_key": my_settings.pcf_iamusersecretaccesskey,
        "pcf_companyname": my_settings.pcf_pcfcompanyname,
        "s3_endpoint": my_settings.get_s3_endpoint(),
        "s3_region": my_settings.region,
        "pcf_skipsslvalidation": my_settings.pcf_input_skipsslvalidation,
        "credhub_encryption_key": credhub_encryption_key,
        "cert": cert.replace("\n", "\\n"),
        "key": key.replace("\n", "\\n")
    }
    with open("templates/ert_config.j2.json", 'r') as f:
        ert_template = Template(f.read())
    ert_config = om_manager.format_om_json_str(
        ert_template.render(ert_config_template_ctx))
    cmd = om_manager.get_om_with_auth(my_settings) + [
        "configure-product", "-n", "cf", "-p", ert_config
    ]
    return util.exponential_backoff_cmd(cmd)
Beispiel #13
0
def configure_opsman_director(my_settings: Settings):
    keyname, keybytes = generate_ssh_keypair(my_settings)

    director_config = '{"ntp_servers_string": "0.amazon.pool.ntp.org,1.amazon.pool.ntp.org,2.amazon.pool.ntp.org,3.amazon.pool.ntp.org"}'

    template_ctx = {
        "zones": my_settings.zones,
        "access_key_id": my_settings.pcf_iamuseraccesskey,
        "secret_access_key": my_settings.pcf_iamusersecretaccesskey,
        "vpc_id": my_settings.pcf_vpc,
        "security_group": my_settings.pcf_vmssecuritygroupid,
        "key_pair_name": keyname,
        "ssh_private_key": keybytes.replace("\n", "\\n"),
        "region": my_settings.region,
        "encrypted": "false",
        "pcf_management_subnet_az1": my_settings.pcf_pcfmanagementsubnetaz1,
        "pcf_management_subnet_az2": my_settings.pcf_pcfmanagementsubnetaz2,
        "pcf_management_subnet_az3": my_settings.pcf_pcfmanagementsubnetaz3,
        "pcf_ert_subnet_az1": my_settings.pcf_pcfertsubnetaz1,
        "pcf_ert_subnet_az2": my_settings.pcf_pcfertsubnetaz2,
        "pcf_ert_subnet_az3": my_settings.pcf_pcfertsubnetaz3,
        "pcf_services_subnet_az1": my_settings.pcf_pcfservicessubnetaz1,
        "pcf_services_subnet_az2": my_settings.pcf_pcfservicessubnetaz2,
        "pcf_services_subnet_az3": my_settings.pcf_pcfservicessubnetaz3,
        "az1": my_settings.pcf_pcfavailabilityzone1,
        "az2": my_settings.pcf_pcfavailabilityzone2,
        "az3": my_settings.pcf_pcfavailabilityzone3,
        "singleton_availability_zone": my_settings.pcf_pcfavailabilityzone1
    }
    with open("templates/bosh_az_config.j2.json", 'r') as f:
        az_template = Template(f.read())
    with open("templates/bosh_network_config.j2.json", 'r') as f:
        network_template = Template(f.read())
    with open("templates/bosh_iaas_config.j2.json", 'r') as f:
        iaas_template = Template(f.read())
    with open("templates/bosh_network_assignment.j2.json", 'r') as f:
        network_assignment_template = Template(f.read())

    az_config = az_template.render(template_ctx).replace("\n", "")
    network_config = network_template.render(template_ctx).replace("\n", "")
    network_assignment_config = network_assignment_template.render(template_ctx).replace("\n", "")
    iaas_config = iaas_template.render(template_ctx).replace("\n", "")

    commands = []
    commands.append("{om_with_auth} configure-bosh --iaas-configuration '{iaas_config}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings), iaas_config=iaas_config
    ))
    commands.append("{om_with_auth} configure-bosh --director-configuration '{director_config}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings), director_config=director_config
    ))
    commands.append("{om_with_auth} configure-bosh --az-configuration '{az_config}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings), az_config=az_config
    ))
    commands.append("{om_with_auth} configure-bosh --networks-configuration '{network_config}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings), network_config=network_config
    ))
    commands.append("{om_with_auth} configure-bosh --network-assignment '{network_assignment}'".format(
        om_with_auth=om_manager.get_om_with_auth(my_settings), network_assignment=network_assignment_config
    ))
    out = err = ""
    for cmd in commands:
        out, err, exit_code = util.run_command(cmd)
        if out != "":
            print(out)
        if err != "":
            print(err)
        if exit_code != 0:
            return out, err, exit_code

    return out, err, 0
 def test_get_om_with_auth(self):
     expected_om_command = "om -k --target https://cf.example.com --username 'admin' --password 'monkey-123'"
     om_command = om_manager.get_om_with_auth(self.settings)
     self.assertEqual(om_command, expected_om_command)