Ejemplo n.º 1
0
    def destroy_vm(self, vm_id):
        vm_id = self.validate_vm_id(vm_id)
        try:

            command = (r'ssh -o "%s" %s "%s stop %s"' %
                       (base_config.NO_STRICT_CHECKING,
                        base_config.BASE_IP_ADDRESS,
                        VZCTL, vm_id))
            logger.debug("BridgeVZAdapter: destroy_vm(): stop command = %s" %
                         command)
            (ret_code, output) = execute_command(command)

            if ret_code == 0:
                command = (r'ssh -o "%s" %s "%s destroy %s"' %
                           (base_config.NO_STRICT_CHECKING,
                            base_config.BASE_IP_ADDRESS,
                            VZCTL, vm_id))
                logger.debug("BridgeVZAdapter: destroy_vm(): destroy command = \
                             %s" % command)
                (ret_code, output) = execute_command(command)
                if ret_code == 0:
                    return "Success"
        except Exception, e:
            logger.error("Error destroying VM: " + str(e))
            return "Failed to destroy VM: " + str(e)
Ejemplo n.º 2
0
    def create_vm(self, lab_spec, vm_id=""):
        logger.debug("centos_openvz_adapter: create_vm()")
        """If no vm_id is specified, it is computed using the last two
        segments"""
        """of an available IP address; vm_spec is an object """
        if vm_id == "":
            ip_address = base_adapter.find_available_ip()
            m = re.match(r'[0-9]+.[0-9]+.([0-9]+).([0-9]+)', ip_address)
            if m is not None:
                vm_id = str((int(m.group(1) + m.group(2))))
                # vm_id = m.group(1) + m.group(2)
        else:
            ip_address = None
            vm_id = self.validate_vm_id(vm_id)

        (vm_create_args, vm_set_args) = self.construct_vzctl_args(lab_spec)

        logger.debug("centos_openvz_adapter: create_vm(): ip = %s, vm_id = %s, \
                     vm_create_args = %s, vm_set_args = %s" %
                     (ip_address, vm_id, vm_create_args, vm_set_args))

        try:
            command = (r'ssh -o "%s" %s "%s create %s %s"' %
                       (base_config.NO_STRICT_CHECKING,
                        base_config.BASE_IP_ADDRESS,
                        VZCTL, vm_id, vm_create_args))
            logger.debug("centos_openvz_adapter: create_vm(): create command = %s" %
                         command)
            (ret_code, output) = execute_command(command)

            if ret_code == 0:

                command = (r'ssh -o "%s" %s "%s start %s"' %
                           (base_config.NO_STRICT_CHECKING,
                            base_config.BASE_IP_ADDRESS,
                            VZCTL, vm_id))
                logger.debug("centos_openvz_adapter: create_vm():start command = %s" %
                             command)
                (ret_code, output) = execute_command(command)

                if ret_code == 0:

                    command = (r'ssh -o "%s" %s "%s set %s %s"' %
                               (base_config.NO_STRICT_CHECKING,
                                base_config.BASE_IP_ADDRESS,
                                VZCTL, vm_id, vm_set_args))
                    logger.debug("centos_openvz_adapter:create_vm():set command=%s" %
                                 command)
                    (ret_code, output) = execute_command(command)

                    if ret_code == 0:
                        return (True, vm_id)

        except Exception, e:
            logger.error("Error creating VM: " + str(e))
            # raise e
            return (False, -1)
Ejemplo n.º 3
0
    def fill_aptconf():

        try:
            http_proxy = os.environ["http_proxy"]
            https_proxy = os.environ["https_proxy"]
            http_cmd = r'echo "Acquire::http::Proxy \"%s\";"%s' % (http_proxy, '>>/etc/apt/apt.conf')
            https_cmd = r'echo "Acquire::https::Proxy \"%s\";"%s' % (https_proxy, '>>/etc/apt/apt.conf')
            (ret_code, output) = execute_command(http_cmd)
            (ret_code, output) = execute_command(https_cmd)
        except Exception, e:
            logger.error("Writing to /etc/apt/apt.conf failed with error: %s"
                         % (str(e)))
            raise e
