Esempio n. 1
0
 def restore_default_df_path(self):
     if self.is_running():
         Executor.exec_sync(self.cmd.shutdown_vm(force=True))
         time.sleep(3)
     Executor.exec_sync(self.cmd.sharedfolder_remove())
     self.config.restore_default("data_folder")
     fullpath = get_full_path(self.config["data_folder"])
     if not os.path.exists(fullpath):
         os.makedirs(fullpath)
     res = Executor.exec_sync(self.cmd.sharedfolder_setup(fullpath))
     if res[0] != 0:
         raise IslandManagerException(
             "Datafolder reset finished with error: %s" % res[2])
Esempio n. 2
0
 def set_new_datafolder(self, new_path):
     if self.is_running():
         Executor.exec_sync(self.cmd.shutdown_vm(force=True))
         time.sleep(3)
     new_path_full = get_full_path(new_path)
     if not os.path.exists(new_path_full):
         os.makedirs(new_path_full)
     Executor.exec_sync(self.cmd.sharedfolder_remove())
     self.config['data_folder'] = new_path_full
     self.config.save()
     res = Executor.exec_sync(self.cmd.sharedfolder_setup(new_path_full))
     if res[0] != 0:
         raise IslandManagerException(
             "Datafolder setup finished with error: %s" % res[2])
Esempio n. 3
0
 def is_running(self):
     res = Executor.exec_sync(self.cmd.vminfo())
     log.debug("IS RUNNING RES: %s" % str(res[1]))
     if res[0] != 0:
         return False
     vminfo = parse_vminfo_output(res[1])
     return vminfo["VMState"] == "running"
Esempio n. 4
0
 def _install_vbox_dar_win(self, path_to_installer):
     """
     Same procedure for MACOS and windows
     :param path_to_installer:
     :return:
     """
     return Executor.exec_stream(self.cmd.install_vbox(path_to_installer),
                                 self.message, self.error)
Esempio n. 5
0
    def is_vbox_up_to_date(self):
        log.debug("Checking vbox version.")
        res = Executor.exec_sync(self.cmd.vboxmanage_version())
        v_output = list(filter(None, res[1].split("\n")))

        version = re.sub(r'[^\d^\.]', "", v_output[-1])
        version = [int(i) for i in version.split('.')]
        version[2] = int(str(version[2])[0:2])
        return (res[0] == 0 and version[0] == 5 and version[1] >= 2
                and version[2] >= 18) or version[0] >= 6
Esempio n. 6
0
 def get_vm_list(self):
     try:
         execres = Executor.exec_sync(self.cmd.listvms())
         if execres[0] != 0:
             return None
         res = []
         lines = execres[1].split("\n")
         for line in lines:
             res.append([i.strip("\"{}") for i in line.split(" ")])
         return res
     except Exception as e:
         log.error("Error getting vms list: %s" % str(e))
Esempio n. 7
0
    def wait_guest_additions(self):
        for i in range(10):
            # Check version 1.0.0

            if (path.exists(self.config.get_stats_path()) and \
                time() - lstat(self.config.get_stats_path()).st_mtime < 1.5) or \
                Executor.exec_sync(self.cmd.ls_on_guest())[0] == 0:  # Check version < 1.0.0
                    print("Looks like guestcontrol is available on Islands VM! Returning...")
                    return
            print("Awaiting for initial setup to complete..")
            sleep(15)
        raise IslandSetupError("Guest additions installation timed out. Please restart setup")
Esempio n. 8
0
 def import_vm(self, path_to_image, on_data, on_error):
     """
     Given path to ova file executes the command that imports the image into VM
     :param path_to_image:
     :param on_data:
     :param on_error:
     :return:
     """
     self.message("Importing virtual appliance..")
     return Executor.exec_stream(self.cmd.import_vm(path_to_image=path_to_image,
                                                    vmname=self.config["vmname"]),
                                 on_data=on_data, on_error=on_error)
