def do_app_worker(self, args, global_args): """Create a new worker.""" if global_args.raw: out = utils.RawOutputFormatter() else: out = utils.ResourceOutputFormatter() App = utils._get_document("App") app = App({'name': args.appname}) env.appname = app.name env.service = args.service try: app.fetch(username=global_args.username, password=global_args.password) except (BackendDoesNotExist, HttpBackendError) as e: out.error(json.loads(e.args[1])) sys.exit(1) Worker = utils._get_document("Worker") worker = Worker({'name': args.appname}) worker.region = app.region if args.instances: worker.instances = args.instances # app.worker = worker self._update_resource(args, global_args, worker)
def do_app(self, args, global_args): """Create a new app.""" App = utils._get_document("App") app = App({'name': args.appname}) env.appname = app.name app.instances = args.instances if args.cname: Cname = utils._get_document('CnameRecord') for c in args.cname: cname = Cname({'record': c}) app.cnames.add(cname) if args.location: app.repository.location = args.location app.repository.variant = "git" app.repository.name = args.appname else: sys.stderr.write("You have to specify a location or an existing repository") sys.exit(1) if args.region: app.region = args.region if args.variant: app.variant = args.variant self._create_resource(args, global_args, app)
def do_app_worker(self, args, global_args): """Update the configuration of a worker.""" if global_args.raw: out = utils.RawOutputFormatter() else: out = utils.ResourceOutputFormatter() env.service = args.service env.appname = args.appname Worker = utils._get_document("Worker") worker = Worker({'name': args.appname}) try: worker.fetch(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if args.add_var: Variable = utils._get_document('EnvironmentVariable') for e in args.add_var: item = e.split("=") variable = Variable({'name': item[0], 'value': item[1]}) worker.envvars.add(variable) if args.del_var: new_collection = [] for e in args.del_var: for doc in worker.envvars.collection_set: if e != doc.name: new_collection.append(doc) worker.envvars.collection_set = new_collection if args.instances: worker.instances = args.instances try: worker.save(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if global_args.raw: out.info(Serializer.dump(worker)) else: out.info("--> %s %s updated!" % (args.service.capitalize(), args.appname)) out.info("--> New %s configuration:\n" % args.service) output = ShowAction() output.do_show(args, global_args)
def do_app_postgres(self, args, global_args): """Create a new postgresql database.""" if global_args.raw: out = utils.RawOutputFormatter() else: out = utils.ResourceOutputFormatter() App = utils._get_document("App") app = App({'name': args.appname}) env.appname = app.name env.service = args.service try: app.fetch(username=global_args.username, password=global_args.password) except (BackendDoesNotExist, HttpBackendError) as e: out.error(json.loads(e.args[1])) sys.exit(1) Postgres = utils._get_document(args.service.capitalize()) postgres = Postgres({'name': args.appname}) # app.postgres = postgres self._update_resource(args, global_args, postgres)
def _delete_resource(self, args, global_args): """Delete a resource.""" self._output_formatter(global_args) env.appname = args.appname env.service = args.service App = utils._get_document('App') app = App({'name': args.appname}) try: app.fetch(username=env.username, password=env.password) except HttpBackendError as e: self.out.error(json.loads(e.args[1])) sys.exit(1) if not args.service: document = app prompt = 'Do you really want to delete app %s?' % args.appname else: if not getattr(app, args.service): self.out.info("App %s has no %s." % (args.appname, args.service)) sys.exit(1) document = getattr(app, args.service) prompt = 'Do you really want to delete the %s of app %s?' % ( args.service, args.appname) resp = confirm(prompt=prompt, resp=False) if not resp: if not global_args.raw: self.out.info("Delete aborted.") sys.exit(1) try: document.delete(username=env.username, password=env.password) except HttpBackendError as e: self.out.error(json.loads(e.args[1])) sys.exit(1) if not global_args.raw: self.out.info("%s %s is deleted!" % ( args.service.capitalize() if args.service else 'App', args.appname))
def do_app_repository(self, args, global_args): """Update the configuration of a repository.""" if global_args.raw: out = utils.RawOutputFormatter() else: out = utils.ResourceOutputFormatter() context = {} env.service = args.service env.appname = args.appname Repository = utils._get_document("Repository") repository = Repository({'name': args.appname}, context=context) try: repository.fetch(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if args.location: repository.location = args.location if args.ssh_key: with open(args.ssh_key, 'r') as f: repository.ssh_key = base64.b64encode(f.read()) try: repository.save(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if global_args.raw: out.info(Serializer.dump(repository)) else: out.info("--> %s %s updated!" % (args.service.capitalize(), repository.name)) out.info("--> New %s configuration:\n" % args.service) output = ShowAction() output.do_show(args, global_args)
def _show_usage(self, args, global_args): """Show the details of a resource.""" self._output_formatter(global_args) App = utils._get_document('App') app = App({'name': args.appname}) try: app.fetch(username=env.username, password=env.password) except HttpBackendError as e: self.out.error(json.loads(e.args[1])) sys.exit(1) if args.service == 'app': document = app else: document = getattr(app, args.service) if document: self.out.info(document.to_dict()) else: self.out.info("%s %s does not exist" % (args.service.capitalize(), args.appname))
def do_app(self, args, global_args): """Update the configuration of an app.""" if global_args.raw: out = utils.RawOutputFormatter() else: out = utils.ResourceOutputFormatter() env.appname = args.appname App = utils._get_document("App") app = App({'name': args.appname}) try: app.fetch(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if args.instances: app.instances = args.instances if args.add_cname: Cname = utils._get_document('CnameRecord') for c in args.add_cname: cname = Cname({'record': c}) app.cnames.add(cname) if args.del_cname: for c in args.del_cname: app.cnames.delete({'record': c}) if args.repo_commit: app.repo_commit = args.repo_commit if args.repository: app.repository.name = args.repository if args.add_var: Variable = utils._get_document('EnvironmentVariable') for e in args.add_var: item = e.split("=") variable = Variable({'name': item[0], 'value': item[1]}) app.envvars.add(variable) if args.del_var: new_collection = [] for e in args.del_var: for doc in app.envvars.collection_set: if e != doc.name: new_collection.append(doc) app.envvars.collection_set = new_collection try: app.save(username=global_args.username, password=global_args.password) except HttpBackendError as e: out.error(json.loads(e.args[1])) sys.exit(1) if global_args.raw: out.info(Serializer.dump(app)) else: out.info("--> App %s updated!" % (args.appname)) out.info("--> New app configuration:\n") output = ShowAction() output.do_show(args, global_args)