94
votes

I have two accounts on Openshift platform. How can I setup my computer so that I can manage both of them with rhc? I cannot find any relevant option in the command line arguments.

7

7 Answers

181
votes

rhc command line tools come with the global option "-l, --rhlogin LOGIN". You have two options:

1) Use -l flag with every command to specify the login name OR

rhc app create <appname> <cartridge> [-l <login1/login2>]

2) Run "rhc setup -l LOGIN" between the sessions. Once done managing apps from one account you can end the session for it by running "rhc account logout".

rhc setup -l <login1> # First account's login
rhc app create <appname> <cartridge>
rhc logout
rhc setup -l <login2> # Second account's login
rhc app create <appname> <cartridge>
rhc logout

When you can "rhc setup" command, the username information gets stored in .openshift/express.conf file; hence the need to run it again when you want to switch the account.

HTH

12
votes

The command line also supports --conf - where you pass a file. You can always alias the command via a shell script.

7
votes

Quite old question, but I use yet another solution which seems to be more comfortable (at least for me) - the environment variable OPENSHIFT_CONFIG.

The OPENSHIFT_CONFIG environment variable can be used to override the OpenShift configuration name (by default "express"). When set the operations performed with rhc refers to ~/.openshift/${OPENSHIFT_CONFIG}.conf (instead of ~/.openshift/express.conf).

To switch to the another OpenShift account the following could be used (Bash):

export OPENSHIFT_CONFIG=thenewone 
rhc apps    //apps on the new account

...
unset OPENSHIFT_CONFIG
rhc apps    //apps on the default account

Verified with rhc 1.37.1, but should work with any version released after May 2013.

2
votes

When you run the rhc setup command for the first time, the ~/.openshift/express.conf file is created, containing the settings for your initial server configuration. When you add another server, or run the rhc setup command again with the --server option, the ~/.openshift/servers.yml file is created, containing the settings for each server. You can edit this file to make any changes to the server configuration, and this takes precedence over the initial ~/.openshift/express.conf file.

    rhc server use server.name.example.co
    rhc server use Server_Nickname

original from access.redhat.com/documentation

1
votes

(In windows) run 2 rhc console commands and answer like <I did>:

>rhc setup -l [email protected]

use the server for OpenShift Online: openshift.redhat.com.

Enter the server hostname: |openshift.redhat.com|<Press Enter>

Password: *********<Press Enter>

Generate a token now? (yes|no) y<Press Enter>

Generating an authorization token for this client ... lasts about 1 month

Saving configuration to C:\Users\UserName.openshift\express.conf ... done Your private SSH key file should be set as readable only to yourself. Please

run 'chmod 600 C:\Users\UserName.ssh\id_rsa'

Your client tools are now configured.

>chmod 600 C:\Users\UserName.ssh\id_rsa

Than you can use console commands for a long time with generated token for your openshift login: [email protected]

1
votes

You can configure multiple accounts using "server add" command and then you can provide the server nickname in all subsequent commands using --server option.

For example,

rhc server add -l <first_account> --nickname srv1 <first-server>
rhc server add -l <second_account> --nickname srv2 <second-server>

You may add options like -p, --use-authorised-tokens to suppress the prompts for password and token-generation. Also --insecured if required

rhc server use srv1
rhc server use srv2

Commands above perform some sort of initialisation. Once two steps above are done you are ready to use your multiple accounts.

Now in your rhc commands you need to specify which server should be used. For example,

rhc app-show -n <domain> <app> --server srv1

Command above will show details of app in srv1 For srv2 you can run

rhc app-show -n <domain> <app> --server srv2
1
votes

Use rhc setup -l <login>. Here login is your registered openshift's email address.