def sp(service_platform): if request.method == 'GET': sp = serviceplatform.ServicePlatform(service_platform,"host","type","username","password","project_name","vim_account","service_token","monitoring_urls") return sp.getServicePlatform() if request.method == 'DELETE': sp = serviceplatform.ServicePlatform(service_platform,"host","type","username","password","project_name","vim_account","service_token","monitoring_urls") return sp.deleteServicePlatform() if request.method == 'PATCH': LOG.debug(request.is_json) content = request.get_json() LOG.debug(content) old_sp = serviceplatform.ServicePlatform(service_platform,"host","type","username","password","project_name","vim_account","service_token","monitoring_urls") old_sp_response = old_sp.getServicePlatform() old_sp_content = json.loads(old_sp_response[0]) try: host = content['host'] except: host = old_sp_content['host'] try: username = content['username'] except: username = old_sp_content['username'] try: password = content['password'] except: password = old_sp_content['password'] try: monitoring_urls = content['monitoring_urls'] except: monitoring_urls = old_sp_content['monitoring_urls'] sp = serviceplatform.ServicePlatform(service_platform,host,old_sp_content['type'],username,password,old_sp_content['project_name'],old_sp_content['vim_account'],old_sp_content['service_token'],monitoring_urls) return sp.patchServicePlatform()
def register_sp(): #sp = serviceplatform.ServicePlatform("name","host","type","service_token") print(request.is_json) content = request.get_json() print(content) sp = serviceplatform.ServicePlatform(content['name'], content['host'], content['type'], content['username'], content['password'], content['project_name'], content['service_token']) return sp.registerServicePlatform()
def sps(): if request.method == 'GET': sp = serviceplatform.ServicePlatform("name","host","type","username","password","project_name","vim_account","service_token","monitoring_urls") return sp.getServicePlatforms() if request.method == 'POST': LOG.debug(request.is_json) vim_account = None content = request.get_json() is_url = validators.url(content['host']) if is_url == True: print ("The host is valid") if is_url != True: print ("the host is invalid") msg = "{\"error\": \"The host is invalid, please check\"}" return msg try: vim_account = content['vim_account'] except: vim_account = "vim_account" LOG.debug(content) try: mon_urls = 'http://son-vnv-monitor-manager:8000/api/v2/services' LOG.debug("mon_url exists") try: pr = content['project_name'] LOG.debug("project name exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],content['project_name'],vim_account,"service_token",mon_urls) return sp.registerServicePlatform() except: sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],"project_name",vim_account,"service_token",mon_urls) return sp.registerServicePlatform() except: LOG.debug("mon_url does not exists") try: pr = content['project_name'] LOG.debug("project name exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],content['project_name'],vim_account,"service_token",mon_urls) return sp.registerServicePlatform() except: LOG.debug("project name does not exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],"project_name",vim_account,"service_token",mon_urls) return sp.registerServicePlatform() if request.method == 'OPTIONS': return "Options", 200 if request.method == 'DELETE': return "delete", 200 if request.method == 'PATCH': LOG.debug(request.is_json) content = request.get_json() LOG.debug(content) try: mon_urls = content['monitoring_urls'] LOG.debug("mon_url exists") try: pr = content['project_name'] LOG.debug("project name exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],content['project_name'],vim_account,"service_token","http://son-vnv-monitor-manager:8000/api/v2/services") return sp.patchServicePlatform() except: sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],"project_name",vim_account,"service_token","http://son-vnv-monitor-manager:8000/api/v2/services") return sp.patchServicePlatform() except: LOG.debug("mon_url does not exists") try: pr = content['project_name'] LOG.debug("project name exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],content['project_name'],vim_account,"service_token","http://son-vnv-monitor-manager:8000/api/v2/services") return sp.patchServicePlatform() except: LOG.debug("project name does not exists") sp = serviceplatform.ServicePlatform(content['name'],content['host'],content['type'],content['username'],content['password'],"project_name",vim_account,"service_token","http://son-vnv-monitor-manager:8000/api/v2/services") return sp.patchServicePlatform()
def countSPs(): sp = serviceplatform.ServicePlatform("name","host","type","username","password","project_name","vim_account","service_token","monitoring_urls") return sp.countServicePlatforms()
def get_sps(): sp = serviceplatform.ServicePlatform("name", "host", "type", "username", "password", "project_name", "service_token") return sp.getServicePlatforms()