Esempio n. 9
0
 def worker():
     if self.setup.is_setup_required():
         state_emitter(States.SETUP_REQUIRED)
         return
     if not self.is_running():
         state_emitter(States.STARTING_UP)
         Executor.exec_sync(self.cmd.start_vm(headless))
         t1 = time.time()
         while not self.is_boot_complete() and (time.time() -
                                                t1) < timeout:
             if self.setup.is_setup_required():
                 state_emitter(States.SETUP_REQUIRED)
                 return
             time.sleep(4)
         if self.is_running():
             state_emitter(States.RUNNING)
         elif self.setup.is_setup_required():
             state_emitter(States.SETUP_REQUIRED)
         else:
             print("Startup error. VM hasn't started up")
             state_emitter(States.UNKNOWN)
Esempio n. 10
0
 def test_config(self):
     c = IMConfig("win32", "../", "../", "../os_defaults/")
     cmd = Cmd(c)
     command = cmd.ip_a_eth1_onguest()
     res = Exec.exec_sync(command)
     response = [line for line in res[1].split("\n") if "eth1" in line]
     for line in response:
         search_res = re.search(r'(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)',
                                line)
         if search_res:
             ip = search_res.group()
             print(ip)
Esempio n. 11
0
 def get_islands_ip(self):
     res = Executor.exec_sync(
         self.cmd.vm_guestproperty(
             property="/VirtualBox/GuestInfo/Net/1/V4/IP"))
     if res[0] == 0 and re.search(
             r'(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)', res[1]):
         try:
             ip = res[1].split(": ")[1].strip()
             log.debug("Found IP address: %s" % res[1])
             return ip
         except Exception as e:
             log.warning("Error getting IP address: %s" % str(e))
             log.debug(res[1])
Esempio n. 12
0
 def is_islands_vm_exist(self):
     try:
         execres = Executor.exec_sync(self.cmd.listvms())
         if execres[0] != 0:
             return False
         lines = execres[1].split("\n")
         pattern = re.compile("^\"%s\".*" % self.__config['vmname'])
         for line in lines:
             if pattern.match(line):
                 return True
         return False
     except Exception as e:
         print("is_islands_vm_exist EXCEPTION!: " + str(e))
         return False
Esempio n. 13
0
 def worker():
     if self.setup.is_setup_required():
         state_emitter(States.SETUP_REQUIRED)
         return
     if self.is_running():
         state_emitter(States.SHUTTING_DOWN)
         Executor.exec_sync(self.cmd.shutdown_vm(force))
     t1 = time.time()
     while self.is_running() and time.time() - t1 < timeout:
         if self.setup.is_setup_required():
             state_emitter(States.SETUP_REQUIRED)
             return
         else:
             time.sleep(4)
     if self.setup.is_setup_required():
         state_emitter(States.SETUP_REQUIRED)
     elif not self.is_running():
         state_emitter(States.NOT_RUNNING)
     elif self.is_running():
         log.debug("ERROR shutting down")
         state_emitter(States.RUNNING)
     else:
         log.error("Fatal error: Island state is unknown")
         state_emitter(States.UNKNOWN)
Esempio n. 14
0
    def _linux_install_proceed(self):
        """
        Assuming that vbox installer is already downloaded
        :return:
        """
        self.message("Running virtualbox installation script...")
        # Checking whether the installer really exists
        if self.path_to_vbox_distr is None or not path.exists(
                self.path_to_vbox_distr):
            log.error("Vbox installer not found. Aborting...")
            raise FileNotFoundError("Virtualbox installer not found")
        log.debug("Installer found")

        # Checking if user is root
        sudo_command = ""
        if getuid() != 0:
            log.debug("Checking sudo")
            sudo_flavors = ["gksudo", "pkexec", "kdesudo"]
            for f in sudo_flavors:
                if which(f) is not None:
                    sudo_command = f
                    break
            if sudo_command == "":
                raise Exception(
                    "Cannot elevate rights. Please restart as root or install virtualbox manually"
                )

        log.debug("Adding execute rights to the installer")
        res, stdout, stderr = Executor.exec_sync("chmod +x %s" %
                                                 self.path_to_vbox_distr)
        if res != 0:
            raise Exception(
                "Unable to add execution rights for the Virtualbox installer.")
        log.debug("VBOX install: all prerequisites checked. Continuing...")

        self.message("Installing Virtualbox. This may take a few minutes.")
        cmd = "%s %s" % (sudo_command, self.path_to_vbox_distr)
        res, stdout, stderr = self.install_vbox_linux(cmd)
        self.message(stdout)
        self.complete(True, "Virtualbox installed successfully.")