Ejemplo n.º 4
0
 def copy_public_key(self, vm_id):
     
     try:
         public_key_file = ("%s%s%s%s" %
                            (base_config.VM_ROOT_DIR,
                             base_config.ADS_SERVER_VM_ID,
                             base_config.VM_DEST_DIR, ".ssh/id_rsa.pub"))
         
         authorized_key_file = ("%s%s%s%s" %
                                (base_config.VM_ROOT_DIR, vm_id,
                                 base_config.VM_DEST_DIR,
                                 ".ssh/authorized_keys"))
         
         logger.debug("public key location = %s, authorized key location = %s" %
                      (public_key_file, authorized_key_file))
         command = (r'ssh -o "%s" %s "%s %s > %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS,
                     "/bin/cat", public_key_file, authorized_key_file))
         logger.debug("command to cpy the public key = %s" % command)
         (ret_code, output) = execute_command(command)
         return True
     except Exception, e:
         logger.error("ERROR = %s" % str(e))
         return False
Ejemplo n.º 5
0
 def fill_aptconf(lab_spec):
     OS = str(lab_spec['lab']['runtime_requirements']['platform']['os'])
     http_proxy = os.environ["http_proxy"]
     https_proxy = os.environ["https_proxy"]
     if OS == "ubuntu":
         try:
             http_cmd = r'echo "Acquire::http::Proxy \"%s\";"%s' % (
                 http_proxy, '>>/etc/apt/apt.conf')
             https_cmd = r'echo "Acquire::https::Proxy \"%s\";"%s' % (
                 https_proxy, '>>/etc/apt/apt.conf')
             (ret_code, output) = execute_command(http_cmd)
             (ret_code, output) = execute_command(https_cmd)
         except Exception, e:
             logger.error(
                 "Writing to /etc/apt/apt.conf failed with error: %s" %
                 (str(e)))
             raise e
Ejemplo n.º 6
0
def execute(command):
    # do some validation
    try:
        logger.info("Command executed: " + command)
        (ret_code, output) = execute_command(command)
        return output
    except Exception, e:
        logger.error("Execution failed: " + str(e))
        return "Error executing the command: " + str(e)
Ejemplo n.º 7
0
    def test_create_vm(self):
        test_logger.debug("test_create_vm()")
        (status, self.vm_id) = self.adapter.create_vm(self.lab_spec)
        test_logger.debug("test_create_vm(): status = %s, vm_id = %s" % (str(status), str(self.vm_id)))
	check_cmd = "ssh root@%s 'vzlist %s'" % (self.base_ip, self.vm_id)
        test_logger.debug("test_create_vm(): check_cmd = %s" % check_cmd)
	(return_code, output) = execute_command(check_cmd)
        test_logger.debug("test_create_vm(): return_code = %s" % str(return_code))
        self.assertEqual(return_code, 0)
        test_logger.debug("test_create_vm(): Test passed") 
Ejemplo n.º 8
0
 def reset_repo(self, repo_name):
     repo = self.git_clone_loc + repo_name
     reset_cmd = "git --git-dir=%s/.git --work-tree=%s reset --hard" % (repo, repo)
     logger.debug("reset cmd: %s" % reset_cmd)
     try:
         (ret_code, output) = execute_command(reset_cmd)
         logger.debug("reset repo successful")
     except Exception, e:
         logger.error("Error Resetting the repository: " + str(e))
         raise e
Ejemplo n.º 9
0
 def pull_repo(self, repo_name):
     repo = self.git_clone_loc + repo_name
     pull_cmd = "git --git-dir=%s/.git --work-tree=%s pull" % (repo, repo)
     logger.debug("pull cmd: %s" % pull_cmd)
     try:
         (ret_code, output) = execute_command(pull_cmd)
         logger.debug("Pull repo successful")
     except Exception, e:
         logger.error("Error Pulling the repository: " + str(e))
         raise e
Ejemplo n.º 10
0
 def clone_repo(self, lab_src_url, repo_name):
     clone_cmd = "git clone %s %s%s" % (lab_src_url, self.git_clone_loc,
                                        repo_name)
     logger.debug(clone_cmd)
     try:
         (ret_code, output) = execute_command(clone_cmd)
         logger.debug("Clone repo successful")
     except Exception, e:
         logger.error("Error Cloning the repository: " + str(e))
         raise e
