VirtualBox

Changeset 21640 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jul 16, 2009 11:21:47 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50172
Message:

Python: WS Python bindings fully usable, extend shell to control remote VMs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r21384 r21640  
    379379    def __init__(self, params):
    380380        sys.path.append(VboxSdkDir+'/bindings/webservice/python/lib')
     381        # not really needed, but just fail early if misconfigured
    381382        import VirtualBox_services
    382383        import VirtualBox_wrappers
     
    390391            self.password = ""
    391392            self.url = None
     393        self.vbox = None       
     394
     395    def getSessionObject(self, vbox):       
     396        return self.wsmgr.getSessionObject(vbox)
     397
     398    def getVirtualBox(self):
     399        return connect(self.url, self.user, self.password)
     400
     401    def connect(self, url, user, passwd):
     402        if self.vbox is not None:
     403             disconnect()
     404        from VirtualBox_wrappers import IWebsessionManager2
     405        self.url = url
     406        if user is None:
     407            user = ""
     408        self.user = user
     409        if passwd is None:
     410            passwd = ""
     411        self.password = passwd
    392412        self.wsmgr = IWebsessionManager2(self.url)
    393 
    394     def getSessionObject(self, vbox):
    395         return self.wsmgr.getSessionObject(vbox)
    396 
    397     def getVirtualBox(self):
    398413        self.vbox = self.wsmgr.logon(self.user, self.password)
    399414        return self.vbox
     415
     416    def disconnect(self):
     417        if self.vbox is not None and self.wsmgr is not None:
     418                self.wsmgr.logoff(self.vbox)
     419                self.vbox = None
     420                self.wsmgr = None
    400421
    401422    def getConstants(self):
     
    426447    def deinit(self):
    427448        try:
    428             if self.vbox is not None:
    429                 self.wsmg.logoff(self.vbox)
    430                 self.vbox = None
     449           disconnect()
    431450        except:
    432             pass
     451           pass
    433452
    434453    def getPerfCollector(self, vbox):
     
    451470        try:
    452471            exec "self.platform = Platform"+style+"(platparams)"
    453             self.vbox = self.platform.getVirtualBox()
    454             self.mgr = SessionManager(self)
     472           
    455473            self.constants = VirtualBoxReflectionInfo()
    456474            self.type = self.platform.getType()
    457475            self.remote = self.platform.getRemote()
    458476            self.style = style           
     477
     478            self.mgr = SessionManager(self)
     479            self.vbox = self.platform.getVirtualBox()
    459480        except Exception,e:
    460481            print "init exception: ",e
    461482            traceback.print_exc()
    462             raise e
     483            if self.remote:
     484                self.vbox = None
     485            else:
     486                raise e
    463487
    464488    def getArray(self, obj, field):
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette