Exemplo n.º 1
0
    def do_clean(self, project_name):
        minion_path = self.parent.config['minions'][project_name]

        # Check if sahara is available
        minion_path = self.parent.config['minions'][project_name]
        try:
            plugins = Vagrant(minion_path).plugin_list()
        except Exception as e:
            raise

        sahara = bool([p for p in plugins if p.name == "sahara"])

        # Check sandbox status
        sandbox_status = 'off'
        if sahara:
            sandbox = SandboxVagrant(minion_path)
            sandbox_status = sandbox.sandbox_status()

        # If sandbox is activated, rollback only
        if sandbox_status == 'on' and not self.force_clean:
            message = "Rollback snapshot, if you will delete snapshot, use "\
                      "--force-clean option"
            puts(colored.blue(message))
            sandbox.sandbox_rollback()
            puts(colored.blue("Done"))

            command = "sudo /etc/init.d/salt-minion restart"
            result = get_output_cmd(command, minion_path)

            puts(colored.blue("Restarted salt-minion"))

            puts(colored.blue("Wait some time for salt-minion to connect"))
            sleep(10)
        # Else destroy and up
        else:
            # Destroy
            VagrantDestroy.parent = self.parent
            VagrantDestroy.run(['destroy', project_name], exit=False)

            # Up
            VagrantUp.parent = self.parent
            VagrantUp.run(['up', project_name], exit=False)
Exemplo n.º 2
0
    def do_clean(self, project_name):
        minion_path = self.parent.config['minions'][project_name]

        # Check if sahara is available
        minion_path = self.parent.config['minions'][project_name]
        try:
            plugins = Vagrant(minion_path).plugin_list()
        except Exception as e:
            raise

        sahara = bool([p for p in plugins if p.name == "sahara"])

        # Check sandbox status
        sandbox_status = 'off'
        if sahara:
            sandbox = SandboxVagrant(minion_path)
            sandbox_status = sandbox.sandbox_status()

        # If sandbox is activated, rollback only
        if sandbox_status == 'on' and not self.force_clean:
            message = "Rollback snapshot, if you will delete snapshot, use "\
                      "--force-clean option"
            puts(colored.blue(message))
            sandbox.sandbox_rollback()
            puts(colored.blue("Done"))

            command = "sudo /etc/init.d/salt-minion restart"
            result = get_output_cmd(command, minion_path)

            puts(colored.blue("Restarted salt-minion"))

            puts(colored.blue("Wait some time for salt-minion to connect"))
            sleep(10)
        # Else destroy and up
        else:
            # Destroy
            VagrantDestroy.parent = self.parent
            VagrantDestroy.run(['destroy', project_name], exit=False)

            # Up
            VagrantUp.parent = self.parent
            VagrantUp.run(['up', project_name], exit=False)
Exemplo n.º 3
0
    def main(self, project_name):
        minion_path = self.parent.config['minions'][project_name]
        self.execute_vagrant_command_on_minion(project_name, 'up')

        # Get back master IP
        puts(colored.blue("Check master ip"))
        command = "/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f 1"
        vm_ip = get_output_cmd(command, minion_path)

        vm_ip = vm_ip.split('.')
        vm_ip[-1] = '1'
        master_ip = ".".join(vm_ip)

        # Check declared master ip
        command = "grep master /etc/salt/minion"
        declared_master_ip = get_output_cmd(command, minion_path)
        declared_master_ip = declared_master_ip.split()[-1]

        change = False

        if declared_master_ip != master_ip:
            puts(
                colored.yellow(
                    "Master ip on minion is invalid, {0} instead of {1}".
                    format(declared_master_ip, master_ip)))

            # Replace master ip
            command = "sudo sed -i 's/{0}/{1}/g' /etc/salt/minion".format(
                declared_master_ip, master_ip)
            result = get_output_cmd(command, minion_path)

            # Reboot minion
            command = "sudo /etc/init.d/salt-minion restart"
            result = get_output_cmd(command, minion_path)

            # Change minion
            command = "sed -i 's/{0}/{1}/g' {2}".format(
                declared_master_ip, master_ip, join(minion_path, 'minion'))
            check_output(command, shell=True)

            # Wait for minion to connect
            sleep(10)

            puts(
                colored.blue(
                    "Master ip has been updated from {0} to {1}".format(
                        declared_master_ip, master_ip)))
            change = True
        else:
            puts(colored.blue("Master is good"))

        # Check if sahara is available
        minion_path = self.parent.config['minions'][project_name]
        try:
            plugins = Vagrant(minion_path).plugin_list()
        except Exception as e:
            raise

        sahara = bool([p for p in plugins if p.name == "sahara"])

        if not sahara:
            message = "Sandbox support is not available, please install sahara"\
                      " plugin with 'vagrant plugin install sahara'"
            puts(colored.yellow(message))
        else:
            sandbox = SandboxVagrant(minion_path,
                                     quiet_stdout=False,
                                     quiet_stderr=False)
            sandbox_status = sandbox.sandbox_status()

            if sandbox_status == 'on':
                puts(colored.blue("Snapshot is already enabled on VM"))
                if change:
                    puts(
                        colored.blue(
                            "Minion config has changes, would you like to redo the snapshot? It will save the VM in its current state"
                        ))
                    choice = bool_choice("Yes/No: ")
                    if choice:
                        sandbox.sandbox_commit()
            else:
                puts(colored.blue("Would you like to enable snapshot on VM?"))
                choice = bool_choice("Yes/No: ")

                if choice:
                    puts(colored.blue("Starting snapshot"))
                    sandbox.sandbox_on()
                    puts(colored.blue("Done"))