Ejemplo n.º 11
0
 def clone_repo(self, lab_src_url, repo_name):
     clone_cmd = "git clone %s %s%s" % (lab_src_url, self.git_clone_loc,
                                        repo_name)
     logger.debug(clone_cmd)
     try:
         (ret_code, output) = execute_command(clone_cmd)
         logger.debug("Clone repo successful")
     except Exception, e:
         logger.error("Error Cloning the repository: " + str(e))
         raise e
Ejemplo n.º 12
0
 def pull_repo(self, repo_name):
     repo = self.git_clone_loc + repo_name
     pull_cmd = "git --git-dir=%s/.git --work-tree=%s pull" % (repo, repo)
     logger.debug("pull cmd: %s" % pull_cmd)
     try:
         (ret_code, output) = execute_command(pull_cmd)
         logger.debug("Pull repo successful")
     except Exception, e:
         logger.error("Error Pulling the repository: " + str(e))
         raise e
Ejemplo n.º 13
0
    def start_vm_manager(self, vm_ip_addr):
        logger.debug("AWSAdapter: Attempting to start VMMgr: vm_ip:%s"
                     % (vm_ip_addr))

        ssh_command = "ssh -i {0} -o StrictHostKeyChecking=no {1}@{2} ".\
            format(self.key_file_path, self.VM_USER, vm_ip_addr)

        vmmgr_cmd = "'python {0}{1} >> vmmgr.log 2>&1 < /dev/null &'".\
            format(settings.VMMANAGERSERVER_PATH, settings.VM_MANAGER_SCRIPT)

        command = ssh_command + vmmgr_cmd

        logger.debug("AWSAdapter: start_vm_manager(): command = %s" % command)

        try:
            execute_command(command)
        except Exception, e:
            logger.error("AWSAdapter: start_vm_manager(): " +
                         "command = %s, ERROR = %s" % (command, str(e)))
            return False
Ejemplo n.º 14
0
 def checkout_version(self, repo_name, version=None):
     repo = self.git_clone_loc + repo_name
     if version is None:
         version = "master"
     checkout_cmd = "git --git-dir=%s/.git --work-tree=%s checkout %s" % (repo, repo, version)
     try:
         (ret_code, output) = execute_command(checkout_cmd)
         logger.debug("Checkout repo successful")
     except Exception, e:
         logger.error("Error checking out the repository: " + str(e))
         raise e
Ejemplo n.º 15
0
 def reset_repo(self, repo_name):
     repo = self.git_clone_loc + repo_name
     reset_cmd = "git --git-dir=%s/.git --work-tree=%s reset --hard" % (
         repo, repo)
     logger.debug("reset cmd: %s" % reset_cmd)
     try:
         (ret_code, output) = execute_command(reset_cmd)
         logger.debug("reset repo successful")
     except Exception, e:
         logger.error("Error Resetting the repository: " + str(e))
         raise e
Ejemplo n.º 16
0
 def restart_vm(self, vm_id):
     vm_id = self.validate_vm_id(vm_id)
     try:
         command = (r'ssh -o "%s" %s "%s restart %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS,
                     VZCTL, vm_id))
         logger.debug("BridgeVZAdapter: restart_vm(): restart command = %s"
                      % command)
         (ret_code, output) = execute_command(command)
     except Exception, e:
         raise e
Ejemplo n.º 17
0
 def checkout_version(self, repo_name, version=None):
     repo = self.git_clone_loc + repo_name
     if version is None:
         version = "master"
     checkout_cmd = "git --git-dir=%s/.git --work-tree=%s checkout %s" % (
         repo, repo, version)
     try:
         (ret_code, output) = execute_command(checkout_cmd)
         logger.debug("Checkout repo successful")
     except Exception, e:
         logger.error("Error checking out the repository: " + str(e))
         raise e
