Skip to content

Commit

Permalink
Merge pull request #139 from huit/feature/integrate-scope
Browse files Browse the repository at this point in the history
Rewritten scope functionality should work with all the various corner cases
  • Loading branch information
hakamadare committed Nov 12, 2013
2 parents b810f0c + f3ace52 commit 62a6d82
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 326 deletions.
5 changes: 4 additions & 1 deletion bin/nepho
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from cement.core import handler
from cement.core import handler, hook
from nepho import cli
import sys

Expand All @@ -16,6 +16,9 @@ def main():
handler.register(cli.parameter.NephoParameterController)
handler.register(cli.scope.NephoScopeController)

hook.register('post_argument_parsing', cli.hooks.set_scope)
hook.register('post_setup', cli.hooks.process_config)

try:
app.setup()
app.run()
Expand Down
3 changes: 2 additions & 1 deletion nepho/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import base
import cloudlet
import blueprint
import hooks
import stack
import config
import parameter
import scope

__all__ = ["base", "config", "parameter", "cloudlet", "blueprint", "stack", "scope"]
__all__ = ["base", "config", "hooks", "parameter", "cloudlet", "blueprint", "stack", "scope"]
44 changes: 3 additions & 41 deletions nepho/cli/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import re

from cement.core import backend, foundation, controller
from cement.utils.misc import init_defaults

import nepho.core.config

defaults = backend.defaults('nepho', 'base')
defaults = init_defaults('nepho', 'internal')
defaults['nepho']['archive_dir'] = path.join("~", ".nepho", "archive")
defaults['nepho']['tmp_dir'] = path.join("~", ".nepho", "tmp")
defaults['nepho']['cache_dir'] = path.join("~", ".nepho", "cache")
Expand All @@ -16,7 +17,7 @@
defaults['nepho']['local_config'] = path.join("~", ".nepho", "local", "config.yaml")
defaults['nepho']['cloudlet_registry_url'] = "http://cloudlets.github.io/registry.yaml"
defaults['nepho']['cloudlet_clone_proto'] = "https"
defaults['base']['processed_config'] = False
defaults['internal']['processed_config'] = False


class NephoBaseController(controller.CementBaseController):
Expand All @@ -28,45 +29,6 @@ class Meta:
def _setup(self, app):
super(NephoBaseController, self)._setup(app)

# Running this section twice (once for base and once for the subclassed
# controller) causes errors. There is no doubt a better way to avoid
# that behavior than this silly cheat...
if self.config.get('base', 'processed_config') is not True:
self.config.set('base', 'processed_config', True)

# Multiple cloudlet dirs in a string need to be split into a list and
# excess whitespace removed
cloudlet_dirs = self.config.get('nepho', 'cloudlet_dirs').split(',')
cloudlet_dirs = map(lambda x: x.strip(), cloudlet_dirs)
self.config.set('nepho', 'cloudlet_dirs', cloudlet_dirs)

# Do some pre-processing on all configuration items
for key in self.config.keys('nepho'):
value = self.config.get('nepho', key)

if isinstance(value, list):
# Expand user where necessary
value = map(lambda x: path.expanduser(x), value)
self.config.set('nepho', key, value)

# If items are directories, make sure they exist
if re.search('_dirs$', key):
for one_dir in value:
if not path.exists(one_dir):
makedirs(one_dir)
else:
# Expand user where necessary
value = path.expanduser(value)
self.config.set('nepho', key, value)

# If item is a directory, make sure it exists
if re.search('_dir$', key) and not path.exists(value):
makedirs(value)

self.my_shared_obj = dict()

self.nepho_config = nepho.core.config.ConfigManager(self.config)

@controller.expose(hide=True)
def default(self):
if self._meta.label == "base":
Expand Down
50 changes: 15 additions & 35 deletions nepho/cli/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import nepho.core.config
from cement.core import controller
from nepho.cli import base
from nepho.cli import base, scope
from nepho.core import cloudlet


class NephoBlueprintController(base.NephoBaseController):
class Meta:
label = 'blueprint'
stacked_on = None
interface = controller.IController
stacked_on = 'base'
stacked_type = 'nested'
description = 'list and view individual cloudlet deployment blueprints'
usage = "nepho blueprint <action> <cloudlet> [blueprint]"
arguments = [
Expand All @@ -25,20 +27,19 @@ class Meta:

def _setup(self, app):
super(base.NephoBaseController, self)._setup(app)
self.nepho_config = nepho.core.config.ConfigManager(self.config)
self.nepho_config = nepho.core.config.ConfigManager(self.app.config)
self.cloudletManager = cloudlet.CloudletManager(self.nepho_config)

@controller.expose(help='List all blueprints in a cloudlet')
def list(self):

cloudlet_name = self._read_cloudlet()

if cloudlet_name is None:
print "Usage: nepho blueprint list [cloudlet]"
if self.app.cloudlet_name is None:
print "Usage: nepho blueprint list <cloudlet>"
exit(1)
else:
scope.print_scope(self)

try:
cloudlt = self.cloudletManager.find(cloudlet_name)
cloudlt = self.cloudletManager.find(self.app.cloudlet_name)
y = cloudlt.defn
except IOError:
print colored("└──", "yellow"), cloudlt.name, "(", colored("error", "red"), "- missing or malformed cloudlet.yaml )"
Expand All @@ -64,23 +65,21 @@ def list(self):

@controller.expose(help='Describe a blueprint')
def describe(self):

(cloudlet_name, blueprint_name) = self._read_cloudlet_and_blueprint()

print blueprint_name
if cloudlet_name is None or blueprint_name is None:
if self.app.cloudlet_name is None or self.app.blueprint_name is None:
print "Usage: nepho blueprint describe <cloudlet> <blueprint>"
exit(1)
else:
scope.print_scope(self)

try:
cloudlt = self.cloudletManager.find(cloudlet_name)
cloudlt = self.cloudletManager.find(self.app.cloudlet_name)
except IOError:
print colored("└──", "yellow"), cloudlt.name, "(", colored("error", "red"), "- missing or malformed cloudlet.yaml )"
exit(1)
else:
print colored("└──", "yellow"), cloudlt.name, "(", colored("v%s", "blue") % (cloudlt.defn['version']), ")"

bprint = cloudlt.blueprint(blueprint_name)
bprint = cloudlt.blueprint(self.app.blueprint_name)

y = bprint.defn

Expand All @@ -100,22 +99,3 @@ def describe(self):

print "-" * 80
return

def _read_cloudlet(self):
"""Determine the cloudlet name to operate on."""

cloudlet_name = self.nepho_config.get("scope_cloudlet")
if self.pargs.cloudlet is not None:
cloudlet_name = self.pargs.cloudlet

return cloudlet_name

def _read_cloudlet_and_blueprint(self):
"""Determine the cloudlet and blueprint names to operate on."""

cloudlet_name = self._read_cloudlet()
blueprint_name = self.nepho_config.get("scope_blueprint")
if self.pargs.blueprint is not None:
blueprint_name = self.pargs.blueprint

return (cloudlet_name, blueprint_name)
Loading

0 comments on commit 62a6d82

Please sign in to comment.