Beispiel #1
0
 def destroyDevice(self, devid):
     try:
         DevController.destroyDevice(self, int(devid))
         time.sleep(5)
         t = xstransact()
         frontpath = self.frontendPath(int(devid))
         backpath = t.Read(frontpath, "backend")
         if backpath:
             t.Remove(backpath)
             log.debug('in try: removed %s' % backpath)
         t.Remove(frontpath)
         log.debug('in try: removed %s' % frontpath)
     except ValueError:
         devid_end = type(devid) is str and devid.split('/')[-1] or None
         for i in self.deviceIDs():
             d = self.readBackend(i, 'dev')
             if d == devid or (devid_end and d == devid_end):
                 DevController.destroyDevice(self, i)
                 time.sleep(5)
                 frontpath = self.frontendPath(int(devid))
                 backpath = t.Read(frontpath, "backend")
                 if backpath:
                     t.Remove(backpath)
                     log.debug('in err: removed %s' % backpath)
                 t.Remove(frontpath)
                 log.debug('in err: removed %s' % frontpath)
                 return
         raise VmError("Device %s not connected" % devid)
Beispiel #2
0
 def destroyDevice(self, devid):
     try:
         DevController.destroyDevice(self, int(devid))
         time.sleep(5)
         t = xstransact()
         frontpath = self.frontendPath(int(devid))
         backpath = t.Read(frontpath, "backend")
         if backpath:
             t.Remove(backpath)
             log.debug("in try: removed %s" % backpath)
         t.Remove(frontpath)
         log.debug("in try: removed %s" % frontpath)
     except ValueError:
         devid_end = type(devid) is str and devid.split("/")[-1] or None
         for i in self.deviceIDs():
             d = self.readBackend(i, "dev")
             if d == devid or (devid_end and d == devid_end):
                 DevController.destroyDevice(self, i)
                 time.sleep(5)
                 frontpath = self.frontendPath(int(devid))
                 backpath = t.Read(frontpath, "backend")
                 if backpath:
                     t.Remove(backpath)
                     log.debug("in err: removed %s" % backpath)
                 t.Remove(frontpath)
                 log.debug("in err: removed %s" % frontpath)
                 return
         raise VmError("Device %s not connected" % devid)
Beispiel #3
0
    def createDevice(self, config):
        """Trigger the creation of a device with the given configuration.

        @return The ID for the newly created device.
        """
        (devid, back, front) = self.getDeviceDetails(config)
        if devid is None:
            return 0

        (backpath, frontpath) = self.addStoreEntries(config, devid, back,
                                                     front)

        import xen.xend.XendDomain
        count = 0
        while True:
            t = xstransact()
            try:
                if devid in self.deviceIDs(t):
                    if 'dev' in back:
                        dev_str = '%s (%d, %s)' % (back['dev'], devid,
                                                   self.deviceClass)
                    else:
                        dev_str = '%s (%s)' % (devid, self.deviceClass)
                    
                    raise VmError("Device %s is already connected." % dev_str)

                if count == 0:
                    log.debug('DevController: writing %s to %s.', str(front),
                              frontpath)
                    log.debug('DevController: writing %s to %s.', str(back),
                              backpath)
                elif count % 50 == 0:
                    log.debug(
                      'DevController: still waiting to write device entries.')

                t.remove(frontpath)
                t.remove(backpath)

                t.mkdir(backpath)
                t.set_permissions(backpath,
                                  {'dom': xen.xend.XendDomain.PRIV_DOMAIN },
                                  {'dom'  : self.vm.getDomid(),
                                   'read' : True })

                t.write2(frontpath, front)
                t.write2(backpath,  back)

                if t.commit():
                    return devid

                count += 1
            except:
                t.abort()
                raise
