예제 #1
0
파일: VMachine.py 프로젝트: BwRy/test-av2
    def send_files(self, src_dir, dst_dir, filestocopy):
        with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:

            self._run_vm(vm, "login_in_guest", self.user, self.passwd)

            memo = []
            for filetocopy in filestocopy:
                d, f = filetocopy.split("/")
                src = "%s/%s/%s" % (src_dir, d, f)

                if d == ".":
                    dst = "%s\\%s" % (dst_dir, f)
                else:
                    dst = "%s\\%s\\%s" % (dst_dir, d, f)

                rdir = "%s\\%s" % (dst_dir, d)
                if not rdir in memo:
                    logging.debug("making directory %s " % (rdir))
                    self._run_vm(vm, "make_directory", rdir)
                    memo.append(rdir)

                try:
                    logging.debug("copy %s -> %s" % (src, dst))
                    self._run_vm(vm, "send_file", src, dst)
                except:
                    logging.debug("resending file %s -> %s" % (src, dst))
                    self._run_vm(vm, "send_file", src, dst)
예제 #2
0
    def send_files(self, src_dir, dst_dir, filestocopy):
        with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                     self.sdkpasswd) as vm:

            self._run_vm(vm, "login_in_guest", self.user, self.passwd)

            memo = []
            for filetocopy in filestocopy:
                d, f = filetocopy.split("/")
                src = "%s/%s/%s" % (src_dir, d, f)

                if d == ".":
                    dst = "%s\\%s" % (dst_dir, f)
                else:
                    dst = "%s\\%s\\%s" % (dst_dir, d, f)

                rdir = "%s\\%s" % (dst_dir, d)
                if not rdir in memo:
                    logging.debug("making directory %s " % (rdir))
                    self._run_vm(vm, "make_directory", rdir)
                    memo.append(rdir)

                try:
                    logging.debug("copy %s -> %s" % (src, dst))
                    self._run_vm(vm, "send_file", src, dst)
                except:
                    logging.debug("resending file %s -> %s" % (src, dst))
                    self._run_vm(vm, "send_file", src, dst)
예제 #3
0
파일: VMachine.py 프로젝트: BwRy/test-av2
 def list_directory(self, dir_path):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:
         try:
             self._run_vm(vm, "login_in_guest", self.user, self.passwd)
             return self._run_vm(vm, "list_files", dir_path)
         #            except VIApiException:
         #                logging.error("path %s is not found on vm %s") % (dir_path, vm)
         #                raise Exception("path %s is not found on vm %s" % (dir_path, vm))
         except Exception as e:
             print "EXCEPTION %s" % e
             return None
예제 #4
0
파일: VMachine.py 프로젝트: BwRy/test-av2
    def _run_cmd(self, func, *params):
        try:
            with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:
                f = getattr(vm, func)

                if len(params) is None:
                    return f
                else:
                    return f(*params)
        except Exception as e:
            logging.error("%s, ERROR: Problem running %s. Reason: %s" % (self.name, func, e))
            raise
예제 #5
0
 def list_directory(self, dir_path):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                  self.sdkpasswd) as vm:
         try:
             self._run_vm(vm, "login_in_guest", self.user, self.passwd)
             return self._run_vm(vm, "list_files", dir_path)
         #            except VIApiException:
         #                logging.error("path %s is not found on vm %s") % (dir_path, vm)
         #                raise Exception("path %s is not found on vm %s" % (dir_path, vm))
         except Exception as e:
             print "EXCEPTION %s" % e
             return None
예제 #6
0
    def _run_cmd(self, func, *params):
        try:
            with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                         self.sdkpasswd) as vm:
                f = getattr(vm, func)

                if len(params) is None:
                    return f
                else:
                    return f(*params)
        except Exception as e:
            logging.error("%s, ERROR: Problem running %s. Reason: %s" %
                          (self.name, func, e))
            raise
예제 #7
0
파일: VMachine.py 프로젝트: BwRy/test-av2
    def _run_task(self, func, *params):

        def wait_for(task):
            s = task.wait_for_state(['success', 'error'])

            if s == 'error':
                logging.error("ERROR: problem with task %s: %s" % (func, task.get_error_message()))
                return False
            return True

        try:
            with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:
                f = getattr(vm, func)
                if len(params) is None:
                    task = f(sync_run=False)
                else:
                    task = f(sync_run=False, *params)
                return wait_for(task)
        except Exception as e:
            logging.error("%s, ERROR: Problem running %s. Reason: %s" % (self.name, func, e))
            raise
예제 #8
0
    def _run_task(self, func, *params):
        def wait_for(task):
            s = task.wait_for_state(['success', 'error'])

            if s == 'error':
                logging.error("ERROR: problem with task %s: %s" %
                              (func, task.get_error_message()))
                return False
            return True

        try:
            with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                         self.sdkpasswd) as vm:
                f = getattr(vm, func)
                if len(params) is None:
                    task = f(sync_run=False)
                else:
                    task = f(sync_run=False, *params)
                return wait_for(task)
        except Exception as e:
            logging.error("%s, ERROR: Problem running %s. Reason: %s" %
                          (self.name, func, e))
            raise
예제 #9
0
파일: VMachine.py 프로젝트: BwRy/test-av2
 def get_file(self, src_file, dst_file):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:
         self._run_vm(vm, "login_in_guest", self.user, self.passwd)
         return self._run_vm(vm, "get_file", src_file, dst_file)
예제 #10
0
파일: VMachine.py 프로젝트: BwRy/test-av2
 def make_directory(self, dst_dir):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain, self.sdkpasswd) as vm:
         self._run_vm(vm, "login_in_guest", self.user, self.passwd)
         return self._run_vm(vm, "make_directory", dst_dir)
예제 #11
0
 def get_file(self, src_file, dst_file):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                  self.sdkpasswd) as vm:
         self._run_vm(vm, "login_in_guest", self.user, self.passwd)
         return self._run_vm(vm, "get_file", src_file, dst_file)
예제 #12
0
 def make_directory(self, dst_dir):
     with vSphere(self.path, self.sdkhost, self.sdkuser, self.sdkdomain,
                  self.sdkpasswd) as vm:
         self._run_vm(vm, "login_in_guest", self.user, self.passwd)
         return self._run_vm(vm, "make_directory", dst_dir)