Skip to content

Commit

Permalink
Merge pull request #176 from ryran/custom-prefix-support
Browse files Browse the repository at this point in the history
Custom appname nick prefix support
  • Loading branch information
ryran authored Jul 18, 2017
2 parents 07ea9bf + 9688e52 commit 2124610
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
33 changes: 22 additions & 11 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
## In addition, ravshello supports a non-standard "!include" extension, e.g.:
## KEY: !include /PATH/FILE
## Such inclusions will be handled recursively so use with care.

##
## WARNING about quoting strings:
## YAML doesn't require quoting simple strings but certain characters (e.g., ":"
## and "#") must be escaped if they're present so it's safer to just use quotes.
## (Ref: http://yaml.org/spec/1.2/spec.html#id2788859)

######
## Optionally specify login credentials for Ravello account to avoid prompting
## Optionally specify login credentials for Ravello account to avoid prompting.

#ravelloUser: [email protected]
#ravelloPass: my cr@zy passw0rd, no quotes required

#ravelloPass: 'my cr@zy passw0rd'

######
## If present, *nickname* will be used as the ravshello 'user', overriding the
Expand All @@ -19,6 +22,18 @@

#nickname: myNickName

######
## If *appnameNickPrefix* is omitted, it defaults to "k:" (originally for
## "kerberos"). This is used in concert with *nickname* to build a prefix for
## all application names, i.e., a new app created by ravshello will be named:
## <appnameNickPrefix><nickname>__<APPLICATION_NAME>
## Furthermore, in ravshello you will only be able to see apps whose names
## begin with:
## <appnameNickPrefix><nickname>__
## Though of course in ravshello, it will hide the prefix so you'll only see:
## <APPLICATION_NAME>

#appnameNickPrefix: 'k:'

######
## Optionally specify a default cost bucket (by name or numeric ID) in which to
Expand All @@ -27,14 +42,14 @@

#appCostBucket: myCostBucketNameOrId


######
## Optionally declare MULTIPLE sets of Ravello credentials and map them to
## profile names. The names are arbitrary and can be selected by use of
## the -u or --user cmdline option. Notes:
## - *ravelloUser* is required.
## - *ravelloPass* is not required. (Will be prompted for pass.)
## - *nickname* is not required.
## - *appnameNickPrefix* is not required.
## - *appCostBucket* is not required.
## - *defaultProfile* is not required.

Expand All @@ -43,16 +58,17 @@
# ravelloUser: [email protected]
# ravelloPass: xxxxx
# appCostBucket: QA
# appnameNickPrefix: 'QA:'
# ana:
# ravelloUser: [email protected]
# ravelloPass: xxxxx
# nickname: ana
# appCostBucket: DEV
# appnameNickPrefix: 'DEV:'
# wow@example:
# ravelloUser: [email protected]
# defaultProfile: ana


######
## Optionally specify text to be displayed when login fails. Declare as simple
## string or as a multiline literal block ("unableToLoginMsg: |") or multiline
Expand All @@ -62,14 +78,12 @@

#unableToLoginMsg: Ohmg contact bob at the helpdesk!


######
## If present, *sshKeyFile* is integrated into the ssh command reported to the
## user by ravshello's query_app_status command.

#sshKeyFile: /expected/path/to/ssh/priv/key


######
## If present, *eventsOfInterest* overrides rav-notify's default list of
## events to watch for. Remove existing lines and/or add new ones.
Expand All @@ -84,7 +98,6 @@ eventsOfInterest:
- VM_SNAPSHOTTING_AFTER_STOP
- VM_FINISHED_SNAPSHOTTING


######
## If present, each cmdline in *preRunCommands* will be executed prior to
## any cmds present on argv and prior to entering the interactive shell but
Expand All @@ -96,15 +109,13 @@ eventsOfInterest:
# - ls
# - (ADD AS MANY COMMANDS AS YOU WANT)


######
## Setting this boolean true changes the default behavior of prompting for
## missing Ravello credentials -- instead, ravshello will exit with login error.
## This can also be set true by use of --never-prompt-creds cmdline option.

#neverPromptCreds: false


######
## Optionally include additional config file(s). These must be the same format
## as above. Keys from included config files will overwrite keys from earlier
Expand Down
5 changes: 4 additions & 1 deletion modules/auth_ravello.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def login():
cfgPass = cfg.cfgFile.get('ravelloPass', None)
profiles = cfg.cfgFile.get('userProfiles', {})
user = passwd = userFrom = profile = None
# Set default cb
# Set default cb & app prefix
cfg.appCostBucket = cfg.cfgFile.get('appCostBucket', None)
cfg.appnameNickPrefix = cfg.cfgFile.get('appnameNickPrefix', None)
# If necessary, get Ravello *username* from configfile or prompt
try:
profile = profiles[rOpt.ravelloUser]
Expand All @@ -89,11 +90,13 @@ def login():
if userFrom == 'profile':
try:
cfg.appCostBucket = profile['appCostBucket']
cfg.appnameNickPrefix = profile['appnameNickPrefix']
except:
pass
elif userFrom == 'defaultProfile':
try:
cfg.appCostBucket = profiles[profiles['defaultProfile']]['appCostBucket']
cfg.appnameNickPrefix = profiles[profiles['defaultProfile']]['appnameNickPrefix']
except:
pass
# If necessary, get Ravello *password* from configfile or prompt
Expand Down
11 changes: 7 additions & 4 deletions modules/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
prog = 'ravshello'

# Version info
__version__ = '1.28.0'
__date__ = '2017/07/15'
__version__ = '1.29.0'
__date__ = '2017/07/17'
version = "{} v{} last mod {}".format(prog, __version__, __date__)

# Defaults
Expand All @@ -31,10 +31,13 @@
# This will hold the options namespace generated by argparse
opts = None

# This will hold the local username
# This will hold the "local" username (nickname)
user = None

# This will hold the default app cost bucket
# This holds the string that builds app name prefix w/nickname (see config.yaml)
appnameNickPrefix = 'k:'

# This will hold the default app cost bucket (see config.yaml)
appCostBucket = None

# This will hold the RavelloClient object
Expand Down
2 changes: 1 addition & 1 deletion modules/user_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def main():
rOpt = cfg.opts
user = cfg.user
if user:
appnamePrefix = 'k:{}__'.format(user)
appnamePrefix = '{}{}__'.format(cfg.appnameNickPrefix, user)
else:
appnamePrefix = ''
rClient = cfg.rClient
Expand Down
3 changes: 2 additions & 1 deletion ravshello.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def main():
"(nickname is normally determined from the system user name "
"and is used to hide applications that don't start with "
"'k:NICK__'; any apps created will also have that tag prefixed "
"to their name)"))
"to their name; see also 'nickname' and 'appnameNickPrefix' "
"config directives in /usr/share/{}/config.yaml)".format(cfg.prog)))
grpU_0.add_argument(
'--prompt-nick', dest='promptNickname', action='store_true',
help="Prompt for nickname to use for app-filtering")
Expand Down

0 comments on commit 2124610

Please sign in to comment.