Beispiel #4
0
    def createDevice(self, config):
        """Trigger the creation of a device with the given configuration.

        @return The ID for the newly created device.
        """
        (devid, back, front) = self.getDeviceDetails(config)
        if devid is None:
            return 0

        self.setupDevice(config)

        (backpath, frontpath) = self.addStoreEntries(config, devid, back,
                                                     front)

        import xen.xend.XendDomain
        xd = xen.xend.XendDomain.instance()
        backdom_name = config.get('backend')
        if backdom_name is None:
            backdom = xen.xend.XendDomain.DOM0_ID
        else:
            bd = xd.domain_lookup_nr(backdom_name)
            backdom = bd.getDomid()
        count = 0
        while True:
            t = xstransact()
            try:
                if devid in self.deviceIDs(t):
                    if 'dev' in back:
                        dev_str = '%s (%d, %s)' % (back['dev'], devid,
                                                   self.deviceClass)
                    else:
                        dev_str = '%s (%s)' % (devid, self.deviceClass)

                    raise VmError("Device %s is already connected." % dev_str)

                if count == 0:
                    log.debug('DevController: writing %s to %s.', str(front),
                              frontpath)
                    log.debug('DevController: writing %s to %s.',
                              str(xen.xend.XendConfig.scrub_password(back)),
                              backpath)
                elif count % 50 == 0:
                    log.debug(
                        'DevController: still waiting to write device entries.'
                    )

                devpath = self.devicePath(devid)

                t.remove(frontpath)
                t.remove(backpath)
                t.remove(devpath)

                t.mkdir(backpath)
                t.set_permissions(backpath, {'dom': backdom}, {
                    'dom': self.vm.getDomid(),
                    'read': True
                })
                t.mkdir(frontpath)
                t.set_permissions(frontpath, {'dom': self.vm.getDomid()}, {
                    'dom': backdom,
                    'read': True
                })

                t.write2(frontpath, front)
                t.write2(backpath, back)

                t.mkdir(devpath)
                t.write2(
                    devpath, {
                        'backend': backpath,
                        'backend-id': "%i" % backdom,
                        'frontend': frontpath,
                        'frontend-id': "%i" % self.vm.getDomid()
                    })

                if t.commit():
                    return devid

                count += 1
            except:
                t.abort()
                raise
    def createDevice(self, config):
        """Trigger the creation of a device with the given configuration.

        @return The ID for the newly created device.
        """
        (devid, back, front) = self.getDeviceDetails(config)
        if devid is None:
            return 0

        self.setupDevice(config)

        (backpath, frontpath) = self.addStoreEntries(config, devid, back,
                                                     front)

        import xen.xend.XendDomain
        xd = xen.xend.XendDomain.instance()
        backdom_name = config.get('backend')
        if backdom_name is None:
            backdom = xen.xend.XendDomain.DOM0_ID
        else:
            bd = xd.domain_lookup_nr(backdom_name)
            backdom = bd.getDomid()
        count = 0
        while True:
            t = xstransact()
            try:
                if devid in self.deviceIDs(t):
                    if 'dev' in back:
                        dev_str = '%s (%d, %s)' % (back['dev'], devid,
                                                   self.deviceClass)
                    else:
                        dev_str = '%s (%s)' % (devid, self.deviceClass)
                    
                    raise VmError("Device %s is already connected." % dev_str)

                if count == 0:
                    log.debug('DevController: writing %s to %s.',
                              str(front), frontpath)
                    log.debug('DevController: writing %s to %s.',
                              str(xen.xend.XendConfig.scrub_password(back)), backpath)
                elif count % 50 == 0:
                    log.debug(
                      'DevController: still waiting to write device entries.')

                devpath = self.devicePath(devid)

                t.remove(frontpath)
                t.remove(backpath)
                t.remove(devpath)

                t.mkdir(backpath)
                t.set_permissions(backpath,
                                  {'dom': backdom },
                                  {'dom'  : self.vm.getDomid(),
                                   'read' : True })
                t.mkdir(frontpath)
                t.set_permissions(frontpath,
                                  {'dom': self.vm.getDomid()},
                                  {'dom': backdom, 'read': True})

                t.write2(frontpath, front)
                t.write2(backpath,  back)

                t.mkdir(devpath)
                t.write2(devpath, {
                    'backend' : backpath,
                    'backend-id' : "%i" % backdom,
                    'frontend' : frontpath,
                    'frontend-id' : "%i" % self.vm.getDomid()
                })

                if t.commit():
                    return devid

                count += 1
            except:
                t.abort()
                raise