コード例 #1
0
    def cancel_and_clean_convert(self, req):
        def abort_block_job(conn, filters):
            with LibvirtConn(conn.libvirtURI, conn.saslUser, conn.saslPass, conn.sshPrivKey) as c:
                dom = c.lookupByUUIDString(cmd.srcVmUuid)
                if not dom:
                    logger.info('VM not found: {}'.format(cmd.srcVmUuid))
                    return

                xmlDesc = dom.XMLDesc(0)
                dxml = xmlobject.loads(xmlDesc)

                volumes = filter(lambda v: not skipVolume(filters, v.name), getVolumes(dom, dxml))

                for v in volumes:
                    info = dom.blockJobInfo(v.name, 0)
                    if info:
                        dom.blockJobAbort(v.name)

        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()
        abort_block_job(cmd.libvirtConn, buildFilterDict(cmd.volumeFilters))
        real_storage_path = getRealStoragePath(cmd.storagePath)
        clean_up_path = os.path.join(real_storage_path, cmd.srcVmUuid)
        linux.rm_dir_force(clean_up_path)

        return jsonobject.dumps(rsp)
コード例 #2
0
    def clean_convert(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()

        clean_up_path = os.path.join(cmd.storagePath, cmd.srcVmUuid)
        shell.run("pkill -9 -f '%s'" % clean_up_path)
        linux.rm_dir_force(clean_up_path)
        return jsonobject.dumps(rsp)
コード例 #3
0
    def clean_convert(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()

        clean_up_path = os.path.join(cmd.storagePath, cmd.srcVmUuid)
        shell.run("pkill -9 -f '%s'" % clean_up_path)
        linux.rm_dir_force(clean_up_path)
        return jsonobject.dumps(rsp)
コード例 #4
0
 def prepare_heartbeat_dir():
     heartbeat_dir = os.path.join(mount_path, "zs-heartbeat")
     if not mounted_by_zstack or linux.is_mounted(mount_path):
         if not os.path.exists(heartbeat_dir):
             os.makedirs(heartbeat_dir, 0755)
     else:
         if os.path.exists(heartbeat_dir):
             linux.rm_dir_force(heartbeat_dir)
     return heartbeat_dir
コード例 #5
0
    def clean(self, req):
        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()
        real_storage_path = getRealStoragePath(cmd.storagePath)
        if not cmd.srcVmUuid:
            cleanUpPath = real_storage_path
        else:
            cleanUpPath = os.path.join(real_storage_path, cmd.srcVmUuid)

        linux.rm_dir_force(cleanUpPath)
        return jsonobject.dumps(rsp)
コード例 #6
0
 def clean_iscsi_cache_configuration(path,iscsiServerIp,iscsiServerPort):
     #clean cache configuration file:/var/lib/iscsi/nodes/iqnxxx/ip,port
     results =  bash.bash_o(("ls %s/*/ | grep %s | grep %s" % (path, iscsiServerIp, iscsiServerPort))).strip().splitlines()
     if results is None or len(results) == 0:
         return
     for result in results:
         dpaths = bash.bash_o("dirname %s/*/%s" % (path, result)).strip().splitlines()
         if dpaths is None or len(dpaths) == 0:
             continue
         for dpath in dpaths:
             linux.rm_dir_force("%s/%s" % (dpath, result))
コード例 #7
0
 def clean_iscsi_cache_configuration(path, iscsiServerIp, iscsiServerPort):
     #clean cache configuration file:/var/lib/iscsi/nodes/iqnxxx/ip,port
     results = bash.bash_o(
         ("ls %s/*/ | grep %s | grep %s" %
          (path, iscsiServerIp, iscsiServerPort))).strip().splitlines()
     if results is None or len(results) == 0:
         return
     for result in results:
         dpaths = bash.bash_o("dirname %s/*/%s" %
                              (path, result)).strip().splitlines()
         if dpaths is None or len(dpaths) == 0:
             continue
         for dpath in dpaths:
             linux.rm_dir_force("%s/%s" % (dpath, result))
コード例 #8
0
        def build_nbdkit_with_adapted_vddk(cmd, rsp):
            logger.info("start build nbdkit with adapted vddk......")
            if os.path.exists(NBDKIT_BUILD_LIB_PATH):
                linux.rm_dir_force(NBDKIT_BUILD_LIB_PATH)

            f, wget_path_file = tempfile.mkstemp()
            with open(wget_path_file, 'w') as wpd:
                wpd.write("%s\n%s" % (cmd.adaptedVddkLibUrl, cmd.nbdkitUrl))

            # wget ndbkit and old vddk
            linux.mkdir(NBDKIT_BUILD_LIB_PATH)
            wget_cmd = 'cd {} && wget -c -i {} && tar zxf {} && tar zxf {};'.format(
                NBDKIT_BUILD_LIB_PATH, wget_path_file,
                cmd.nbdkitUrl.split("/")[-1], cmd.adaptedVddkLibUrl.split("/")[-1])

            if shell.run(wget_cmd) != 0:
                rsp.success = False
                rsp.error = "failed to download nbdkit and vddklib " \
                            "from management node to v2v conversion host"
                os.remove(wget_path_file)
                return jsonobject.dumps(rsp)

            logger.info("wget nbdkit and vddk lib from mn success")
            os.remove(wget_path_file)

            build_cmd = "cd {} && ./configure --with-vddk={} > {} 2>&1; " \
                        "make install >> {} 2>&1".format(get_dir_path_from_url(cmd.nbdkitUrl), get_dir_path_from_url(cmd.adaptedVddkLibUrl),
                                                         NBDKIT_BUILD_LOG_PATH, NBDKIT_BUILD_LOG_PATH)

            # persist nbdkit and vddk version
            linux.write_file(NBDKIT_VERSION_PATH, cmd.nbdkitUrl.split("/")[-1], True)
            linux.write_file(ADAPTED_VDDK_VERSION_PATH, cmd.adaptedVddkLibUrl.split("/")[-1], True)

            # build nbdkit
            if shell.run(build_cmd) != 0 or not self._ndbkit_is_work():
                rsp.success = False
                rsp.error = "failed to build nbdkit with vddk, log in conversion host: %s" % NBDKIT_BUILD_LOG_PATH
                return jsonobject.dumps(rsp)
コード例 #9
0
    def clean(self, req):
        def clean_dnat(dnatInfo):
            vmware_host_ip = linux.get_host_by_name(dnatInfo.hostName)
            dnat_interface = linux.find_route_interface_by_destination_ip(dnatInfo.convertIp)
            if vmware_host_ip != dnatInfo.convertIp:
                if shell.run("route -n |grep %s |grep %s" % (vmware_host_ip, dnat_interface)) == 0:
                    shell.run("route del -host %s dev %s" % (vmware_host_ip, dnat_interface))

                if shell.run("iptables -t nat -nL --line-number | grep DNAT |grep %s | grep %s" % (vmware_host_ip, dnatInfo.convertIp)) == 0:
                    nat_number = shell.call("iptables -t nat -nL --line-number | grep DNAT |grep %s | grep %s" % (vmware_host_ip, dnatInfo.convertIp)).split(" ")[0]
                    shell.run("iptables -D OUTPUT %s -t nat" % nat_number)

        cmd = jsonobject.loads(req[http.REQUEST_BODY])
        rsp = AgentRsp()
        if not cmd.srcVmUuid:
            cleanUpPath = cmd.storagePath
        else:
            cleanUpPath = os.path.join(cmd.storagePath, cmd.srcVmUuid)
            shell.run("pkill -9 -f '%s'" % cleanUpPath)
        if cmd.needCleanDnat:
            clean_dnat(cmd.dnatInfo)
        linux.rm_dir_force(cleanUpPath)
        return jsonobject.dumps(rsp)