def get(self, app_id): if app_id == "showall": OpenAPI("db", "App", "getAllApps", args=(), env=getenv(self)).webCall(self) else: OpenAPI("db", "App", "getApp", args=(app_id, ), env=getenv(self)).webCall(self)
def get(self, server_id): if server_id == "showall": OpenAPI("db", "Server", "getAllServers", args=(), env=getenv(self)).webCall(self) else: OpenAPI("db", "Server", "getServer", args=(server_id, ), env=getenv(self)).webCall(self)
def get(self, script_id): if script_id == "showall": OpenAPI("db", "Script", "getAllScripts", args=(), env=getenv(self)).webCall(self) else: OpenAPI("db", "Script", "getScript", args=(script_id, ), env=getenv(self)).webCall(self)
def get(self, host_id): if host_id == "showall": OpenAPI("db", "Host", "getAllHosts", args=(), env=getenv(self)).webCall(self) else: OpenAPI("db", "Host", "getHost", args=(host_id, ), env=getenv(self)).webCall(self)
def post(self, action): if action == "add": OpenAPI("db", "Script", "saveScript", args=(self.get_argument("name"), "owner", self.get_argument("content")), env=getenv(self)).webCall(self) if action == "runScript": OpenAPI("openapi", None, "runScript", args=(self.get_argument("script_id"), self.get_argument("host_id")), env=getenv(self)).webCall(self)
def put(self, host_id): OpenAPI("db", "Host", "updateHost", args=(host_id, self.get_argument("name"), self.get_argument("ssh_port"), self.get_argument("type")), env=getenv(self)).webCall(self)
def get(uri_application_id): api = OpenAPI() applications = api.pem.APS.getApplications( aps_application_id=uri_application_id) if not applications: raise Exception('Application with URI id "%s" is not found' % uri_application_id) return Application(applications[0]['application_id'], None)
def post(self, action): OpenAPI("db", "Host", "saveHost", args=(self.get_argument("name"), self.get_argument("ip"), self.get_argument("ssh_port"), self.get_argument("type")), env=getenv(self)).webCall(self)
def put(self, server_id): OpenAPI("db", "Server", "updateServer", args=(server_id, self.get_argument("name"), self.get_argument("host"), self.get_argument("ssh_port"), self.get_argument("type"), self.get_argument("port"), self.get_argument("webapp_home")), env=getenv(self)).webCall(self)
def import_app(URL): from urlparse import urlparse app_URI = URL if not urlparse(app_URI)[0]: app_URI = __getApplicationPackage(app_URI) api = OpenAPI() res = api.pem.APS.importPackage(package_url=app_URI) return Application(res['application_id'], res['package_version'])
def put(self, job_id): OpenAPI("db", "Job", "updateJob", args=( job_id, self.get_argument("data"), ), env=getenv(self)).webCall(self)
def post(self, action): OpenAPI("db", "Server", "saveServer", args=(self.get_argument("name"), self.get_argument("host"), self.get_argument("ssh_port"), self.get_argument("type"), self.get_argument("port"), self.get_argument("webapp_home")), env=getenv(self)).webCall(self)
def restartServer(data, self): env = utils.Namespace() setattr(env, "machine", "") setattr(env, "ipaddr", self.request.remote_ip) setattr(env, "username", "") setattr(env, "program", "webctl") OpenAPI("openapi", None, "restartServer", args=(data.get("brand"), data.get("res")), env=getenv(self)).socketCall(self, 600)
def getInstance(self, application_instance_id): if not self.id: raise Exception('Application is not imported') api = OpenAPI() res = api.pem.APS.getApplicationInstance( application_instance_id=application_instance_id) return ApplicationInstanceExt(res['application_instance_id'], res['application_id'], res['url'], res['rt_id'], res['status'], res['package_version'], res['application_resource_id'])
def remove(self, open_api_req='App'): api = OpenAPI() api.beginRequest(request_id_cand=open_api_req, prefix_gen=None) api.pem.APS.removeApplication(application_id=self.id) api.commit() self.id = None self.version = None pass
def getInstances(self): if not self.id: raise Exception('Application is not imported') api = OpenAPI() res = api.pem.APS.getApplicationInstances(app_id=self.id) rv = [] for app in res: rv.append( ApplicationInstance(app['application_instance_id'], app['application_resource_id'])) return rv
def post(self, action): OpenAPI("db", "App", "saveApp", args=(self.get_argument("brand").upper(), self.get_argument("app").upper(), { "MASTER_SVN": self.get_argument("master_svn"), "CONFIG_SVN": self.get_argument("config_svn"), "CONTEXT": self.get_argument("context"), "SERVERS": self.get_argument("servers"), "CDN_TYPE": self.get_argument("cdn_type"), "DOMAINID": self.get_argument("domainId"), "URL": self.get_argument("url") }), env=getenv(self)).webCall(self)
def put(self, app_id): OpenAPI("db", "App", "updateApp", args=( self.get_argument("id"), { "MASTER_SVN": self.get_argument("master_svn"), "CONFIG_SVN": self.get_argument("config_svn"), "CONTEXT": self.get_argument("context"), "SERVERS": self.get_argument("servers"), "CDN_TYPE": self.get_argument("cdn_type"), "DOMAINID": self.get_argument("domainId"), "URL": self.get_argument("url") }, ), env=getenv(self)).webCall(self)
def createInstance(self, endpoint, address='localhost', open_api_req='App_Instance'): if not self.id: raise Exception('Application is not imported') api = OpenAPI() api.beginRequest(request_id_cand=open_api_req, prefix_gen=None) api.pem.APS.provideApplicationInstance(subscription_id=0, app_id=self.id, package_version=self.version, url_path=endpoint, rt_id=0) api.commit()
def resetUsageAPI(resclass_name, con): from openapi import OpenAPI api = OpenAPI() cur = con.cursor() cur.execute(""" SELECT sr.sub_id, sr.rt_id, rt.restype_name, rc.friendly_name FROM resource_types rt JOIN resource_classes rc ON rt.class_id = rc.class_id JOIN subs_resources sr ON rt.rt_id = sr.rt_id WHERE rc.name = '%s'; """ % resclass_name) res_types = set() for sub_id, rt_id, restype_name, friendly_name in cur.fetchall(): uLogging.debug("reset resource usage for subscription id %s resource type id %s", sub_id, rt_id) api.pem.resetResourceUsage(subscription_id=sub_id, resource_type_ids=(rt_id,)) res_types.add(ResType(rt_id, restype_name, friendly_name)) resetUsage(resclass_name, con) return res_types
def deployApp(data, self): env = utils.Namespace() setattr(env, "machine", "") setattr(env, "ipaddr", self.request.remote_ip) setattr(env, "username", "") setattr(env, "program", "webctl") master_svn = data.get("master_svn") config_svn = data.get("config_svn") logging.debug("master_svn:" + str(master_svn)) logging.debug("config_svn:" + str(config_svn)) if not master_svn: master_svn = "HEAD" if not config_svn: config_svn = "HEAD" OpenAPI("openapi", None, "deployApp", args=(data.get("brand").upper(), data.get("app").upper(), master_svn, config_svn), env=env).socketCall(self)
def upgradeInstance(self, application_instance_id, open_api_req='App_Instance_Upgrade'): if not self.id: raise Exception('Application is not imported') inst = self.getInstance(application_instance_id) ver = inst.get_version() if ver == self.version: return api = OpenAPI() api.beginRequest(request_id_cand=open_api_req, prefix_gen=None) api.pem.APS.upgradeApplicationInstance( application_instance_id=application_instance_id, package_version=self.version) api.commit() pass
def restartServer(args): # restartServer(args.brand, args.res) OpenAPI("openapi", None, "restartServer", args=(args.brand, args.res), env=e).call()
def put(self, script_id): OpenAPI("db", "Script", "updateScript", args=(script_id, self.get_argument("content")), env=getenv(self)).webCall(self)
def get(self, brand, app): OpenAPI("openapi", None, "getSVNLog", args=(brand.upper(), app.upper()), env=getenv(self)).webCall(self)
def stopServer(args): # stopServer(args.brand, args.res) OpenAPI("openapi", None, "stopServer", args=(args.brand, args.res), env=e).call()
def get(self, brand, server): OpenAPI("openapi", None, "keysMem", args=(brand, server), env=getenv(self)).webCall(self)
def rollbackApp(args): OpenAPI("openapi", None, "rollbackApp", args=(args.brand.upper(), args.module.upper()),env=e).call()
def post(self, action): OpenAPI("db", "Job", "saveJob", args=(self.get_argument("data"), ), env=getenv(self)).webCall(self)
def get(self, job_id): OpenAPI("db", "Job", "getJob", args=(job_id, ), env=getenv(self)).webCall(self)