Repository: deis/deis

Issue:
[CLI] scale operation accepts app parameter but does not (fully) respect this
KeyboardInterrupt
[nathan@omega deis-dev]$ deis-dev scale web=2 --app=devvy1
Scaling containers... but first, coffee!
done in 41s

=== devvy2 Containers

[nathan@omega deis-dev]$ git remote -v
deis    git@deis-controller.local:devvy2.git (fetch)
deis    git@deis-controller.local:devvy2.git (push)



Discussion:

Resolving patch:
diff --git a/client/deis.py b/client/deis.py
--- a/client/deis.py
+++ b/client/deis.py
@@ -784,6 +784,8 @@ def config(self, args):
 
         Use `deis help [command]` to learn more
         """
+        sys.argv[1] = 'config:list'
+        args = docopt(self.config_list.__doc__)
         return self.config_list(args)
 
     def config_list(self, args):
@@ -886,17 +888,20 @@ def containers(self, args):
 
         Use `deis help [command]` to learn more
         """
+        sys.argv[1] = 'containers:list'
+        args = docopt(self.containers_list.__doc__)
         return self.containers_list(args)
 
-    def containers_list(self, args):
+    def containers_list(self, args, app=None):
         """
         List containers servicing an application
 
         Usage: deis containers:list [--app=<app>]
         """
-        app = args.get('--app')
         if not app:
-            app = self._session.get_app()
+            app = args.get('--app')
+            if not app:
+                app = self._session.get_app()
         response = self._dispatch('get',
                                   "/api/apps/{}/containers".format(app))
         if response.status_code != requests.codes.ok:  # @UndefinedVariable
@@ -947,7 +952,7 @@ def containers_scale(self, args):
             progress.join()
         if response.status_code == requests.codes.ok:  # @UndefinedVariable
             print('done in {}s\n'.format(int(time.time() - before)))
-            self.containers_list({})
+            self.containers_list({}, app)
         else:
             raise ResponseError(response)
 
@@ -1273,53 +1278,20 @@ def keys_add(self, args):
         Usage: deis keys:add [<key>]
         """
 
-        Key = namedtuple('Key', 'path name type str comment')
-
-        def parse_key(path):
-            """Parse an SSH public key path into a Key namedtuple."""
-            name = path.split(os.path.sep)[-1]
-            with open(path) as f:
-                data = f.read()
-                match = re.match(r'^(ssh-...) ([^ ]+) ?(.*)', data)
-                if not match:
-                    print("Could not parse SSH public key {0}".format(name))
-                    return
-                key_type, key_str, key_comment = match.groups()
-                return Key(path, name, key_type, key_str, key_comment)
-
         path = args.get('<key>')
         if not path:
-            # find public keys and prompt the user to pick one
-            ssh_dir = os.path.expanduser('~/.ssh')
-            pubkey_paths = glob.glob(os.path.join(ssh_dir, '*.pub'))
-            if not pubkey_paths:
-                print('No SSH public keys found')
-                return
-            pubkeys_list = [parse_key(k) for k in pubkey_paths]
-            print('Found the following SSH public keys:')
-            for i, key_ in enumerate(pubkeys_list):
-                print("{}) {} {}".format(i + 1, key_.name, key_.comment))
-            inp = raw_input('Which would you like to use with Deis? ')
-            try:
-                selected_key = pubkeys_list[int(inp) - 1]
-            except:
-                print('Aborting')
-                return
+            selected_key = self._ask_pubkey_interactively()
         else:
             # check the specified key format
-            selected_key = parse_key(path)
+            selected_key = self._parse_key(path)
             if not selected_key:
                 return
         # Upload the key to Deis
-        if selected_key.comment:
-            key_id = selected_key.comment
-        else:
-            key_id = selected_key.name.replace('.pub', '')
         body = {
-            'id': key_id,
+            'id': selected_key.id,
             'public': "{} {}".format(selected_key.type, selected_key.str)
         }
-        sys.stdout.write("Uploading {} to Deis...".format(key_id))
+        sys.stdout.write("Uploading {} to Deis...".format(selected_key.id))
         sys.stdout.flush()
         response = self._dispatch('post', '/api/keys', json.dumps(body))
         if response.status_code == requests.codes.created:  # @UndefinedVariable
@@ -1327,6 +1299,48 @@ def parse_key(path):
         else:
             raise ResponseError(response)
 
+    def _parse_key(self, path):
+        """Parse an SSH public key path into a Key namedtuple."""
+        Key = namedtuple('Key', 'path name type str comment id')
+
+        name = path.split(os.path.sep)[-1]
+        with open(path) as f:
+            data = f.read()
+            match = re.match(r'^(ssh-...) ([^ ]+) ?(.*)', data)
+            if not match:
+                print("Could not parse SSH public key {0}".format(name))
+                return
+            key_type, key_str, key_comment = match.groups()
+            if key_comment:
+                key_id = key_comment
+            else:
+                key_id = name.replace('.pub', '')
+            return Key(path, name, key_type, key_str, key_comment, key_id)
+
+    def _ask_pubkey_interactively(self):
+        # find public keys and prompt the user to pick one
+        ssh_dir = os.path.expanduser('~/.ssh')
+        pubkey_paths = glob.glob(os.path.join(ssh_dir, '*.pub'))
+        if not pubkey_paths:
+            print('No SSH public keys found')
+            return
+        pubkeys_list = [self._parse_key(k) for k in pubkey_paths]
+        print('Found the following SSH public keys:')
+        for i, key_ in enumerate(pubkeys_list):
+            print("{}) {} {}".format(i + 1, key_.name, key_.comment))
+        print("0) Enter path to pubfile (or use keys:add <key_path>) ")
+        inp = raw_input('Which would you like to use with Deis? ')
+        try:
+            if int(inp) != 0:
+                selected_key = pubkeys_list[int(inp) - 1]
+            else:
+                selected_key_path = raw_input('Enter the path to the pubkey file: ')
+                selected_key = self._parse_key(os.path.expanduser(selected_key_path))
+        except:
+            print('Aborting')
+            return
+        return selected_key
+
     def keys_list(self, args):
         """
         List SSH keys for the logged in user
@@ -1728,6 +1742,8 @@ def perms(self, args):
         Use `deis help perms:[command]` to learn more
         """
         # perms:transfer        transfer ownership of an app or formation
+        sys.argv[1] = 'perms:list'
+        args = docopt(self.perms_list.__doc__)
         return self.perms_list(args)
 
     def perms_list(self, args):


Test patch: