Example #1
0
def cli(env):
    """Setup the ~/.softlayer file with username and apikey.

    Set the username to 'apikey' for cloud.ibm.com accounts.
    """

    username, secret, endpoint_url, timeout = get_user_input(env)
    new_client = SoftLayer.Client(username=username,
                                  api_key=secret,
                                  endpoint_url=endpoint_url,
                                  timeout=timeout)
    api_key = get_api_key(new_client, username, secret)

    path = '~/.softlayer'
    if env.config_file:
        path = env.config_file
    config_path = os.path.expanduser(path)

    env.out(
        env.fmt(
            config.config_table({
                'username': username,
                'api_key': api_key,
                'endpoint_url': endpoint_url,
                'timeout': timeout
            })))

    if not formatting.confirm('Are you sure you want to write settings '
                              'to "%s"?' % config_path,
                              default=True):
        raise exceptions.CLIAbort('Aborted.')

    # Persist the config file. Read the target config file in before
    # setting the values to avoid clobbering settings
    parsed_config = configparser.RawConfigParser()
    parsed_config.read(config_path)
    try:
        parsed_config.add_section('softlayer')
    except configparser.DuplicateSectionError:
        pass

    parsed_config.set('softlayer', 'username', username)
    parsed_config.set('softlayer', 'api_key', api_key)
    parsed_config.set('softlayer', 'endpoint_url', endpoint_url)
    parsed_config.set('softlayer', 'timeout', timeout)

    config_fd = os.fdopen(
        os.open(config_path, (os.O_WRONLY | os.O_CREAT | os.O_TRUNC), 0o600),
        'w')
    try:
        parsed_config.write(config_fd)
    finally:
        config_fd.close()

    env.fout("Configuration Updated Successfully")
Example #2
0
def cli(env):
    """Edit configuration."""

    username, secret, endpoint_url, timeout = get_user_input(env)

    env.client.transport.transport.endpoint_url = endpoint_url
    api_key = get_api_key(env.client, username, secret)

    path = '~/.softlayer'
    if env.config_file:
        path = env.config_file
    config_path = os.path.expanduser(path)

    env.out(env.fmt(config.config_table({'username': username,
                                         'api_key': api_key,
                                         'endpoint_url': endpoint_url,
                                         'timeout': timeout})))

    if not formatting.confirm('Are you sure you want to write settings '
                              'to "%s"?' % config_path, default=True):
        raise exceptions.CLIAbort('Aborted.')

    # Persist the config file. Read the target config file in before
    # setting the values to avoid clobbering settings
    parsed_config = utils.configparser.RawConfigParser()
    parsed_config.read(config_path)
    try:
        parsed_config.add_section('softlayer')
    except utils.configparser.DuplicateSectionError:
        pass

    parsed_config.set('softlayer', 'username', username)
    parsed_config.set('softlayer', 'api_key', api_key)
    parsed_config.set('softlayer', 'endpoint_url', endpoint_url)
    parsed_config.set('softlayer', 'timeout', timeout)

    config_fd = os.fdopen(os.open(config_path,
                                  (os.O_WRONLY | os.O_CREAT | os.O_TRUNC),
                                  0o600),
                          'w')
    try:
        parsed_config.write(config_fd)
    finally:
        config_fd.close()

    env.fout("Configuration Updated Successfully")
Example #3
0
def cli(env):
    """Show current configuration."""

    settings = config.get_settings_from_client(env.client)
    return config.config_table(settings)
Example #4
0
def cli(env, auth):
    """Setup the ~/.softlayer file with username and apikey.

    [Auth Types]

    ibmid: Requires your cloud.ibm.com username and password, and generates a classic infrastructure API key.

    cloud_key: A 32 character API key. Username will be 'apikey'

    classic_key: A 64 character API key used in the Softlayer/Classic Infrastructure systems.

    sso: For users with @ibm.com email addresses.
    """
    username = None
    api_key = None

    timeout = 0
    defaults = config.get_settings_from_client(env.client)
    endpoint_url = get_endpoint_url(env, defaults.get('endpoint_url',
                                                      'public'))
    # Get ths username and API key
    if auth == 'ibmid':
        username, api_key = ibmid_login(env)

    elif auth == 'cloud_key':
        username = '******'
        secret = env.getpass('Classic Infrastructue API Key',
                             default=defaults['api_key'])
        new_client = SoftLayer.Client(username=username,
                                      api_key=secret,
                                      endpoint_url=endpoint_url,
                                      timeout=timeout)
        api_key = get_api_key(new_client, username, secret)

    elif auth == 'sso':
        username, api_key = sso_login(env)

    else:
        username = env.input('Classic Infrastructue Username',
                             default=defaults['username'])
        secret = env.getpass('Classic Infrastructue API Key',
                             default=defaults['api_key'])
        new_client = SoftLayer.Client(username=username,
                                      api_key=secret,
                                      endpoint_url=endpoint_url,
                                      timeout=timeout)
        api_key = get_api_key(new_client, username, secret)

    # Ask for timeout, convert to float, then to int
    timeout = int(float(env.input('Timeout', default=defaults['timeout']
                                  or 0)))

    path = '~/.softlayer'
    if env.config_file:
        path = env.config_file
    config_path = os.path.expanduser(path)

    env.out(
        env.fmt(
            config.config_table({
                'username': username,
                'api_key': api_key,
                'endpoint_url': endpoint_url,
                'timeout': timeout
            })))

    if not formatting.confirm(
            'Are you sure you want to write settings to "%s"?' % config_path,
            default=True):
        raise exceptions.CLIAbort('Aborted.')

    # Persist the config file. Read the target config file in before
    # setting the values to avoid clobbering settings
    parsed_config = configparser.RawConfigParser()
    parsed_config.read(config_path)
    try:
        parsed_config.add_section('softlayer')
    except configparser.DuplicateSectionError:
        pass

    parsed_config.set('softlayer', 'username', username)
    parsed_config.set('softlayer', 'api_key', api_key)
    parsed_config.set('softlayer', 'endpoint_url', endpoint_url)
    parsed_config.set('softlayer', 'timeout', timeout)

    config_fd = os.fdopen(
        os.open(config_path, (os.O_WRONLY | os.O_CREAT | os.O_TRUNC), 0o600),
        'w')
    try:
        parsed_config.write(config_fd)
    finally:
        config_fd.close()

    env.fout("Configuration Updated Successfully")