Example #1
0
def infrastructure_ssh_keys(name, version, known_host):
    """
    Diplays ssh keys or adds it to known_hosts

    :param name:
    :param version:
    :param known_host:
    :return:
    """
    try:
        ssh_keys = service.infrastructure.keys(name, version, known_host)
        if not maccli.quiet:
            if known_host:
                for ssh_key in ssh_keys:
                    show("%s processed" % ssh_key['cloudServer']['ipv4'])

            else:
                for ssh_key in ssh_keys:
                    show(ssh_key['stdout'])

    except KeyboardInterrupt:
       show_error("Aborting")
    except Exception as e:
       show_error(e)
       sys.exit(EXCEPTION_EXIT_CODE)
def infrastructure_ssh_keys(name, version, known_host):
    """
    Diplays ssh keys or adds it to known_hosts

    :param name:
    :param version:
    :param known_host:
    :return:
    """
    try:
        ssh_keys = service.infrastructure.keys(name, version, known_host)
        if not maccli.quiet:
            if known_host:
                for ssh_key in ssh_keys:
                    show("%s processed" % ssh_key['cloudServer']['ipv4'])

            else:
                for ssh_key in ssh_keys:
                    show(ssh_key['stdout'])

    except KeyboardInterrupt:
       show_error("Aborting")
    except Exception as e:
       show_error(e)
       sys.exit(EXCEPTION_EXIT_CODE)
Example #3
0
def no_credentials():
    show("You need to login into Manageacloud.com")
    show()
    show("    mac login")
    show()
    show("If you do not have an account, register at https://manageacloud.com/register")
Example #4
0
def instance_create(cookbook_tag, bootstrap_raw, deployment, location, servername, provider, release_raw, release_version_raw,
                    branch, hardware, lifespan, environments, hd, port, net):

    # allow format release:release_version, ie ubuntu:trusty
    if ":" in release_raw:
        release, release_version = release_raw.split(":", 1)
    else:
        release = release_raw
        release_version = release_version_raw


    # TODO check if cookbook_tag exists
    # TODO validate bootstrap inputs
    try:
        if cookbook_tag is None and bootstrap_raw is None:
            view.view_instance.show_instance_create_help()

        elif location is None:
            locations_json = service.provider.list_locations(provider, release)
            if locations_json is not None:
                show()
                show("--location parameter not set. You must choose the location.")
                show()
                show("Available locations:")
                show()
                if len(locations_json):
                    view.view_location.show_locations(locations_json)
                    view.view_instance.show_create_example_with_parameters(cookbook_tag, bootstrap_raw, deployment,
                                                                           locations_json[0]['id'], servername,
                                                                           provider, release, release_version,
                                                                           branch, hardware)

                else:
                    type = None
                    if release is not None:
                        type = release

                    if type is None and cookbook_tag is not None:
                        type = cookbook_tag

                    show("There is not locations available for '%s' and provider '%s'" % (type, provider))

                view.view_instance.show_instance_help()

        elif deployment == "production" and hardware is None or \
                                        deployment == "testing" and provider is not "default" and hardware is None:
            hardwares = service.provider.list_hardwares(provider, location, release)
            show()
            show("--hardware not found. You must choose the hardware.")
            show()
            show("Available hardware:")
            show()
            view.view_hardware.show_hardwares(hardwares)
            if (len(hardwares) > 0):
                view.view_instance.show_create_example_with_parameters(cookbook_tag, bootstrap_raw, deployment, location, servername,
                                                                       provider, release, release_version, branch, hardwares[0]['id'])
        else:
            """ Execute create instance """

            # load the bootstrap file properly
            if bootstrap_raw is not None:
                if os.path.exists(bootstrap_raw):  # it is a file
                    # this is going to be the PWD to run commands
                    maccli.pwd = os.path.dirname(os.path.realpath(bootstrap_raw))
                    maccli.logger.info("Path %s exists, trying to open file", bootstrap_raw)
                    stream = open(bootstrap_raw, "r")
                    bootstrap = stream.read()
                elif _is_url(bootstrap_raw):  # try url
                    maccli.logger.info("%s looks like an URL, trying to open URL" % bootstrap_raw)
                    f = urllib2.urlopen(bootstrap_raw)
                    bootstrap = f.read()
                else:  # values are bash executable
                    bootstrap = bootstrap_raw
            else:
                bootstrap = bootstrap_raw

            if cookbook_tag == "" and bootstrap == "":
                show_error("Server contains no configuration")
            else:
                instance = service.instance.create_instance(cookbook_tag, bootstrap, deployment, location,
                                                            servername, provider, release, release_version,
                                                            branch, hardware, lifespan, environments, hd, port, net)
                if instance is not None:
                    view.view_instance.show_instance(instance)

                view.view_generic.show("")
                view.view_generic.show("Monitor the progress of all servers:")
                view.view_generic.show("")
                view.view_generic.show("    watch mac instance list")
                view.view_generic.show("")
                view.view_generic.show("Tail server logs:")
                view.view_generic.show("")
                view.view_generic.show("    mac instance log -f %s" % instance['id'])
                view.view_generic.show("")
    except KeyboardInterrupt:
        show_error("Aborting")
    except URLError:
        show_error("Can't open URL %s" % bootstrap_raw)
    except Exception as e:
        show_error(e)
        sys.exit(EXCEPTION_EXIT_CODE)
def no_credentials():
    show("You need to login into Manageacloud.com")
    show()
    show("    mac login")
    show()
    show("If you do not have an account, register at https://manageacloud.com/register")
