Пример #1
0
def status():
    """Check the status of the environment and every service in it."""
    settings = project.read_settings()
    session = client.acquire_session(settings)
    env = environments.retrieve(session, settings["environmentId"])
    output.write("environment state: " + env["state"])
    codes = []
    noncodes = []
    for service in services.list(session, settings["environmentId"]):
        if service["type"] != "utility":
            if service["type"] == "code":
                codes.append("\t%s (size = %s, build status = %s, deploy status = %s)" % (service["label"], service["size"], service["build_status"], service["deploy_status"]))
            else:
                noncodes.append("\t%s (size = %s, image = %s, status = %s)" % (service["label"], service["size"], service["name"], service["deploy_status"]))
    for item in (codes + noncodes):
        output.write(item)
Пример #2
0
def associate(env_label, service_label, remote):
    """Associates the git repository in the current directory. This means that the service and environment IDs are stored locally, and a git remote is created (default name = "catalyze") so that code can be pushed, built, and deployed."""
    session = client.acquire_session()
    for env in environments.list(session):
        if env["data"]["name"] == env_label:
            settings = {
                    "token": session.token,
                    "user_id": session.user_id,
                    "environmentId": env["environmentId"]
                }
            code_services = [svc for svc in services.list(session, env["environmentId"]) if svc["type"] == "code"]
            selected_service = None
            if len(code_services) == 0:
                output.error("No code service found for \"%s\" environment (%s)" % (env_label, env["environmentId"]))
            elif service_label:
                for svc in code_services:
                    if svc["label"] == service_label:
                        selected_service = svc
                        break
                if selected_service is None:
                    output.error("No code service found with label '%s'. Labels found: %s" % \
                            (service_label, ", ".join([svc["label"] for svc in code_services])))
            elif len(code_services) > 1:
                output.error("Found multiple code services. Must pass one specifically to associate with. Labels found: " + \
                        ", ".join([svc["label"] for svc in code_services]))
            else:
                selected_service = code_services[0]

            if remote in git.remote_list():
                git.remote_remove(remote)
            git.remote_add(remote, selected_service["source"])
            settings["serviceId"] = selected_service["id"]
            project.save_settings(settings)
            output.write("\"%s\" remote added." % (remote,))
            return
    output.error("No environment with label \"%s\" found." % (env_label,))