示例#1
0
def step_2_init_infra(create_wait=0):
    init_start_ts = _dt.utcnow()
    log.info("------------- Getting Environment at [%s]", init_start_ts)
    horton.cbd = infra.get_cloudbreak(purge=horton.global_purge,
                                      create_wait=create_wait)
    log.info("------------- Connecting to Environment")
    public_ip = horton.cbd.public_ips[0]
    cbd_url = 'https://' + public_ip + '/cb/api'
    cad_url = 'https://' + public_ip + ':7189'
    log.info("Setting Cloudbreak endpoint to %s", cbd_url)
    utils.set_endpoint(cbd_url)
    log.info("Setting Altus Director endpoint to %s", cad_url)
    utils.set_endpoint(cad_url)
    log.info("------------- Authenticating to Cloudbreak")
    cbd_auth_success = security.service_login(
        service='cloudbreak',
        username=config.profile['email'],
        password=security.get_secret('ADMINPASSWORD'),
        bool_response=False)
    if not cbd_auth_success:
        raise ConnectionError("Couldn't login to Cloudbreak")
    else:
        log.info('Logged into Cloudbreak at [%s]', cbd_url)
    # log.info("------------- Authenticating to Altus Director")
    # cad_auth_success = security.service_login(
    #     service='director',
    #     username=config.profile['username'],
    #     password=security.get_secret('ADMINPASSWORD'),
    #     bool_response=False
    # )
    # if not cad_auth_success:
    #     raise ConnectionError("Couldn't login to Director")
    # else:
    #     log.info('Logged into Director at [%s]', cad_url)
    # Cloudbreak may have just booted and not be ready for queries yet
    log.info("Waiting for Cloudbreak API Calls to be available")
    utils.wait_to_complete(deploy.list_blueprints,
                           bool_response=True,
                           whoville_delay=5,
                           whoville_max_wait=120)
    # # Director may not be ready for queries yet
    # log.info("Waiting for Altus Director API Calls to be available")
    # utils.wait_to_complete(
    #     director.list_environments,
    #     bool_response=True,
    #     whoville_delay=5,
    #     whoville_max_wait=120
    # )
    log.info("------------- Setting Deployment Credential")
    horton.cred = deploy.get_credential(config.profile['namespace'] +
                                        'credential',
                                        create=True,
                                        purge=horton.global_purge)
    init_finish_ts = _dt.utcnow()
    diff_ts = init_finish_ts - init_start_ts
    log.info("Completed Infrastructure Init at [%s] after [%d] seconds",
             init_finish_ts, diff_ts.seconds)
示例#2
0
def get_cloudbreak(s_libc=None, create=True, purge=False, create_wait=0):
    if not s_libc:
        s_libc = create_libcloud_session()

    cbd_name = namespace + 'cloudbreak'
    cbd_nodes = list_nodes(s_libc, {'name': cbd_name})
    cbd = [x for x in cbd_nodes if x.state == 'running']
    if cbd:
        if not purge:
            log.info("Cloudbreak [%s] found, returning instance",
                     cbd[0].name)
            return cbd[0]
        else:
            log.info("Cloudbreak found, Purge is True, destroying...")
            [s_libc.destroy_node(x) for x in cbd]
            cbd = None
    if not cbd:
        log.info("Cloudbreak instance [%s] not found", cbd_name)
        if not create:
            log.info("Cloudbreak not found, Create is False, returning None")
            return None
        else:
            log.info("Cloudbreak is None, Create is True - deploying new "
                     "Cloudbreak [%s]", cbd_name)
            if create_wait:
                log.warning("About to create a Cloudbreak Instance! waiting "
                            "[%s] seconds for abort", create_wait)
                sleep(create_wait)
            cbd = create_cloudbreak(s_libc, cbd_name)
            log.info("Waiting for Cloudbreak Deployment to Complete")
            utils.wait_to_complete(
                utils.is_endpoint_up,
                'https://' + cbd.public_ips[0],
                whoville_delay=30,
                whoville_max_wait=600
            )
            return cbd
示例#3
0
def init_cbreak_infra(create=True, create_wait=0):
    init_start_ts = _dt.utcnow()
    log.info("------------- Getting Environment at [%s]", init_start_ts)
    horton.cbd = infra.get_cloudbreak(purge=horton.global_purge,
                                      create_wait=create_wait,
                                      create=create)
    if not horton.cbd:
        if create:
            # Create has failed, throw error
            raise ValueError(
                "Cloudbreak Create requested but failed, exiting...")
        else:
            return None
    else:
        log.info("Found existing Cloudbreak in Namespace, connecting...")
    log.info("------------- Connecting to Environment")
    if horton.cbd.public_ips:
        public_ip = horton.cbd.public_ips[0]
    else:
        public_ip = horton.cbd.name + config.profile['platform']['domain']
    cbd_url = 'https://' + public_ip + '/cb/api'
    cad_url = 'https://' + public_ip + ':7189'
    log.info("Setting Cloudbreak endpoint to %s", cbd_url)
    utils.set_endpoint(cbd_url)
    log.info("Setting Altus Director endpoint to %s", cad_url)
    utils.set_endpoint(cad_url)
    log.info("------------- Authenticating to Cloudbreak")
    cbd_auth_success = security.service_login(
        service='cloudbreak',
        username=config.profile['email'],
        password=security.get_secret('ADMINPASSWORD'),
        bool_response=False)
    if not cbd_auth_success:
        raise ConnectionError("Couldn't login to Cloudbreak")
    else:
        log.info('Logged into Cloudbreak at [%s]', cbd_url)
    log.info("------------- Authenticating to Altus Director")
    cad_auth_success = security.service_login(
        service='director',
        username=config.profile['username'],
        password=security.get_secret('ADMINPASSWORD'),
        bool_response=False)
    if not cad_auth_success:
        raise ConnectionError("Couldn't login to Director")
    else:
        log.info('Logged into Director at [%s]', cad_url)
    # Cloudbreak may have just booted and not be ready for queries yet
    log.info("Waiting for Cloudbreak API Calls to be available")
    utils.wait_to_complete(deploy.list_blueprints,
                           bool_response=True,
                           whoville_delay=5,
                           whoville_max_wait=120)
    # Director may not be ready for queries yet
    log.info("Waiting for Altus Director API Calls to be available")
    utils.wait_to_complete(director.list_environments,
                           bool_response=True,
                           whoville_delay=5,
                           whoville_max_wait=120)
    # Validating Cloudbreak version
    if not deploy.check_cloudbreak_version():
        raise ValueError(
            "Cloudbreak server is older than configured minimum version of %s",
            str(config.cb_ver))
    # Creating Environment Credentials
    log.info("------------- Setting Deployment Credential")
    log.info("Ensuring Credential for Cloudbreak")
    horton.cbcred = deploy.get_credential(config.profile['namespace'] +
                                          'credential',
                                          create=True,
                                          purge=horton.global_purge)
    if ((config.profile['platform']['provider'] == 'EC2')
            or (config.profile['platform']['provider'] == 'GCE')):
        log.info("Ensuring Environment Credential for Director")
        horton.cadcred = director.get_environment()
    init_finish_ts = _dt.utcnow()
    diff_ts = init_finish_ts - init_start_ts
    log.info("Completed Infrastructure Init at [%s] after [%d] seconds",
             init_finish_ts, diff_ts.seconds)