Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactored the setup step into an explicit setup command.

  • Loading branch information...
commit c11a1e29b340315297947f7311f20ff27a60d88f 1 parent 649df16
@progrium authored
Showing with 40 additions and 19 deletions.
  1. +1 −1  MANIFEST.in
  2. +26 −8 skypipe/cli.py
  3. +13 −10 skypipe/cloud.py
View
2  MANIFEST.in
@@ -1 +1 @@
-README.md
+include README.md
View
34 skypipe/cli.py
@@ -5,6 +5,7 @@
"""
import sys
import os
+import argparse
from dotcloud.ui.cli import CLI as DotCloudCLI
@@ -25,19 +26,36 @@ def save_satellite_endpoint(endpoint):
"""caches endpoint data in config"""
pass
+def get_parser():
+ parser = argparse.ArgumentParser(prog='skypipe')
+ parser.add_argument('name', metavar='NAME', type=str, nargs='?',
+ help='use a named skypipe', default='')
+ parser.add_argument('--setup', action='store_const',
+ const=True, default=False,
+ help='setup account and satellite')
+ parser.add_argument('--check', action='store_const',
+ const=True, default=False,
+ help='check if satellite is online')
+ return parser
+
def run():
- try:
- skypipe_name = sys.argv[1]
- except IndexError:
- skypipe_name = ''
+ parser = get_parser()
+ args = parser.parse_args()
dotcloud_endpoint = os.environ.get('DOTCLOUD_API_ENDPOINT',
'https://rest.dotcloud.com/v1')
cli = DotCloudCLI(endpoint=dotcloud_endpoint)
- skypipe_endpoint = os.environ.get("SATELLITE", load_satellite_endpoint())
- if not skypipe_endpoint:
- skypipe_endpoint = cloud.discover_satellite(cli)
+ if args.setup:
+ cloud.setup(cli)
+ else:
+ skypipe_endpoint = os.environ.get("SATELLITE", load_satellite_endpoint())
+ skypipe_endpoint = skypipe_endpoint or cloud.discover_satellite(cli, deploy=False)
+ if not skypipe_endpoint:
+ cli.die("Unable to locate satellite. Please run `skypipe --setup`")
save_satellite_endpoint(skypipe_endpoint)
- client.run(skypipe_endpoint, skypipe_name)
+ if args.check:
+ cli.success("Skypipe is ready for action")
+ else:
+ client.run(skypipe_endpoint, args.name)
View
23 skypipe/cloud.py
@@ -63,7 +63,7 @@ def setup_dotcloud_account(cli):
client = RESTClient(endpoint=cli.client.endpoint)
client.authenticator = NullAuth()
urlmap = client.get('/auth/discovery').item
- username = cli.prompt('dotCloud username')
+ username = cli.prompt('dotCloud email')
password = cli.prompt('Password', noecho=True)
credential = {'token_url': urlmap.get('token'),
'key': CLIENT_KEY, 'secret': CLIENT_SECRET}
@@ -78,9 +78,15 @@ def setup_dotcloud_account(cli):
cli.global_config = GlobalConfig() # reload
cli.setup_auth()
cli.get_keys()
- cli.info("Account setup, resuming...")
-def discover_satellite(cli, timeout=10):
+def setup(cli):
+ if not cli.global_config.loaded:
+ setup_dotcloud_account(cli)
+ discover_satellite(cli)
+ cli.success("Skypipe is ready for action")
+
+
+def discover_satellite(cli, deploy=True, timeout=5):
"""Looks to make sure a satellite exists, returns endpoint
First makes sure we have dotcloud account credentials. Then it looks
@@ -91,19 +97,17 @@ def discover_satellite(cli, timeout=10):
return a working endpoint.
"""
if not cli.global_config.loaded:
- cli.info("First time use, please setup dotCloud account")
- setup_dotcloud_account(cli)
+ cli.die("Please setup skypipe by running `skypipe --setup`")
try:
endpoint = lookup_endpoint(cli)
ok = client.check_skypipe_endpoint(endpoint, timeout)
if ok:
- #cli.info("DEBUG: Found satellite") # TODO: remove
return endpoint
else:
- return launch_satellite(cli)
+ return launch_satellite(cli) if deploy else None
except (RESTAPIError, KeyError):
- return launch_satellite(cli)
+ return launch_satellite(cli) if deploy else None
def launch_satellite(cli):
"""Deploys a new satellite app over any existing app"""
@@ -174,13 +178,12 @@ class args: path = satellite_path
finish = wait_for(" Satellite coming online", finish)
endpoint = lookup_endpoint(cli)
- ok = client.check_skypipe_endpoint(endpoint, 60)
+ ok = client.check_skypipe_endpoint(endpoint, 120)
finish.set()
time.sleep(0.1) # sigh, threads
if ok:
- cli.info("Finished, resuming normal use.")
return endpoint
else:
cli.die("Satellite failed to come online")
Please sign in to comment.
Something went wrong with that request. Please try again.