Esempio n. 15
0
 def setup_host_only_adapter(self):
     """
     This assumes that VM is already imported
     There is no way to check whether vboxnet0 interface exists,
     so we issue erroneous command to modify it
     if exitcode is 1 - interface doesn't exists, so we create it
     if exitcode is 2 - interface found and we can add it to our VM
     Otherwise there is some other error and we raise it
     """
     res = Executor.exec_sync(self.cmd.hostonly_config())
     if res[0] == 1:
         Executor.exec_sync(self.cmd.hostonly_create())
     elif res[0] != 2:
         raise Exception(res[2])
     """Installing adapter onto vm """
     self.message("Enabling DHCP...")
     Executor.exec_sync(self.cmd.hostonly_enable_dhcp())
     return Executor.exec_sync(self.cmd.hostonly_setup())
Esempio n. 16
0
 def is_boot_complete(self):
     # Version 1.0.0 check
     return (os.path.exists(self.config.get_stats_path()) and \
         time.time() - os.lstat(self.config.get_stats_path()).st_mtime < 1.5) or \
         Executor.exec_sync(self.cmd.ls_on_guest())[0] == 0 # Version <1.0.0 check
Esempio n. 17
0
 def start_vm(headless=True):
     headless = " --type headless " if headless else ""
     cmd = "{vboxmanage} startvm Island {headless}".format(vboxmanage=self.config["vboxmanage"],
                                                           headless=headless)
     return Executor.exec_sync(cmd)
Esempio n. 18
0
 def test_grep(self):
     res = Executor.exec("vboxmanage list vms | "
             "grep -c \\\"{vmname}\\\"  ".format(vmname="Island"))
     print(not not res)
Esempio n. 19
0
 def setup_shared_folder(self, data_folder_path=""):
     fullpath = get_full_path(data_folder_path)
     if not path.exists(fullpath):
         makedirs(fullpath)
     return Executor.exec_sync(self.cmd.sharedfolder_setup(fullpath))
Esempio n. 20
0
 def _get_guest_properties(self):
     return Executor.exec_sync(self.cmd.vm_guestproperty())
Esempio n. 21
0
 def start_vm(self, headless=True):
     return Executor.exec_sync(self.cmd.start_vm(headless))
Esempio n. 22
0
 def delete_islands_vm(self):
     return Executor.exec_sync(self.cmd.delete_vm())
Esempio n. 23
0
 def _get_vminfo(self):
     return Executor.exec_sync(self.cmd.vminfo())
Esempio n. 24
0
 def insert_guest_additions_image(self):
     return Executor.exec_sync(self.cmd.insert_guest_additions())
Esempio n. 25
0
 def onvm_get_setup_script(self):
     return Executor.exec_sync(self.cmd.onvm_get_setup_script())
Esempio n. 26
0
 def onvm_chmodx_install_script(self):
     return Executor.exec_sync(self.cmd.onvm_chmodx_install_script())
Esempio n. 27
0
 def onvm_launch_setup_script(self):
     def on_data(msg):
         self.message(msg=msg, size=8, color="black")
     return Executor.exec_stream(
         self.cmd.onvm_launch_setup_script(),
         on_data=on_data, on_error=on_data)
Esempio n. 28
0
 def shutdown_vm(self, force=False):
     return Executor.exec_sync(self.cmd.shutdown_vm(force=force))
Esempio n. 29
0
 def stop_island_sync(self, force=True):
     return Executor.exec_sync(self.cmd.shutdown_vm(force))
Esempio n. 30
0
 def is_vbox_installed(self):
     com = self.cmd.vboxmanage_version()
     res = Executor.exec_sync(com)
     log.debug("is_vbox_installed 0: %s 1: %s 2:%s " %
               (str(res[0]), str(res[1]), str(res[2])))
     return res[0] == 0