Ejemplo n.º 18
0
    def start_vm_manager(self, vm_ip_addr):
        ovpl_dir_name = base_adapter.OVPL_DIR_PATH.split("/")[-1]
        vm_ovpl_path = base_config.VM_DEST_DIR + ovpl_dir_name
        logger.debug("AWSAdapter: Attempting to start VMMgr: vm_ip:%s" %
                     (vm_ip_addr))

        ssh_command = "ssh -i {0} -o StrictHostKeyChecking=no {1}@{2} ".\
            format(self.key_file_path, self.VM_USER, vm_ip_addr)

        vmmgr_cmd = "'python {0}{1} >> vmmgr.log 2>&1 < /dev/null &'".\
            format(vm_ovpl_path, base_config.VM_MANAGER_SERVER_PATH)

        command = ssh_command + vmmgr_cmd

        logger.debug("AWSAdapter: start_vm_manager(): command = %s" % command)

        try:
            execute_command(command)
        except Exception, e:
            logger.error("AWSAdapter: start_vm_manager(): " +
                         "command = %s, ERROR = %s" % (command, str(e)))
            return False
Ejemplo n.º 19
0
    def start_vm_manager(self, vm_ip_addr):
        ovpl_dir_name = base_adapter.OVPL_DIR_PATH.split("/")[-1]
        vm_ovpl_path = base_config.VM_DEST_DIR + ovpl_dir_name
        logger.debug("AWSAdapter: Attempting to start VMMgr: vm_ip:%s"
                     % (vm_ip_addr))

        ssh_command = "ssh -i {0} -o StrictHostKeyChecking=no {1}@{2} ".\
            format(self.key_file_path, self.VM_USER, vm_ip_addr)

        vmmgr_cmd = "'python {0}{1} >> vmmgr.log 2>&1 < /dev/null &'".\
            format(vm_ovpl_path, base_config.VM_MANAGER_SERVER_PATH)

        command = ssh_command + vmmgr_cmd

        logger.debug("AWSAdapter: start_vm_manager(): command = %s" % command)

        try:
            execute_command(command)
        except Exception, e:
            logger.error("AWSAdapter: start_vm_manager(): " +
                         "command = %s, ERROR = %s" % (command, str(e)))
            return False
Ejemplo n.º 20
0
 def register_lab(self, lab_id, ip_address):
     service_host = base_config.SERVICE_HOST
     service_name = "hosting_service"
     service_action = "register"
     command = 'ssh  %s %s %s %s %s' % \
               (service_host, service_name, service_action, lab_id,
                ip_address)
     logger.debug("Hook's service command =  %s" % command)
     (ret_code, output) = execute_command(command)
     if ret_code == 0:
         domain_name = lab_id + "." + get_adapter_hostname()
         logger.debug("FQDN of lab is  =  %s" % domain_name)
         return domain_name
Ejemplo n.º 21
0
    def _add_default_gw(self, vm_ip):
        if not self.default_gw:
            return True

        logger.debug("AWSAdapter: Attempting to add default gateway to VM: %s"
                     % (vm_ip))

        ssh_command = "ssh -i {0} -o StrictHostKeyChecking=no {1}@{2} ".\
            format(self.key_file_path, self.VM_USER, vm_ip)

        add_def_gw_cmd = "'route del default; route add default gw {0}'".\
            format(self.default_gw)

        command = ssh_command + add_def_gw_cmd

        logger.debug("AWSAdapter: _add_default_gw(): command = %s" % command)

        try:
            execute_command(command)
        except Exception, e:
            logger.error("AWSAdapter: _add_default_gw(): " +
                         "command = %s, ERROR = %s" % (command, str(e)))
            return False
Ejemplo n.º 22
0
    def _add_default_gw(self, vm_ip):
        if not self.default_gw:
            return True

        logger.debug(
            "AWSAdapter: Attempting to add default gateway to VM: %s" %
            (vm_ip))

        ssh_command = "ssh -i {0} -o StrictHostKeyChecking=no {1}@{2} ".\
            format(self.key_file_path, self.VM_USER, vm_ip)

        add_def_gw_cmd = "'route del default; route add default gw {0}'".\
            format(self.default_gw)

        command = ssh_command + add_def_gw_cmd

        logger.debug("AWSAdapter: _add_default_gw(): command = %s" % command)

        try:
            execute_command(command)
        except Exception, e:
            logger.error("AWSAdapter: _add_default_gw(): " +
                         "command = %s, ERROR = %s" % (command, str(e)))
            return False
Ejemplo n.º 23
0
    def stop_vm(self, vm_id):
        vm_id = self.validate_vm_id(vm_id)
        try:
            command = (r'ssh -o "%s" %s "%s stop %s"' %
                       (base_config.NO_STRICT_CHECKING,
                        base_config.BASE_IP_ADDRESS,
                        VZCTL, vm_id))
            logger.debug("centos_openvz_adapter: stop_vm(): command = %s" %
                         command)
            (ret_code, output) = execute_command(command)
            return "Success"

        except Exception, e:
            logger.error("Error stopping VM: " + str(e))
            return "Failed to stop VM: " + str(e)
Ejemplo n.º 24
0
 def start_container(self, vm_id):
     try:
         command = (r'ssh -o "%s" %s "%s start %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS, VZCTL, vm_id))
         logger.debug("BridgeVZAdapter: start_container(): start command = \
                      %s" % command)
         (ret_code, output) = execute_command(command)
         if ret_code == 0:
             return True
         else:
             return False
     except Exception, e:
         logger.error("Error starting VM: " + str(e))
         return False
Ejemplo n.º 25
0
 def run(self):
     """Runs a command. Waits for the command to finish."""
     if len(self._cmd) == 0:
         logger.error("LabActionScript::run() - No command to run")
         raise EmptyLabActionError("No command to run")
     try:
         # self._cmd[0] = os.path.join(self._path_prefix, self._cmd[0])
         logger.debug("LabActionScript::run() - " + os.environ["http_proxy"])
         logger.debug("LabActionScript::run() - " + self._cmd)
         logger.debug("LabActionScript::run() - " + str(os.getcwd()))
         (ret_code, output) = execute_command(self._cmd)
         self._state = LabActionScript.ACTION_COMPLETED
     except Exception, e:
         self._state = LabActionScript.ACTION_UNSUCCESSFUL
         logger.error("LabActionScript::run() exception is: %s" % str(e))
Ejemplo n.º 26
0
 def register_lab(self, lab_id, ip_address):
     service_host = base_config.SERVICE_HOST
     service_name = "hosting_service"
     service_action = "register"
     command = 'ssh  %s %s %s %s %s' % \
               (service_host, service_name, service_action, lab_id,
                ip_address)
     logger.debug("Hook's service command =  %s" %
                  command)
     (ret_code, output) = execute_command(command)
     if ret_code == 0:
         domain_name = lab_id + "." +  get_adapter_hostname()
         logger.debug("FQDN of lab is  =  %s" %
                      domain_name)
         return domain_name
Ejemplo n.º 27
0
 def get_vm_ip(self, vm_id):
     vm_id = self.validate_vm_id(vm_id)
     try:
         command = (r'ssh -o "%s" %s "%s | grep %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS,
                     VZLIST, vm_id))
         (ret_code, vzlist) = execute_command(command)
         if vzlist == "":
             return                                  # raise exception?
         ip_address = re.search(IP_ADDRESS_REGEX, vzlist)
         if ip_address is not None:
             ip_address = ip_address.group(0)
         return ip_address
     except Exception, e:
         raise e
Ejemplo n.º 28
0
 def run(self):
     """Runs a command. Waits for the command to finish."""
     if len(self._cmd) == 0:
         logger.error("LabActionScript::run() - No command to run")
         raise EmptyLabActionError("No command to run")
     try:
         # self._cmd[0] = os.path.join(self._path_prefix, self._cmd[0])
         logger.debug("LabActionScript::run() - " +
                      os.environ["http_proxy"])
         logger.debug("LabActionScript::run() - " + self._cmd)
         logger.debug("LabActionScript::run() - " + str(os.getcwd()))
         (ret_code, output) = execute_command(self._cmd)
         self._state = LabActionScript.ACTION_COMPLETED
     except Exception, e:
         self._state = LabActionScript.ACTION_UNSUCCESSFUL
         logger.error("LabActionScript::run() exception is: %s" % str(e))
Ejemplo n.º 29
0
 def set_container_params(self, vm_id, vm_set_args):
     try:
         command = (r'ssh -o "%s" %s "%s set %s %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS,
                     VZCTL, vm_id, vm_set_args))
         logger.debug("BridgeVZAdapter: set_container_params(): set command \
                      = %s" % command)
         (ret_code, output) = execute_command(command)
         if ret_code == 0:
             return self.prepare_vm_for_bridged_network(vm_id)
         else:
             return False
     except Exception, e:
         logger.error("Error setting VM: " + str(e))
         return False
