Exemplo n.º 1
0
    def _create_server(self):
        path_to_json_file = os.path.dirname(os.path.realpath(__file__)) + "/joyent"
        machine_name = input_choice("Machine name", fmode=True)
        api = input_choice("API Server", ["us-east-1", "us-west-1", "us-sw-1", "eu-ams-1", "us-east-2", "us-east-3"],
                           fmode=False)

        package_list = self._load_list(path_to_json_file + "/{}.package.json".format(api))
        package = input_choice("Package", options=package_list, fmode=True)

        image_list, image_id = self._load_list(path_to_json_file + "/{}.images.json".format(api),
                                               fields=["name", "version"], return_id=True)
        image = input_choice("Image", options=image_list, fmode=True)
        if image in image_list:
            image_ref = "alias=" + image
            image = image_id[image_list.index(image)]
        else:
            image_ref = ""

        network_list, network_id = self._load_list(path_to_json_file + "/{}.networks.json".format(api), return_id=True)
        networks_ref,  networks = [], []
        new_input = input_choice("Network", options=network_list, fmode=False)
        while not new_input == "d":
            if new_input in network_list:
                networks_ref.append(new_input)
                networks.append(network_id[network_list.index(new_input)])

            new_input = input_choice("Network ('d' for done)", options=network_list, fmode=True)
            if new_input == "d":
                break

        networks = ",".join(networks)
        networks_ref = "alias=" + ",".join(networks_ref)
        print "You want to provision the following:"
        print "{0:15}: {1:30}".format("DC", TColors.warning(api))
        print "{0:15}: {1:30}".format("Machine Name", TColors.warning(machine_name))
        print "{0:15}: {1:30}".format("Package", TColors.warning(package))
        print "{0:15}: {1:30} {2:30}".format("Image", TColors.warning(image), image_ref)
        print "{0:15}: {1:30} {2:30}".format("Networks", TColors.warning(networks), networks_ref)
        answer = input_choice("Are you (yes/no)", ["yes", "no"], fmode=False)
        if answer == "yes":
            self.joyent_runner(machine_name, api, "present", package=package, image=image, networks=networks)
        else:
            print "bye..."