Implement --cloud arg to switch between clouds
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 3 Jun 2013 09:58:34 +0000 (12:58 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Mon, 3 Jun 2013 10:02:44 +0000 (13:02 +0300)
Refs: #3913

Config file can (optionaly) contain:

[remotes]
 example = https://www.example.org/astakos/identity/v2.0/
 old_version = https://www.example.org/astakos/identity/v1.0/
 ...

Now, user can explicitely request for a remote cloud authentication URI:

kamaki --cloud=<remote>

Conflicts:

Changelog

kamaki/cli/__init__.py
kamaki/cli/argument.py
kamaki/cli/commands/image.py
kamaki/clients/astakos/__init__.py

index d53427d..939891f 100644 (file)
@@ -201,15 +201,30 @@ def _init_session(arguments):
     _include = arguments['include'].value
     global _verbose
     _verbose = arguments['verbose'].value
+    _cnf = arguments['config']
     global _colors
-    _colors = arguments['config'].get('global', 'colors')
+    _colors = _cnf.get('global', 'colors')
     if not (stdout.isatty() and _colors == 'on'):
         from kamaki.cli.utils import remove_colors
         remove_colors()
     _silent = arguments['silent'].value
     _setup_logging(_silent, _debug, _verbose, _include)
-    global_url = arguments['config'].get('global', 'url')
-    global_token = arguments['config'].get('global', 'token')
+    picked_cloud = arguments['cloud'].value
+    if picked_cloud:
+        global_url = _cnf.get('remotes', picked_cloud)
+        if not global_url:
+            raise CLIError(
+                'No remote cloud "%s" in kamaki configuration' % picked_cloud,
+                importance=3, details=[
+                    'To check if this remote cloud alias is declared:',
+                    '  /config get remotes.%s' % picked_cloud,
+                    'To set a remote authentication URI aliased as "%s"' % (
+                        picked_cloud),
+                    '  /config set remotes.%s <URI>' % picked_cloud
+                ])
+    else:
+        global_url = _cnf.get('global', 'auth_url')
+    global_token = _cnf.get('global', 'token')
     from kamaki.clients.astakos import AstakosClient as AuthCachedClient
     return AuthCachedClient(global_url, global_token)
 
index 4fd5eb3..d13864d 100644 (file)
@@ -398,31 +398,20 @@ class ProgressBarArgument(FlagArgument):
 
 _arguments = dict(
     config=_config_arg,
+    cloud=ValueArgument('Chose a remote cloud to connect to', ('--cloud')),
     help=Argument(0, 'Show help message', ('-h', '--help')),
     debug=FlagArgument('Include debug output', ('-d', '--debug')),
     include=FlagArgument(
-        'Include raw connection data in the output',
-        ('-i', '--include')),
+        'Include raw connection data in the output', ('-i', '--include')),
     silent=FlagArgument('Do not output anything', ('-s', '--silent')),
     verbose=FlagArgument('More info at response', ('-v', '--verbose')),
     version=VersionArgument('Print current version', ('-V', '--version')),
     options=CmdLineConfigArgument(
-        _config_arg,
-        'Override a config value',
-        ('-o', '--options'))
+        _config_arg, 'Override a config value', ('-o', '--options'))
 )
-"""Initial command line interface arguments"""
-
-
-"""
-Mechanism:
-    init_parser
-    parse_known_args
-    manage top-level user arguments input
-    find user-requested command
-    add command-specific arguments to dict
-    update_arguments
-"""
+
+
+#  Initial command line interface arguments
 
 
 class ArgumentParseManager(object):
index 5cb44c0..5d6b28a 100644 (file)
@@ -81,9 +81,9 @@ class _init_image(_command_init):
             self.config.get('plankton', 'type'),
             self.config.get('plankton', 'version'))
         base_url = plankton_endpoints['publicURL']
-        base_url = self.config.get('image', 'url')\
-            or self.config.get('compute', 'url')\
-            or self.config.get('global', 'url')
+        #base_url = self.config.get('image', 'url')\
+        #    or self.config.get('compute', 'url')\
+        #    or self.config.get('global', 'url')
         self.client = ImageClient(base_url=base_url, token=token)
         self._set_log_params()
         self._update_max_threads()
@@ -303,8 +303,9 @@ class image_register(_init_image, _optional_json):
 
     def _get_uuid(self):
         atoken = self.client.token
-        user = AstakosClient(self.config.get('user', 'url'), atoken)
-        return user.term('uuid')
+        #user = AstakosClient(self.config.get('user', 'url'), atoken)
+        #return user.term('uuid')
+        self.auth_base.term('uuid', atoken)
 
     def _get_pithos_client(self, container):
         if self['no_metafile_upload']:
index a9b631c..c1599de 100644 (file)
@@ -53,7 +53,7 @@ class AstakosClient(Client):
         :returns: (dict) authentication information
         """
         self.token = token or self.token
-        self._cache[self.token] = self.get('/tokens').json
+        self._cache[self.token] = self.post('/tokens').json
         return self._cache[self.token]
 
     def get_services(self, token=None):