Ejemplo n.º 30
0
 def start_container(self, vm_id):
     try:
         command = (r'ssh -o "%s" %s "%s start %s"' %
                    (base_config.NO_STRICT_CHECKING,
                     base_config.BASE_IP_ADDRESS,
                     VZCTL, vm_id))
         logger.debug("BridgeVZAdapter: start_container(): start command = \
                      %s" % command)
         (ret_code, output) = execute_command(command)
         if ret_code == 0:
             return True
         else:
             return False
     except Exception, e:
         logger.error("Error starting VM: " + str(e))
         return False
Ejemplo n.º 31
0
 def is_ctid_free(ip):
     # to check vm_id is already exist or not
     m = re.match(r'[0-9]+.[0-9]+.([0-9]+).([0-9]+)', ip)
     vm_id = str(int(m.group(1) + m.group(2)))
     command = (r'ssh -o "%s" %s "%s %s| grep %s"' %
                (base_config.NO_STRICT_CHECKING,
                 base_config.BASE_IP_ADDRESS, VZLIST, vm_id, vm_id))
     logger.debug("CentOSVZAdapter: vzlist command = %s" % command)
     try:
         (ret_code, vzlist) = execute_command(command)
         if ret_code == 0:
             return False
         else:
             return True
     except Exception:
         logger.debug("No container found with vm id = %s" % vm_id)
         return True
Ejemplo n.º 32
0
    def copy_files(self, src_dir, dest_dir):

        try:
            copy_command = "rsync -arz --progress " + src_dir + " " + dest_dir
            logger.debug("copy command = %s" % copy_command)
            command = (r'ssh %s "%s"' %
                       (base_config.BASE_IP_ADDRESS, copy_command))
            logger.debug("Command = %s" % command)
            (ret_code, output) = execute_command(command)
            if ret_code == 0:
                logger.debug("Copy successful")
                return True
            else:
                logger.debug("Copy Unsuccessful, return code is %s" % str(ret_code))
                return False
        except Exception, e:
            logger.error("ERROR = %s" % str(e))
            return False
Ejemplo n.º 33
0
    def _copy_files(self, src_dir, dest_dir):
        cmd = "rsync -azr -e 'ssh -i {0} -o StrictHostKeyChecking=no' {1} {2}".\
            format(self.key_file_path, src_dir, dest_dir)

        logger.debug("Command = %s" % cmd)

        try:
            (ret_code, output) = execute_command(cmd)

            if ret_code == 0:
                logger.debug("Copy successful")
                return True
            else:
                logger.debug("Copy Unsuccessful, return code is %s" %
                             str(ret_code))
                return False
        except Exception, e:
            logger.error("ERROR = %s" % str(e))
            return False
Ejemplo n.º 34
0
    def _copy_files(self, src_dir, dest_dir):
        cmd = "rsync -azr -e 'ssh -i {0} -o StrictHostKeyChecking=no' {1} {2}".\
            format(self.key_file_path, src_dir, dest_dir)

        logger.debug("Command = %s" % cmd)

        try:
            (ret_code, output) = execute_command(cmd)

            if ret_code == 0:
                logger.debug("Copy successful")
                return True
            else:
                logger.debug("Copy Unsuccessful, return code is %s" %
                             str(ret_code))
                return False
        except Exception, e:
            logger.error("ERROR = %s" % str(e))
            return False
Ejemplo n.º 35
0
    def prepare_vm_for_bridged_network(self, vm_id):
        src_file = base_adapter.OVPL_DIR_PATH + \
            config.BRIDGE_NETWORK_SETUP_PATH + "bridge-settings"
        dest_file = base_adapter.OVPL_DIR_PATH + \
            config.BRIDGE_NETWORK_SETUP_PATH + "interfaces"

        try:
            copy_command = "rsync -arz --progress " + src_file + " " + dest_file
            logger.debug("copy command = %s" % copy_command)
            command = ('%s' % (copy_command))
            logger.debug("Command = %s" % command)
            (ret_code, output) = execute_command(command)
            if ret_code == 0:
                logger.debug("Copy successful")
            else:
                logger.debug("Copy Unsuccessful, return code is %s"
                             % str(ret_code))
        except Exception, e:
            logger.error("ERROR = %s" % str(e))
