def add(self, raw=False, populate=False, default=False, test=False, flavor=None): if self._collection == None or self._template == None: raise Exception("Add operation is not available in this container") template_json = json.load( open(os.path.join(Config()._get_templates_path(), self._template))) updated = edit_text(json.dumps(template_json, indent=4)) entity_data = json.loads(updated, object_pairs_hook=OrderedDict) res = self._collection._new(entity_data) parameters = {} if populate: parameters["populate"] = "true" if default: parameters["default"] = "true" if test: parameters["test"] = "true" if flavor != None: parameters["flavor"] = flavor res.create(parameters=parameters) res.show(as_json=raw)
def _add(self, argv): options = self._config.options if options.filename: with open(options.filename, 'r') as f: item = json.load(f, object_pairs_hook=OrderedDict) elif options.json: item = json.loads(options.json, object_pairs_hook=OrderedDict) else: template_json = json.load( open( os.path.join(Config()._get_templates_path(), self._template))) self._complete_template(argv, template_json) updated = edit_text(json.dumps(template_json, indent=4)) item = json.loads(updated, object_pairs_hook=OrderedDict) res = self.get_collection(argv)._new(item) parameters = {} if options.populate: parameters["populate"] = "true" if options.default: parameters["default"] = "true" if options.test: parameters["test"] = "true" if options.flavor != None: parameters["flavor"] = options.flavor res.create(parameters=parameters) res.show(as_json=options.raw)
def _add(self, argv): options = globals.options if options.filename: with open(options.filename, 'r') as f: item = json.load(f) elif options.json: item = json.loads(options.json) else: template_json = json.load( open( os.path.join(Config()._get_templates_path(), self._template))) # template = "# To abort the request; just exit your editor without saving this file.\n\n" + template self._complete_template(argv, template_json) updated = edit_text(json.dumps(template_json, indent=4)) # updated = re.sub(r'#.*$', "", updated) item = json.loads(updated) res = self.get_collection(argv)._new(item) parameters = {} if options.populate: parameters["populate"] = "true" if options.default: parameters["default"] = "true" if options.test: parameters["test"] = "true" if options.flavor != None: parameters["flavor"] = options.flavor res.create(parameters=parameters) res.show(as_json=options.raw)
def __init__(self): self._actions = {} self._subcontrollers = {} self._completions = {} self._docs = {} self._register("__available_actions", self._available_actions) self._default_action = lambda x : self._error("No default action defined", -1) self._config = Config()
def _publish(self, argv): app = self._ctrl._get_entity(argv) if not app.published_as is None: raise PythonApiException(self._type_name + " has already been published") template_json = json.load(open(os.path.join(Config()._get_templates_path(), self._template))) template_json[self._label] = app.uuid pub_app = self.store()._new(template_json) self.store()._create(pub_app)
def _vnc(self, argv): if len(argv) != 3: raise MissingException("This action takes 3 arguments") host = self._get_entity(argv) vnc_params = host.instance().get().vnc # Get VNC viewer call string config = Config() viewer_call_template = config.get_vnc_viewer_call(self._config.options.profile_name) if viewer_call_template is None or viewer_call_template == "": raise ControllerException("VNC viewer is not configured") # Call viewer hostname = vnc_params.hostname port = vnc_params.port if hostname != None and port != None: call = viewer_call_template.replace("%h", hostname).replace("%p", port) subprocess.call(call, shell = True) else: raise ControllerException("Could not retrieve VNC server host and/or port")
def _load_comoditrc_conf(options): """ """ profile_name = None if options.profile: profile_name = options.profile config = Config() try: org = config._get_value(profile_name, 'default_organization') except: org = '' if options.organization: org = options.organization return { 'api': config.get_api(profile_name), 'username': config.get_username(profile_name), 'password': config.get_password(profile_name), 'organization': org }
def _purchase(self, argv): if len(argv) < 2: raise ArgumentException( "A published entity UUID and an organization name must be provided" ) org = self._client.organizations().get(argv[1]) pub = self.get_collection(argv).get(argv[0], parameters={"org_name": argv[1]}) template_json = json.load( open(os.path.join(Config()._get_templates_path(), self._template))) template_json["published"] = pub.uuid template_json["name"] = pub.name updated = edit_text(json.dumps(template_json, indent=4)) pur_app = self.get_purchased_collection(org)._new(json.loads(updated)) pur_app.create()
# coding: utf-8 from __future__ import print_function import sys, argparse from comodit_client.console.core import ComodITConsole from comodit_client.config import Config, ConfigException if __name__ == '__main__': # Load configuration try: config = Config() except ConfigException as e: print("Configuration error:") print(e.msg) exit(-1) parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description="This is the ComodIT console.") parser.add_argument('-P', "--profile", dest="profile", help="A profile from comoditrc file", default=None) parser.add_argument('-a', "--api", dest="api", help="URL of the API", default=None)
# coding: utf-8 import sys, argparse from comodit_client.console.core import ComodITConsole from comodit_client.config import Config, ConfigException if __name__ == '__main__': # Load configuration try: config = Config() except ConfigException as e: print "Configuration error:" print e.msg exit(-1) parser = argparse.ArgumentParser(formatter_class = argparse.RawDescriptionHelpFormatter, description = "This is the ComodIT console.") parser.add_argument('-P', "--profile", dest = "profile", help = "A profile from comoditrc file", default = None) parser.add_argument('-a', "--api", dest = "api", help = "URL of the API", default = None) parser.add_argument('-u', "--user", dest = "username", help = "username on comodit server", default = None) parser.add_argument('-p', "--pass", dest = "password", help = "password on comodit server", default = None) parser.add_argument('-i', "--insecure", dest = "insecure", help = "Tells the client to ignore self-signed certificates", action = "store_true", default = False) parser.add_argument('-f', "--file", dest = "file", help = "Tells the client to execute the content of given file", default = None) parser.add_argument('-d', "--debug", dest = "debug", help = "Tells the client to work in debug mode, causing every exception to be considered as an error", action = "store_true", default = False) options = parser.parse_known_args(args = sys.argv)[0] # Use profile data to configure connection. if not options.api is None: