def cli(env):
    """Edit configuration."""

    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 = 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")
def cli ( env ) : 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.' ) 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" )
Edit configuration.