def instance_create(cookbook_tag, bootstrap_raw, deployment, location, servername, provider, release_raw, release_version_raw,
                    branch, hardware, lifespan, environments, hd, port, net):

    # allow format release:release_version, ie ubuntu:trusty
    if ":" in release_raw:
        release, release_version = release_raw.split(":", 1)
    else:
        release = release_raw
        release_version = release_version_raw


    # TODO check if cookbook_tag exists
    # TODO validate bootstrap inputs
    try:
        if cookbook_tag is None and bootstrap_raw is None:
            view.view_instance.show_instance_create_help()

        elif location is None:
            locations_json = service.provider.list_locations(provider, release)
            if locations_json is not None:
                show()
                show("--location parameter not set. You must choose the location.")
                show()
                show("Available locations:")
                show()
                if len(locations_json):
                    view.view_location.show_locations(locations_json)
                    view.view_instance.show_create_example_with_parameters(cookbook_tag, bootstrap_raw, deployment,
                                                                           locations_json[0]['id'], servername,
                                                                           provider, release, release_version,
                                                                           branch, hardware)

                else:
                    type = None
                    if release is not None:
                        type = release

                    if type is None and cookbook_tag is not None:
                        type = cookbook_tag

                    show("There is not locations available for '%s' and provider '%s'" % (type, provider))

                view.view_instance.show_instance_help()

        elif deployment == "production" and hardware is None or \
                                        deployment == "testing" and provider is not "default" and hardware is None:
            hardwares = service.provider.list_hardwares(provider, location, release)
            show()
            show("--hardware not found. You must choose the hardware.")
            show()
            show("Available hardware:")
            show()
            view.view_hardware.show_hardwares(hardwares)
            if (len(hardwares) > 0):
                view.view_instance.show_create_example_with_parameters(cookbook_tag, bootstrap_raw, deployment, location, servername,
                                                                       provider, release, release_version, branch, hardwares[0]['id'])
        else:
            """ Execute create instance """

            # load the bootstrap file properly
            if bootstrap_raw is not None:
                if os.path.exists(bootstrap_raw):  # it is a file
                    # this is going to be the PWD to run commands
                    maccli.pwd = os.path.dirname(os.path.realpath(bootstrap_raw))
                    maccli.logger.info("Path %s exists, trying to open file", bootstrap_raw)
                    stream = open(bootstrap_raw, "r")
                    bootstrap = stream.read()
                elif _is_url(bootstrap_raw):  # try url
                    maccli.logger.info("%s looks like an URL, trying to open URL" % bootstrap_raw)
                    f = urllib2.urlopen(bootstrap_raw)
                    bootstrap = f.read()
                else:  # values are bash executable
                    bootstrap = bootstrap_raw
            else:
                bootstrap = bootstrap_raw

            if cookbook_tag == "" and bootstrap == "":
                show_error("Server contains no configuration")
            else:
                instance = service.instance.create_instance(cookbook_tag, bootstrap, deployment, location,
                                                            servername, provider, release, release_version,
                                                            branch, hardware, lifespan, environments, hd, port, net)
                if instance is not None:
                    view.view_instance.show_instance(instance)

                view.view_generic.show("")
                view.view_generic.show("Monitor the progress of all servers:")
                view.view_generic.show("")
                view.view_generic.show("    watch mac instance list")
                view.view_generic.show("")
                view.view_generic.show("Tail server logs:")
                view.view_generic.show("")
                view.view_generic.show("    mac instance log -f %s" % instance['id'])
                view.view_generic.show("")
    except KeyboardInterrupt:
        show_error("Aborting")
    except URLError:
        show_error("Can't open URL %s" % bootstrap_raw)
    except Exception as e:
        show_error(e)
        sys.exit(EXCEPTION_EXIT_CODE)
Example #7
0
def instance_create(cookbook_tag, deployment, location, servername, provider, release, branch, hardware, lifespan,
                    environments, hd, port):
    try:
        if cookbook_tag is None:
            view.view_instance.show_instance_create_help()

        elif location is None:
            locations_json = service.provider.list_locations(cookbook_tag, provider, release)
            if locations_json is not None:
                show()
                show("--location parameter not set. You must choose the location.")
                show()
                show("Available locations:")
                show()
                if len(locations_json):
                    view.view_location.show_locations(locations_json)
                    view.view_instance.show_create_example_with_parameters(cookbook_tag, deployment,
                                                                           locations_json[0]['id'], servername,
                                                                           provider, release, branch, hardware)

                else:
                    show("There is not locations available for configuration %s and provider %s" % (
                        cookbook_tag, provider))

                view.view_instance.show_instance_help()
        elif deployment == "production" and hardware is None or \
                                        deployment == "testing" and provider is not "manageacloud" and hardware is None:
            hardwares = service.provider.list_hardwares(provider, location, cookbook_tag, release)
            show()
            show("--hardware not found. You must choose the hardware.")
            show()
            show("Available hardware:")
            show()
            view.view_hardware.show_hardwares(hardwares)
            if (len(hardwares) > 0):
                view.view_instance.show_create_example_with_parameters(cookbook_tag, deployment, location, servername,
                                                                       provider, release, branch, hardwares[0]['id'])
        else:
            """ Execute create instance """
            instance = service.instance.create_instance(cookbook_tag, deployment, location, servername, provider,
                                                        release,
                                                        branch, hardware, lifespan, environments, hd, port)
            if instance is not None:
                view.view_instance.show_instance(instance)

            view.view_generic.show("")
            view.view_generic.show("To monitor the creation progress:")
            view.view_generic.show("")
            view.view_generic.show("watch mac instance list")
            view.view_generic.show("")
    except KeyboardInterrupt:
        show_error("Aborting")
    except Exception as e:
        show_error(e)
        sys.exit(EXCEPTION_EXIT_CODE)