Ejemplo n.º 36
0
 def is_ctid_free(ip):
     # to check vm_id is already exist or not
     m = re.match(r'[0-9]+.[0-9]+.([0-9]+).([0-9]+)', ip)
     vm_id = str(int(m.group(1) + m.group(2)))
     command = (r'ssh -o "%s" %s "%s %s| grep %s"' %
                (base_config.NO_STRICT_CHECKING,
                 base_config.BASE_IP_ADDRESS,
                 VZLIST, vm_id, vm_id))
     logger.debug("CentOSVZAdapter: vzlist command = %s" %
                  command)
     try:
         (ret_code, vzlist) = execute_command(command)
         if ret_code == 0:
             return False
         else:
             return True
     except Exception:
         logger.debug("No container found with vm id = %s" % vm_id)
         return True
Ejemplo n.º 37
0
 def start_vm_manager(self, vm_id):
     ovpl_dir_name = base_adapter.OVPL_DIR_PATH.split("/")[-1]
     vm_ovpl_path = base_config.VM_DEST_DIR + ovpl_dir_name
     start_vm_manager_command = (
         "python %s%s %s" %
         (vm_ovpl_path, base_config.VM_MANAGER_SERVER_PATH,
          ">>/root/vm.log 2>&1 </dev/null &"))
     command = (r"ssh -o '%s' %s%s '%s'" %
                (base_config.NO_STRICT_CHECKING, "root@", IP_ADDRESS,
                 start_vm_manager_command))
     logger.debug("BridgeVZAdapter: start_vm_manager(): command = %s" %
                  command)
     try:
         (ret_code, output) = execute_command(command)
         return True
     except Exception, e:
         logger.error("BridgeVZAdapter: start_vm_manager(): command = %s, \
                      ERROR = %s" % (command, str(e)))
         return False
Ejemplo n.º 38
0
    def prepare_vm_for_bridged_network(self, vm_id):
        src_file = base_adapter.OVPL_DIR_PATH + \
            config.BRIDGE_NETWORK_SETUP_PATH + "bridge-settings"
        dest_file = base_adapter.OVPL_DIR_PATH + \
            config.BRIDGE_NETWORK_SETUP_PATH + "interfaces"

        try:
            copy_command = "rsync -arz --progress " + src_file + " " + dest_file
            logger.debug("copy command = %s" % copy_command)
            command = ('%s' % (copy_command))
            logger.debug("Command = %s" % command)
            (ret_code, output) = execute_command(command)
            if ret_code == 0:
                logger.debug("Copy successful")
            else:
                logger.debug("Copy Unsuccessful, return code is %s" %
                             str(ret_code))
        except Exception, e:
            logger.error("ERROR = %s" % str(e))
Ejemplo n.º 39
0
    def create_container(self, vm_id, vm_create_args):
        try:
            command = (r'ssh -o "%s" %s "%s create %s %s"' %
                       (base_config.NO_STRICT_CHECKING,
                        base_config.BASE_IP_ADDRESS,
                        VZCTL, vm_id, vm_create_args))
            logger.debug("BridgeVZAdapter: vm_create(): create command = %s" %
                         command)

            (ret_code, output) = execute_command(command)

            if ret_code == 0:
                return True
            else:
                return False

        except Exception, e:
            logger.error("Error creating VM: " + str(e))
            return False
Ejemplo n.º 40
0
 def start_vm_manager(self, vm_id):
     ovpl_dir_name = base_adapter.OVPL_DIR_PATH.split("/")[-1]
     vm_ovpl_path = base_config.VM_DEST_DIR + ovpl_dir_name
     start_vm_manager_command = ("python %s%s %s" %
                                 (vm_ovpl_path,
                                  base_config.VM_MANAGER_SERVER_PATH,
                                  ">>/root/vm.log 2>&1 </dev/null &"))
     command = (r"ssh -o '%s' %s%s '%s'" %
                (base_config.NO_STRICT_CHECKING,
                 "root@", IP_ADDRESS,
                 start_vm_manager_command))
     logger.debug("BridgeVZAdapter: start_vm_manager(): command = %s" %
                  command)
     try:
         (ret_code, output) = execute_command(command)
         return True
     except Exception, e:
         logger.error("BridgeVZAdapter: start_vm_manager(): command = %s, \
                      ERROR = %s" % (command, str(e)))
         return False