Esempio n. 1
0
 def _connections(self):
     self.environment.prepare_connect()
     hosts = sorted(self.environment.hosts)
     for i, hostname in enumerate(hosts, 1):
         host = self.environment.hosts[hostname]
         if host.ignore:
             output.step(
                 hostname,
                 "Connection ignored ({}/{})".format(
                     i, len(self.environment.hosts)
                 ),
                 bold=False,
                 red=True,
             )
             continue
         output.step(
             hostname,
             "Connecting via {} ({}/{})".format(
                 self.environment.connect_method,
                 i,
                 len(self.environment.hosts),
             ),
         )
         sem = threading.Semaphore(5)
         c = Connector(host, sem)
         c.start()
         yield c
Esempio n. 2
0
 def prepare_connect(self):
     if self.connect_method == 'vagrant':
         output.step("vagrant", "Ensuring machines are up ...")
         cmd('vagrant up')
     elif self.connect_method == 'kitchen':
         output.step("kitchen", "Ensuring machines are up ...")
         for fqdn in self.hosts:
             cmd('kitchen create {}'.format(fqdn))
         if 'BATOU_POST_KITCHEN_CREATE_CMD' in os.environ:
             cmd("kitchen exec -c '{}'".format(
                 os.environ['BATOU_POST_KITCHEN_CREATE_CMD']))
Esempio n. 3
0
 def provision(self):
     if not self.environment.provisioners:
         return
     output.section("Provisioning hosts ...")
     for host in self.environment.hosts.values():
         if host.provisioner:
             output.step(
                 host.name, "Provisioning with `{}` provisioner. {}".format(
                     host.provisioner.name,
                     "(Rebuild)" if host.provisioner.rebuild else ""))
             host.provisioner.provision(host)
Esempio n. 4
0
    def load(self):
        output.section("Preparing")

        output.step("main",
                    "Loading environment `{}`...".format(self.environment))

        self.environment = Environment(self.environment, self.timeout,
                                       self.platform)
        self.environment.deployment = self
        self.environment.load()

        if self.jobs is not None:
            self.jobs = self.jobs
        elif self.environment.jobs is not None:
            self.jobs = int(self.environment.jobs)
        else:
            self.jobs = 1
        output.step("main", "Number of jobs: %s" % self.jobs, debug=True)

        # This is located here to avoid duplicating the verification check
        # when loading the repository on the remote environment object.
        output.step("main", "Verifying repository ...")
        self.environment.repository.verify()

        output.step("main", "Loading secrets ...")
        self.environment.load_secrets()
Esempio n. 5
0
    async def _deploy_component(self, key, info, todolist):
        hostname, component = key
        host = self.environment.hosts[hostname]
        if host.ignore:
            output.step(
                hostname,
                "Skipping component {} ... (Host ignored)".format(component),
                red=True)
        elif info["ignore"]:
            output.step(hostname,
                        "Skipping component {} ... (Component ignored)".format(
                            component),
                        red=True)
        else:
            output.step(hostname,
                        "Scheduling component {} ...".format(component))
            await self.loop.run_in_executor(None, host.deploy_component,
                                            component, self.predict_only)

        # Clear dependency from todolist
        for other_component in todolist.values():
            if key in other_component["dependencies"]:
                other_component["dependencies"].remove(key)

        # Trigger start of unblocked dependencies
        self._launch_components(todolist)
Esempio n. 6
0
    def load(self):
        output.section("Preparing")

        output.step("main",
                    "Loading environment `{}`...".format(self.environment))

        self.environment = Environment(self.environment, self.timeout,
                                       self.platform)
        self.environment.deployment = self
        self.environment.load()

        # This is located here to avoid duplicating the verification check
        # when loading the repository on the remote environment object.
        output.step("main", "Verifying repository ...")
        self.environment.repository.verify()

        output.step("main", "Loading secrets ...")
        self.environment.load_secrets()
Esempio n. 7
0
 def disconnect(self):
     output.step("main", "Disconnecting from nodes ...", debug=True)
     for node in list(self.environment.hosts.values()):
         node.disconnect()