def find_app_location(app_name, namespace=""): app_namespace = "" app_type = "" resource = "" app_list = [] output = OC().get_deployments_all_namespace() if output.find(app_name) != -1: for line in output.split("\n"): if line.find(app_name) != -1: app_namespace = line.split()[0] app_type = "deployment" resource = line.split()[1] app = {} app["namespace"] = app_namespace app["resource_type"] = app_type app["resource"] = resource app_list.append(app) if not app_list: output = OC().get_deploymentconfigs_all_namespace() if output.find(app_name) != -1: for line in output.split("\n"): if line.find(app_name) != -1: app_namespace = line.split()[0] app_type = "deploymentconfig" resource = line.split()[1] app = {} app["namespace"] = app_namespace app["resource_type"] = app_type app["resource"] = resource app_list.append(app) if not app_list: raise Exception("app: %s is not existed" % app_name) # do not choose if namespace: for app in app_list: if app["namespace"] == namespace and app["resource"] == app_name: break return app_namespace, app_type, resource app_namespace = app["namespace"] app_type = app["resource_type"] resource = app["resource"] if query_mode: # show app i = 0 print "\n" print "*******************************************************************" print " Applications:" for app in app_list: print " %d) namespace: %s %s: %s" % (i, app["namespace"], app["resource_type"], app["resource"]) i = i + 1 print "*******************************************************************\n" sys.stdin = open('/dev/tty') try: x = raw_input("input prefered application (default:0): ") if not x: x = 0 except Exception: x = 0 x = int(x) app_namespace = app_list[x]["namespace"] app_type = app_list[x]["resource_type"] resource = app_list[x]["resource"] print "preferred application is %s/%s" % (app_namespace, resource) os.environ["NAMESPACE"] = app_namespace os.environ["RESOURCE"] = resource os.environ["RESOURCE_TYPE"] = app_type return app_namespace, app_type, resource
def get_executor_status(namespace, desired_status): output = OC().get_configmap(namespace, "alameda-executor-config") if output.find(desired_status) == -1: raise Exception("executor must be %s" % desired_status)