From 85c9fcafa7dee6ced593c7c8ab4dd7c9702fc989 Mon Sep 17 00:00:00 2001 From: Evgeniy L Date: Thu, 14 May 2015 15:14:53 +0200 Subject: [PATCH] Added assign command and implemented resources and nodes retrival --- config.yml | 1 + solar/solar/cli.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index 400e4590..5ced636f 100644 --- a/config.yml +++ b/config.yml @@ -9,3 +9,4 @@ file-system-db: storage-path: /vagrant/tmp/storage template-dir: /vagrant/templates +resources-files-mask: /vagrant/examples/resources/*.yml diff --git a/solar/solar/cli.py b/solar/solar/cli.py index bc05827a..f5f1ee24 100644 --- a/solar/solar/cli.py +++ b/solar/solar/cli.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + """Solar CLI api On create "golden" resource should be moved to special place @@ -27,6 +28,7 @@ import yaml from solar import extensions from solar import utils from solar.core import data +from solar.core.tags_set_parser import Expression from solar.interfaces.db import get_db # NOTE: these are extensions, they shouldn't be imported here @@ -79,12 +81,17 @@ class Cmd(object): group.add_argument('-t', '--tags', nargs='+', default=['env/test_env']) group.add_argument('-i', '--id', default=utils.generate_uuid()) + # Assign + parser = self.subparser.add_parser('assign') + parser.set_defaults(func=getattr(self, 'assign')) + parser.add_argument('-n', '--nodes') + parser.add_argument('-r', '--resources') + def profile(self, args): if args.create: params = {'tags': args.tags, 'id': args.id} profile_template_path = os.path.join( - utils.read_config()['template-dir'], 'profile.yml' - ) + utils.read_config()['template-dir'], 'profile.yml') data = yaml.load(utils.render_template(profile_template_path, params)) self.db.store('profiles', data) else: @@ -100,6 +107,18 @@ class Cmd(object): def discover(self, args): Discovery({'id': 'discovery'}).discover() + def assign(self, args): + nodes = filter( + lambda n: Expression(args.nodes, n['tags']).evaluate(), + self.db.get_list('nodes')) + + resources = filter( + lambda r: Expression(args.resources, r['tags']).evaluate(), + self._get_resources_list()) + + def _get_resources_list(self): + return utils.load_by_mask(utils.read_config()['resources-files-mask']) + def main(): api = Cmd()