コード例 #1
0
ファイル: snapshot.py プロジェクト: hakusama1024/MacInstaller
    def __init__(self):
        prlsdkapi.init_desktop_sdk()
        self.server = prlsdkapi.Server()

        result = self.server.login_local('', 0,
                                         consts.PSL_NORMAL_SECURITY).wait()

        login_response = result.get_param()

        self.current_path = os.path.dirname(os.path.abspath(__file__))

        self.vmlist = []
        self.runningVm = []

        file_path = os.path.join(self.current_path + "/vmlist")
        if not os.path.exists(file_path):
            print("file path not exist", file_path)
            raise
        if not os.path.isfile(file_path):
            print("file not exist", file_path)
            raise

        with open("vmlist", "r") as f:
            for line in f:
                self.vmlist.append(line.strip())
コード例 #2
0
 def __init__(self):
     # initialize the desktop sdk & login to the Parallels local service
     prlsdkapi.init_desktop_sdk()
     self.server = prlsdkapi.Server()
     try:
         # The call returns a prlsdkapi.Result object on success.
         result = self.server.login_local('', 0, prlsdkapi.prlsdk.consts.PSL_NORMAL_SECURITY).wait()
         log.debug("Logged in to Parallels service")
     except prlsdkapi.PrlSDKError, e:
         sys.exit("Login error: %s" % e)
コード例 #3
0
	def __init__(self):
		
		self.current_path = os.getcwd()
		path = sys.argv[0]
		self.current_path = "/".join(path.split("/")[:-1]) + "/"

		self.vmlist = []
		self.runningVm = []
		self.log = []

		prlsdkapi.init_desktop_sdk()
		print(prlsdkapi.is_sdk_initialized())
		self.server = prlsdkapi.Server()

		result = self.server.login_local('', 0, consts.PSL_NORMAL_SECURITY).wait()

		login_response = result.get_param()

		product_version = login_response.get_product_version()
		print("product_version:", product_version)
		
		host_os_version = login_response.get_host_os_version()
		print("host_os_version:", host_os_version)
		
		host_uuid = login_response.get_server_uuid()
		print("host_uuid:", host_uuid)
		
		result = self.server.get_srv_config().wait()
		srv_config = result.get_param()

		file_path = os.path.join(self.current_path + "/vmlist")
		if not os.path.exists(file_path):
			print("file path not exist", file_path)
			raise
		if not os.path.isfile(file_path):
			print("file not exist", file_path)
			raise

		with open(file_path, "r") as f:
			for line in f:
				self.vmlist.append(line.strip())
コード例 #4
0
ファイル: synchosts.py プロジェクト: bitwalker/synchosts
def main(vmname, username, password):
    debug("Synchronizing host entries for {0} as {1}:{2}".format(vmname, username, password))
    # Init Parallels SDK lib
    prlsdkapi.init_desktop_sdk()
    # For Win/Linux, this script will take a little tweaking
    # but to start with, you'll need to uncomment the following
    # prlsdkapi.init_desktop_wl_sdk()

    # Create server object and login
    server = prlsdkapi.Server()
    login(server)

    debug("Logged in to Parallels.")

    # Find vm
    vm = get_vm(server, vmname)

    if vm:
        debug("Successfully fetched VM with name %s" % vmname)

        # Get guest object
        guest = get_guest(vm, username, password)

        # Get guest network info
        network_info = get_guest_netinfo(guest)

        debug("Acquired the following network information:", network_info)

        # Extract the guest IP address
        m = re.search("^([\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3})", network_info[0]["ip"])
        ip = m.group(0)

        debug("Selected %s as the new host IP address." % ip)

        # Update hosts file
        update_hosts(ip)

        # If flag is set, update dnsmasq.conf
        if UPDATE_DNSMASQ_ENTRIES:
            dnsmasq_found = False
            debug("Searching for dnsmasq.conf...")
            if path_exists("/etc/dnsmasq.conf"):
                debug("Found dnsmasq.conf in /etc")
                dnsmasq_found = True
                update_dnsmasq_conf("/etc/dnsmasq.conf", ip)
            if path_exists("/usr/local/etc/dnsmasq.conf"):
                debug("Found dnsmasq.conf in /usr/local/etc/dnsmasq.conf")
                dnsmasq_found = True
                update_dnsmasq_conf("/usr/local/etc/dnsmasq.conf", ip)
            if dnsmasq_found is False:
                debug("No dnsmasq.conf file found.")

        # Logoff of guest
        guest.logout()
        debug("Logged off of VM guest")
        print "Host file entries for *.local and local.* have been updated!"
        print "New address is: " + ip
    else:
        print "Could not find a VM by the name '%s'" % vmname

    server.logoff()
    prlsdkapi.deinit_sdk()
    debug("Successfully logged out of Parallels and unloaded SDK.")