Exemplo n.º 4
0
    def main(self, project_name):
        minion_path = self.parent.config['minions'][project_name]
        self.execute_vagrant_command_on_minion(project_name, 'up')

        # Get back master IP
        puts(colored.blue("Check master ip"))
        command = "/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | cut -d' ' -f 1"
        vm_ip = get_output_cmd(command, minion_path)

        vm_ip = vm_ip.split('.')
        vm_ip[-1] = '1'
        master_ip = ".".join(vm_ip)

        # Check declared master ip
        command = "grep master /etc/salt/minion"
        declared_master_ip = get_output_cmd(command, minion_path)
        declared_master_ip = declared_master_ip.split()[-1]

        change = False

        if declared_master_ip != master_ip:
            puts(colored.yellow("Master ip on minion is invalid, {0} instead of {1}".format(declared_master_ip, master_ip)))

            # Replace master ip
            command = "sudo sed -i 's/{0}/{1}/g' /etc/salt/minion".format(declared_master_ip, master_ip)
            result = get_output_cmd(command, minion_path)

            # Reboot minion
            command = "sudo /etc/init.d/salt-minion restart"
            result = get_output_cmd(command, minion_path)

            # Change minion
            command = "sed -i 's/{0}/{1}/g' {2}".format(declared_master_ip, master_ip, join(minion_path, 'minion'))
            check_output(command, shell=True)

            # Wait for minion to connect
            sleep(10)

            puts(colored.blue("Master ip has been updated from {0} to {1}".format(declared_master_ip, master_ip)))
            change = True
        else:
            puts(colored.blue("Master is good"))

        # Check if sahara is available
        minion_path = self.parent.config['minions'][project_name]
        try:
            plugins = Vagrant(minion_path).plugin_list()
        except Exception as e:
            raise

        sahara = bool([p for p in plugins if p.name == "sahara"])

        if not sahara:
            message = "Sandbox support is not available, please install sahara"\
                      " plugin with 'vagrant plugin install sahara'"
            puts(colored.yellow(message))
        else:
            sandbox = SandboxVagrant(minion_path, quiet_stdout=False, quiet_stderr=False)
            sandbox_status = sandbox.sandbox_status()

            if sandbox_status == 'on':
                puts(colored.blue("Snapshot is already enabled on VM"))
                if change:
                    puts(colored.blue("Minion config has changes, would you like to redo the snapshot? It will save the VM in its current state"))
                    choice = bool_choice("Yes/No: ")
                    if choice:
                        sandbox.sandbox_commit()
            else:
                puts(colored.blue("Would you like to enable snapshot on VM?"))
                choice = bool_choice("Yes/No: ")

                if choice:
                    puts(colored.blue("Starting snapshot"))
                    sandbox.sandbox_on()
                    puts(colored.blue("Done"))