Exemplo n.º 1
0
    def joyent_runner(self, machine_name, api, state, package=None, networks=None, image=None):
        print ".....\nPlease wait doing API request to {}".format(api)

        module_arg = {"name": machine_name, "state": state, "data_center": api}
        if state == "present":
            module_arg.update({"networks": networks, "flavor": package, "image": image, "fire_forget": "false"})
        inventory_manager = inventory.Inventory("127.0.0.1,")
        # construct the ansible runner and execute on all hosts
        results = ansible.runner.Runner(
            pattern='*',
            forks=1,
            inventory=inventory_manager,
            transport="local",
            module_name='joyent',
            module_path=self._get_config("ansible_lib"),
            module_args=module_arg
        ).run()
        for (hostname, result) in results['contacted'].items():
            if 'failed' in result:
                print "Failed \n%s" % result['msg']
            elif 'failed' not in result:
                if result.get("msg"):
                    msg = TColors.red(result.get("msg"))
                    if result.get("changed"):
                        if result.get("ips"):
                            msg += " IPs=" + ", ".join(result.get("ips"))
                        print msg
                    else:
                        print result.get("msg")
                    print result.get("timer")
                else:
                    print "Output format not correct dumping all:\n%s", result
Exemplo n.º 2
0
 def _start_server(self):
     machine_name = self.arguments.get("<servername>")
     api = self._get_config("api")
     print "Are you sure you want to start '" + TColors.red(machine_name) + "' in '" + TColors.red(api) + "'?"
     user_input = raw_input("If you are sure please type the server name again: ")
     if user_input != machine_name:
         print "Server names don't match. bye!!"
         exit(1)
     self.joyent_runner(machine_name, api, "running")
Exemplo n.º 3
0
 def _network_format(self, network):
     if network["public"] == True:
         network["public"] = TColors.green("Public")
     else:
         network["public"] = TColors.red("Private")
     if "description" not in network:
         network["description"] = ""
     self.results.append([network["public"],
                          network["name"],
                          network["id"],
                          network["description"]])
Exemplo n.º 4
0
    def _delete_server(self):
        machine_name = self.arguments.get("<servername>")
        api = self._get_config("api")
        print "Are you sure you want to delete '" + TColors.red(machine_name) + "' in '" + TColors.red(api) + "'?"
        user_input = raw_input("If you are sure please type the server name again: ")
        if user_input != machine_name:
            print "Server names don't match. bye!!"
            exit(1)

        self.joyent_runner(machine_name, api, "absent")
        print "if you run on mac os OS X Mavericks, Mountain Lion, and Lion, you can reset your dns cache with:"
        print "\tsudo killall -HUP mDNSResponder"
        print "if you run mac os OS X Yosemite you can reset your dns cache with:"
        print "\tsudo discoveryutil mdnsflushcache"
Exemplo n.º 5
0
 def _machine_format(self, m):
     if m.state == "running":
         m.state = TColors.green(m.state)
     elif m.state == "stopped":
         m.state = TColors.red(m.state)
     else:
         m.state = TColors.yellow(m.state)
     m.created = format_last_run(m.created, color=False)
     m.dataset = str(m.dataset).split(":")
     self.results.append([m.name,
                          m.state,
                          "",
                          ", ".join(m.ips),
                          m.type[0].upper(),
                          ":".join(m.dataset[-2:]),
                          m.created])