Ejemplo n.º 1
0
    def test_sampleLabelings(self):
        tree = Tree("(A:1,(B:1,(C:1,(E:1,D:1)Int_1:0.5[&&NHX:ancient=1])Int_2:0.5[&&NHX:ancient=0])Int_3:1)Root;", format=1)
        chrom = {}
        chrom["one"] = ["3","4"]
        species = {}
        species["C"] = chrom
        chrom = {}
        chrom["one"] = ["3","4"]
        species["D"] = chrom
        chrom = {}
        chrom["one"] = []
        species["E"] = chrom
        chrom = {}
        chrom["one"] = []
        species["A"] = chrom
        chrom = {}
        chrom["one"] = []
        species["B"] = chrom

        adj = getAdjacencies.findAdjacencies(species)
        paths = getAdjacencies.findTreePaths(tree)
        internal,adjacenciesAncestral = getAdjacencies.assignAncestralAdjacencies(paths,adj,tree)
        graphs = globalAdjacencyGraph.createGraph(adj,adjacenciesAncestral)
        jointLabels, first = SR.enumJointLabelings(graphs)
        probs={"Int_1":{(6, 7):0.1},"Int_2":{(6, 7):0.1},"Int_3":{(6, 7):0.1},"Root":{(6, 7):0.1}}
        for i in range(0,10):
            validLabels, validAtNode = SR.validLabels(jointLabels,first)
            resolvedCCs = SR.sampleLabelings(tree, graphs, validAtNode, adj,probs, alpha=0)
            reconstructedAdj = SR.reconstructedAdjacencies(resolvedCCs)
            print reconstructedAdj
Ejemplo n.º 2
0
    def __init__(self, key, opterr=None):
        # Check the XML definition file exists
        if not os.path.exists(XML_DEFS):
            print "No XML def file found"
            raise Exception.__init__(self, '')

        # Read the definition list
        self._fromxml('SM-errorcodes')

        ########DEBUG#######
        #for val in self.errorlist.keys():
        #    subdict = self.errorlist[val]
        #    print "KEY [%s]" % val
        #    for subval in subdict.keys():
        #        print "\tSUBKEY: %s, VALUE: %s" % (subval,subdict[subval])
        ########END#######

        # Now find the specific error
        if self.errorlist.has_key(key):
            subdict = self.errorlist[key]
            errorcode = int(subdict['value'])
            errormessage = subdict['description']
            if opterr is not None:
                errormessage += " [opterr=%s]" % opterr
            util.SMlog("Raising exception [%d, %s]" %
                       (errorcode, errormessage))
            raise SR.SROSError(errorcode, errormessage)

        # development error
        raise SR.SROSError(1, "Error reporting error, unknown key %s" % key)
Ejemplo n.º 3
0
 def test_enumJointLabelings(self):
     #print nx.maximal_matching(self.graph)
     #print nx.max_weight_matching(self.graph)
     joint,first = SR.enumJointLabelings([self.graph])
     TestCase.assertEqual(self,len(joint[self.graph]),15)
     valid, validAtNode = SR.validLabels(joint,first)
     TestCase.assertEqual(self,len(valid[self.graph]),8)
Ejemplo n.º 4
0
    def create(self, sr_uuid, size):
        if self.checkmount():
            raise SR.SROSError(113, 'GlusterFS mount point already attached')

        try:
            self.mount()
        except GlusterFSException, exc:
            # noinspection PyBroadException
            try:
                os.rmdir(self.mountpoint)
            except:
                # we have no recovery strategy
                pass
            raise SR.SROSError(111, "GlusterFS mount error [opterr=%s]" % exc.errstr)
Ejemplo n.º 5
0
 def endpointing(self, current):
     energy = 0.0
     # print current
     # print len(current)
     self.is_speech = False
     for i in range(len(current)):
         energy += pow(current[i], 2)
     energy = 10 * numpy.log(energy)
     # print self.threshold, self.level, self.background
     # print energy
     if self.index == 0:
         self.level = energy
     # threshold equals to max energy of first ten frames divide 4
     if self.index < 10 and self.index >= 0:
         if self.max_energy < energy:
             self.max_energy = energy
         self.background += energy
         if self.index == 9:
             self.background /= 10
             self.threshold = self.max_energy / 8
     if self.index >= 10:
         if energy < self.background:
             self.background = energy
         else:
             self.background += (energy - self.background) * self.adjustment
         self.level = (self.level * self.forget_factor +
                       energy) / (self.forget_factor + 1)
         if self.level < self.background:
             self.level = self.background
         if self.level - self.background > self.threshold:
             self.is_speech = True
         if self.is_speech != self.past_is_speech:
             if self.is_speech:
                 self.begin_index = self.index
                 # print "speech begin at %d\n" % self.begin_index
                 # print 'energy = %d\n' % energy
             else:
                 self.end_index = self.index
                 if not self.record_continuous and self.time_synchronous and self.end_index - self.begin_index > 8:
                     # if self.need_train:
                     #    self.need_train = 0
                     #    self.DTW_obj = SR.training_model(5, self.using_kmeans)[0]
                     SR.test(self.time_synchronous, 1, 5, self.using_kmeans,
                             self.begin_index, self.end_index, self.DTW_obj,
                             self.read_feature_from_file)
                     # print "speech end at %d\n" % self.end_index
                     # print 'energy = %d\n' % energy
         self.past_is_speech = self.is_speech
     self.index += 1
Ejemplo n.º 6
0
 def attach(self, sr_uuid):
     if not self.checkmount():
         try:
             self.mount()
             os.symlink(self.linkpath, self.path)
         except GlusterFSException, exc:
             raise SR.SROSError(12, exc.errstr)
Ejemplo n.º 7
0
    def create(self, sr_uuid, size):
        # Check whether an SR already exists
        SRs = self.session.xenapi.SR.get_all_records()
        for sr in SRs:
            record = SRs[sr]
            sm_config = record["sm_config"]
            if 'datatype' in sm_config and \
               sm_config['datatype'] == 'HBA' and \
               sm_config['hbatype'] == self.type:
                raise xs_errors.XenError('SRInUse')
        self._init_hbadict()
        if not self.attached:
            raise xs_errors.XenError('InvalidDev', \
                      opterr=('No such HBA Device detected [%s]') % self.type)

        if self._loadvdis() > 0:
            scanrecord = SR.ScanRecord(self)
            scanrecord.synchronise()
        try:
            self.detach(sr_uuid)
        except:
            pass
        self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref)
        self.sm_config['disktype'] = 'Raw'
        self.sm_config['datatype'] = 'HBA'
        self.sm_config['hbatype'] = self.type
        self.sm_config['multipathable'] = 'true'
        self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config)
Ejemplo n.º 8
0
 def create_SR(self, cmd, dconf, cmd_params=None):
     srcmd = mock.Mock()
     srcmd.dconf = dconf
     srcmd.params = {'command': cmd}
     if cmd_params:
         srcmd.params.update(cmd_params)
     return SR.SR(srcmd, "some SR UUID")
Ejemplo n.º 9
0
def _is_open(session, args):
    """Check if VDI <args["vdiUuid"]> is open by a tapdisk on this host"""
    import SRCommand, SR, NFSSR, EXTSR, LVHDSR, blktap2

    util.SMlog("on-slave.is_open: %s" % args)
    vdiUuid = args["vdiUuid"]
    srRef = args["srRef"]
    srRec = session.xenapi.SR.get_record(srRef)
    srType = srRec["type"]

    # FIXME: ugly hacks to create a VDI object without a real SRCommand to
    # avoid having to refactor the core files
    if srType.startswith("lvm"):
        srType = "lvhd"
    cmd = SRCommand.SRCommand(None)
    cmd.driver_info = {"capabilities": None}
    cmd.dconf = {"server": None, "device": "/HACK"}
    cmd.params = {"command": None}

    driver = SR.driver(srType)
    sr = driver(cmd, srRec["uuid"])
    vdi = sr.vdi(vdiUuid)
    tapdisk = blktap2.Tapdisk.find_by_path(vdi.path)
    util.SMlog("Tapdisk for %s: %s" % (vdi.path, tapdisk))
    if tapdisk:
        return "True"
    return "False"
Ejemplo n.º 10
0
    def scan(self, sr_uuid):
        """
        This function is almost a copy of its base class equivalent.
        Main differences are:
        - Fixed erroneous size calculation
        - Set VDI names automatically
        - Avoid ScanRecord sync for missing VDIS (stale LUNs)

        The last one is called in the sub-sub class so we cannot simply
        extend the base class funcion but we need to override it
        """

        self._init_hbadict()
        if not self.passthrough:
            if not self.attached:
                raise xs_errors.XenError('SRUnavailable')

            self._loadvdis()

        # This block is almost SR.scan but without missing sync
        self._db_update()
        scanrecord = SR.ScanRecord(self)
        scanrecord.synchronise_new()
        scanrecord.synchronise_existing()

        # Fixing sizes calculation
        phys_util = 0
        for key in self.vdis:
            vdi_ref = self.session.xenapi.VDI.get_by_uuid(key)
            if B_util.is_vdi_attached(self.session, vdi_ref):
                phys_util += self.vdis[key].size
        self._set_stats(phys_util=phys_util)

        self._set_vdis_name()
Ejemplo n.º 11
0
    def run(self):
        global goal_pos, servo_command, init_get, functionMode
        while self.__running.isSet():
            self.__flag.wait()
            if SR_mode:
                voice_command = SR.run()
                if voice_command == 'forward':
                    SpiderG.walk('forward')
                    time.sleep(2)
                    SpiderG.servoStop()

                elif voice_command == 'backward':
                    SpiderG.walk('backward')
                    time.sleep(2)
                    SpiderG.servoStop()

                elif voice_command == 'left':
                    SpiderG.walk('turnleft')
                    time.sleep(5)
                    SpiderG.servoStop()

                elif voice_command == 'right':
                    SpiderG.walk('turnright')
                    time.sleep(5)
                    SpiderG.servoStop()

                elif voice_command == 'stop':
                    SpiderG.servoStop()
            else:
                self.pause()
Ejemplo n.º 12
0
    def create(self, sr_uuid, size):
        # Check whether an SR already exists
        SRs = self.session.xenapi.SR.get_all_records()
        for sr in SRs:
            record = SRs[sr]
            sm_config = record["sm_config"]
            if 'targetIQN' in sm_config and \
               sm_config['targetIQN'] == self.targetIQN:
                raise xs_errors.XenError('SRInUse')
        self.attach(sr_uuid)
        # Wait up to MAX_TIMEOUT for devices to appear
        util.wait_for_path(self.path, MAX_TIMEOUT)

        if self._loadvdis() > 0:
            scanrecord = SR.ScanRecord(self)
            scanrecord.synchronise()
        try:
            self.detach(sr_uuid)
        except:
            pass
        self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref)
        self.sm_config['disktype'] = 'Raw'
        self.sm_config['datatype'] = 'ISCSI'
        self.sm_config['target'] = self.target
        self.sm_config['targetIQN'] = self.targetIQN
        self.sm_config['multipathable'] = 'true'
        self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config)
        return
Ejemplo n.º 13
0
 def endpointing(self, current):
     energy = 0.0
     # print current
     # print len(current)
     self.is_speech = False
     for i in range(len(current)):
         energy += pow(current[i], 2)
     energy = 10 * numpy.log(energy)
     # print self.threshold, self.level, self.background
     # print energy
     if self.index == 0:
         self.level = energy
     # threshold equals to max energy of first ten frames divide 4
     if self.index < 10 and self.index >= 0:
         if self.max_energy < energy:
             self.max_energy = energy
         self.background += energy
         if self.index == 9:
             self.background /= 10
             self.threshold = self.max_energy / 4
     if self.index >= 10:
         if energy < self.background:
             self.background = energy
         else:
             self.background += (energy - self.background) * self.adjustment
         self.level = (self.level * self.forget_factor + energy) / (self.forget_factor + 1)
         if self.level < self.background:
             self.level = self.background
         if self.level - self.background > self.threshold:
             self.is_speech = True
         if self.is_speech != self.past_is_speech:
             if self.is_speech:
                 self.begin_index = self.index
                 # print "speech begin at %d\n" % self.begin_index
                 # print 'energy = %d\n' % energy
             else:
                 self.end_index = self.index
                 if self.time_synchronous and self.end_index - self.begin_index > 8:
                     # if self.need_train:
                     #    self.need_train = 0
                     #    self.DTW_obj = SR.training_model(5, self.using_kmeans)[0]
                     SR.test(self.time_synchronous, 1, 5, self.using_kmeans, self.begin_index,
                             self.end_index, self.DTW_obj, self.read_feature_from_file)
                     # print "speech end at %d\n" % self.end_index
                     # print 'energy = %d\n' % energy
         self.past_is_speech = self.is_speech
     self.index += 1
Ejemplo n.º 14
0
def main():
    pc = PCC.PrintControl(printid, portname, baudrate, tem_position)
    pc.printor_alive()
    fr = FR.FileReceiver()
    sr = SR.StatueReportor()
    ss = threading.Thread(target=state_send_thread, args=(pc, sr))
    gft = threading.Thread(target=get_file_thread, args=(pc, fr))
    ss.start()
    gft.start()
    ss.join()
    gft.join()
Ejemplo n.º 15
0
    def load(self, sr_uuid):
        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # User must specify a LUN ID(s) for adding to the VG
        if not self.dconf.has_key('LUNid') or not self.dconf['LUNid']:
            raise xs_errors.XenError('ConfigLUNIDMissing')
        self.dconf['device'] = os.path.join(self.iscsi.path,"LUN%s" % \
                               self.dconf['LUNid'])

        if not self.iscsi.attached:
            # Must attach SR here in order to load VG
            self.iscsi.attach(sr_uuid)
        super(EXToISCSISR, self).load(sr_uuid)
Ejemplo n.º 16
0
 def delete(self, sr_uuid):
     # try to remove/delete non VDI contents first
     super(GlusterFSSR, self).delete(sr_uuid)
     try:
         if self.checkmount():
             self.detach(sr_uuid)
         self.mount()
         if util.ioretry(lambda: util.pathexists(self.linkpath)):
             util.ioretry(lambda: os.rmdir(self.linkpath))
         self.unmount(self.mountpoint, True)
     except util.CommandException, inst:
         self.detach(sr_uuid)
         if inst.code != errno.ENOENT:
             raise SR.SROSError(114, "Failed to remove GlusterFS mount point")
Ejemplo n.º 17
0
    def load(self, sr_uuid):
        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # User must specify a LUN ID(s) for adding to the VG
        if not self.dconf.has_key('LUNid') or  not self.dconf['LUNid']:
            raise xs_errors.XenError('ConfigLUNIDMissing')
        self.dconf['device'] = os.path.join(self.iscsi.path,"LUN%s" % \
                               self.dconf['LUNid'])

        if not self.iscsi.attached:
            # Must attach SR here in order to load VG
            self.iscsi.attach(sr_uuid)
        super(EXToISCSISR, self).load(sr_uuid)
Ejemplo n.º 18
0
    def scan(self, sr_uuid):
        util.SMlog("RBDSR.load: sr_uuid=%s" % sr_uuid)
        cephutils.SR.scan(self, sr_uuid)

        self.physical_size = self.RBDPOOLs[sr_uuid]['stats'][
            'max_avail'] + self.RBDPOOLs[sr_uuid]['stats']['bytes_used']
        self.physical_utilisation = self.RBDPOOLs[sr_uuid]['stats'][
            'bytes_used']

        self.virtual_allocation = self._get_allocated_size()
        self._loadvdis()
        self._db_update()
        scanrecord = SR.ScanRecord(self)
        scanrecord.synchronise_existing()
        scanrecord.synchronise_new()
Ejemplo n.º 19
0
    def test_attach_nfs_no_server(self, _checkmount, testHost, makedirs,
                                  validate_nfsversion, convertDNS, gen_uuid):

        isosr = self.create_isosr(location='aServer:/aLocation',
                                  atype='nfs_iso',
                                  sr_uuid='asr_uuid')

        _checkmount.side_effect = [False]
        testHost.side_effect = SR.SROSError(
            140, 'Incorrect DNS name, unable to resolve.')

        with self.assertRaises(SR.SROSError) as ose:
            isosr.attach(None)

        self.assertEqual(140, ose.exception.errno)
Ejemplo n.º 20
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >>sys.stderr,self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(OCFSoHBASR)
        super(OCFSoHBASR, self).load(sr_uuid)
Ejemplo n.º 21
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if 'SCSIid' not in self.dconf or not self.dconf['SCSIid']:
            print(self.hbasr.print_devs(), file=sys.stderr)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(OCFSoHBASR, load = False)
        super(OCFSoHBASR, self).load(sr_uuid)
Ejemplo n.º 22
0
class SR_ctrl(threading.Thread):
	def __init__(self, *args, **kwargs):
		super(SR_ctrl, self).__init__(*args, **kwargs)
		self.__flag = threading.Event()
		self.__flag.set()
		self.__running = threading.Event()
		self.__running.set()

	def run(self):
		global goal_pos, servo_command, init_get, functionMode
		while self.__running.isSet():
			self.__flag.wait()
			if SR_mode:

        voice_command = SR.run()
				if voice_command == 'forward':
					turn.turnMiddle()
					move.move(speed_set, 'forward')
					time.sleep(1)
					move.motorStop()

				elif voice_command == 'backward':
					turn.turnMiddle()
					move.move(speed_set, 'backward')
					time.sleep(1)
					move.motorStop()

				elif voice_command == 'left':
					servo.turnLeft()
					move.move(speed_set, 'forward')
					time.sleep(1)
					turn.turnMiddle()
					move.motorStop()

				elif voice_command == 'right':
					servo.turnRight()
					move.move(speed_set, 'forward')
					time.sleep(1)
					turn.turnMiddle()
					move.motorStop()

				elif voice_command == 'stop':
					turn.turnMiddle()
					move.motorStop()
Ejemplo n.º 23
0
    def scan(self, sr_uuid):
        if not self.isMaster:
            util.SMlog('sr_scan blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        self._loadbuffer()
        self._loadvdis()
        stats = lvutil._getVGstats(self.vgname)
        self.physical_size = stats['physical_size']
        self.physical_utilisation = stats['physical_utilisation']
        self.virtual_allocation = self.physical_utilisation
        # Update the SR record
        self._db_update()
        # Synchronise the VDIs
        scanrecord = SR.ScanRecord(self)
        # XXX: never forget VDI records to work around glitch where some
        # volumes temporarily disappeared
        scanrecord.synchronise_new()
        scanrecord.synchronise_existing()
Ejemplo n.º 24
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if 'SCSIid' not in self.dconf or not self.dconf['SCSIid']:
            print(self.hbasr.print_devs(), file=sys.stderr)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 25
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        # If this is a vdi command, don't initialise SR
        if not (util.isVDICommand(self.original_srcmd.cmd)):
            pbd = None
            try:
                pbd = util.find_my_pbd(self.session, self.host_ref,
                                       self.sr_ref)
            except:
                pass

            try:
                if not self.dconf.has_key('SCSIid') and self.dconf.has_key(
                        'device'):
                    # UPGRADE FROM MIAMI: add SCSIid key to device_config
                    util.SMlog("Performing upgrade from Miami")
                    if not os.path.exists(self.dconf['device']):
                        raise xs_errors.XenError('InvalidDev')
                    SCSIid = scsiutil.getSCSIid(self.dconf['device'])
                    self.dconf['SCSIid'] = SCSIid
                    del self.dconf['device']

                    if pbd <> None:
                        device_config = self.session.xenapi.PBD.get_device_config(
                            pbd)
                        device_config['SCSIid'] = SCSIid
                        device_config['upgraded_from_miami'] = 'true'
                        del device_config['device']
                        self.session.xenapi.PBD.set_device_config(
                            pbd, device_config)
            except:
                pass

            if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
                print >> sys.stderr, self.hbasr.print_devs()
                raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoHBASR, load=False)
        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 26
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >> sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoFCoESR, load=False)
        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 27
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >>sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoFCoESR)
        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 28
0
    def test_after_master_attach_vdi_not_available(
            self, mock_log, mock_scan, mock_xenapi):
        """
        Test that after_master_attach calls scan
        """
        mock_session = mock.MagicMock(name='MockXapiSession')
        mock_xenapi.xapi_local.return_value = mock_session
        sr1 = self.create_SR("sr_create", {'ISCSIid': '12333423'},
            {'session_ref': 'session1'})

        mock_scan.side_effect = SR.SROSError(46, "The VDI is not available")

        sr1.after_master_attach('dummy uuid')

        mock_scan.assert_called_once_with(sr1, 'dummy uuid')

        self.assertEquals(1, mock_log.call_count)
        self.assertIn("Error in SR.after_master_attach",
                      mock_log.call_args[0][0])
        mock_session.xenapi.message.create.assert_called_once_with(
            "POST_ATTACH_SCAN_FAILED", 2, 'SR', 'dummy uuid', mock.ANY)
Ejemplo n.º 29
0
    def load(self, sr_uuid):
        if not sr_uuid:
            # This is a probe call, generate a temp sr_uuid
            sr_uuid = util.gen_uuid()

        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # Be extremely careful not to throw exceptions here since this function
        # is the main one used by all operations including probing and creating
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') and self.dconf.has_key(
                'LUNid') and pbd <> None:
            # UPGRADE FROM RIO: add SCSIid key to device_config
            util.SMlog("Performing upgrade from Rio")
            scsiid = self._getSCSIid_from_LUN(sr_uuid)

            device_config = self.session.xenapi.PBD.get_device_config(pbd)
            device_config['SCSIid'] = scsiid
            device_config['upgraded_from_rio'] = 'true'
            self.session.xenapi.PBD.set_device_config(pbd, device_config)

            self.dconf['SCSIid'] = scsiid

        # Apart from the upgrade case, user must specify a SCSIid
        if not self.dconf.has_key('SCSIid'):
            self._LUNprint(sr_uuid)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVMoISCSISR)

        super(LVMoISCSISR, self).load(sr_uuid)
Ejemplo n.º 30
0
    def load(self, sr_uuid):
        driver = SR.driver('hba')
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        # If this is a vdi command, don't initialise SR
        if not (util.isVDICommand(self.original_srcmd.cmd)):
            pbd = None
            try:
                pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
            except:
                pass

            try:
                if not self.dconf.has_key('SCSIid') and self.dconf.has_key('device'):
                    # UPGRADE FROM MIAMI: add SCSIid key to device_config
                    util.SMlog("Performing upgrade from Miami")
                    if not os.path.exists(self.dconf['device']):
                        raise xs_errors.XenError('InvalidDev')
                    SCSIid = scsiutil.getSCSIid(self.dconf['device'])
                    self.dconf['SCSIid'] = SCSIid
                    del self.dconf['device']

                    if pbd <> None:
                        device_config = self.session.xenapi.PBD.get_device_config(pbd)
                        device_config['SCSIid'] = SCSIid
                        device_config['upgraded_from_miami'] = 'true'
                        del device_config['device']
                        self.session.xenapi.PBD.set_device_config(pbd, device_config)
            except:
                pass

            if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
                print >>sys.stderr,self.hbasr.print_devs()
                raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoHBASR, load = False)
        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 31
0
    def load(self, sr_uuid):
        if not sr_uuid:
            # This is a probe call, generate a temp sr_uuid
            sr_uuid = util.gen_uuid()

        driver = SR.driver('iscsi')
        self.iscsi = driver(self.original_srcmd, sr_uuid)

        # Be extremely careful not to throw exceptions here since this function
        # is the main one used by all operations including probing and creating
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass
        
        if not self.dconf.has_key('SCSIid') and self.dconf.has_key('LUNid') and pbd <> None:
            # UPGRADE FROM RIO: add SCSIid key to device_config
            util.SMlog("Performing upgrade from Rio")
            scsiid = self._getSCSIid_from_LUN(sr_uuid)
            
            device_config = self.session.xenapi.PBD.get_device_config(pbd)
            device_config['SCSIid'] = scsiid
            device_config['upgraded_from_rio'] = 'true'
            self.session.xenapi.PBD.set_device_config(pbd, device_config)

            self.dconf['SCSIid'] = scsiid            

        # Apart from the upgrade case, user must specify a SCSIid
        if not self.dconf.has_key('SCSIid'):
            self._LUNprint(sr_uuid)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVMoISCSISR)

        super(LVMoISCSISR, self).load(sr_uuid)
Ejemplo n.º 32
0
    def run(self):
        global goal_pos, servo_command, init_get, functionMode
        while self.__running.isSet():
            self.__flag.wait()
            if SR_mode:
                voice_command = SR.run()
                if voice_command == 'forward':
                    turn.turnMiddle()
                    move.move(speed_set, 'forward')
                    time.sleep(1)
                    move.motorStop()

                elif voice_command == 'backward':
                    turn.turnMiddle()
                    move.move(speed_set, 'backward')
                    time.sleep(1)
                    move.motorStop()

                elif voice_command == 'left':
                    servo.turnLeft()
                    move.move(speed_set, 'forward')
                    time.sleep(1)
                    turn.turnMiddle()
                    move.motorStop()

                elif voice_command == 'right':
                    servo.turnRight()
                    move.move(speed_set, 'forward')
                    time.sleep(1)
                    turn.turnMiddle()
                    move.motorStop()

                elif voice_command == 'stop':
                    turn.turnMiddle()
                    move.motorStop()
            else:
                self.pause()
Ejemplo n.º 33
0
    def load(self, sr_uuid):
        driver = SR.driver("hba")
        self.hbasr = driver(self.original_srcmd, sr_uuid)

        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        try:
            if not self.dconf.has_key("SCSIid") and self.dconf.has_key("device"):
                # UPGRADE FROM MIAMI: add SCSIid key to device_config
                util.SMlog("Performing upgrade from Miami")
                if not os.path.exists(self.dconf["device"]):
                    raise
                SCSIid = scsiutil.getSCSIid(self.dconf["device"])
                self.dconf["SCSIid"] = SCSIid
                del self.dconf["device"]

                if pbd <> None:
                    device_config = self.session.xenapi.PBD.get_device_config(pbd)
                    device_config["SCSIid"] = SCSIid
                    device_config["upgraded_from_miami"] = "true"
                    del device_config["device"]
                    self.session.xenapi.PBD.set_device_config(pbd, device_config)
        except:
            pass

        if not self.dconf.has_key("SCSIid") or not self.dconf["SCSIid"]:
            print >>sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError("ConfigSCSIid")

        self.SCSIid = self.dconf["SCSIid"]
        self._pathrefresh(LVMoHBASR)
        super(LVMoHBASR, self).load(sr_uuid)
Ejemplo n.º 34
0
def main():
    command = SRCommand.SRCommand()
    command.parse("")

    if not command.type:
        raise SRCommand.SRInvalidArgumentException( \
                                'missing driver type argument: -t <type>')
    if not command.dconf:
        raise SRCommand.SRInvalidArgumentException('missing dconf string')
    if not command.cmdname:
        raise SRCommand.SRInvalidArgumentException('missing command')
    if not command.sr_uuid:
        raise SRCommand.SRInvalidArgumentException('missing SR UUID')
    if command.cmdtype == 'vdi' and not command.vdi_uuid:
        raise SRCommand.SRInvalidArgumentException('missing VDI UUID')
    if not command.cmd:
        raise SRCommand.SRInvalidArgumentException('unknown command')
    if command.args is None:
        raise SRCommand.SRInvalidArgumentException('wrong number of arguments')

    driver = SR.driver(command.type)
    sr = driver(command.dconf, command.sr_uuid)

    command.run(sr)
Ejemplo n.º 35
0
    def load(self, sr_uuid):
        if not sr_uuid:
            # This is a probe call, generate a temp sr_uuid
            sr_uuid = util.gen_uuid()

        driver = SR.driver('iscsi')
        if self.original_srcmd.dconf.has_key('target'):
            self.original_srcmd.dconf['targetlist'] = self.original_srcmd.dconf['target']
        iscsi = driver(self.original_srcmd, sr_uuid)
        self.iscsiSRs = []
        self.iscsiSRs.append(iscsi)
        
        if self.dconf['target'].find(',') == 0 or self.dconf['targetIQN'] == "*":
            # Instantiate multiple sessions
            self.iscsiSRs = []
            if self.dconf['targetIQN'] == "*":
                IQN = "any"
            else:
                IQN = self.dconf['targetIQN']
            dict = {}
            IQNstring = ""
            IQNs = []
            try:
                if self.dconf.has_key('multiSession'):
                    IQNs = self.dconf['multiSession'].split("|")
                    for IQN in IQNs:
                        if IQN:
                            dict[IQN] = ""
                        else:
                            try:
                                IQNs.remove(IQN)
                            except:
                                # Exceptions are not expected but just in case
                                pass
                    # Order in multiSession must be preserved. It is important for dual-controllers.
                    # IQNstring cannot be built with a dictionary iteration because of this
                    IQNstring = self.dconf['multiSession']
                else:
                    for tgt in self.dconf['target'].split(','):
                        try:
                            tgt_ip = util._convertDNS(tgt)
                        except:
                            raise xs_errors.XenError('DNSError')
                        iscsilib.ensure_daemon_running_ok(iscsi.localIQN)
                        map = iscsilib.discovery(tgt_ip,iscsi.port,iscsi.chapuser,iscsi.chappassword,targetIQN=IQN)
                        util.SMlog("Discovery for IP %s returned %s" % (tgt,map))
                        for i in range(0,len(map)):
                            (portal,tpgt,iqn) = map[i]
                            (ipaddr, port) = iscsilib.parse_IP_port(portal)
                            try:
                                util._testHost(ipaddr, long(port), 'ISCSITarget')
                            except:
                                util.SMlog("Target Not reachable: (%s:%s)" % (ipaddr, port))
                                continue
                            key = "%s,%s,%s" % (ipaddr,port,iqn)
                            dict[key] = ""
                # Again, do not mess up with IQNs order. Dual controllers will benefit from that
                if IQNstring == "":
                    # Compose the IQNstring first
                    for key in dict.iterkeys(): IQNstring += "%s|" % key
                    # Reinitialize and store iterator
                    key_iterator = dict.iterkeys()
                else:
                    key_iterator = IQNs

                # Now load the individual iSCSI base classes
                for key in key_iterator:
                    (ipaddr,port,iqn) = key.split(',')
                    srcmd_copy = copy.deepcopy(self.original_srcmd)
                    srcmd_copy.dconf['target'] = ipaddr
                    srcmd_copy.dconf['targetIQN'] = iqn
                    srcmd_copy.dconf['multiSession'] = IQNstring
                    util.SMlog("Setting targetlist: %s" % srcmd_copy.dconf['targetlist'])
                    self.iscsiSRs.append(driver(srcmd_copy, sr_uuid))
                pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
                if pbd <> None and not self.dconf.has_key('multiSession'):
                    dconf = self.session.xenapi.PBD.get_device_config(pbd)
                    dconf['multiSession'] = IQNstring
                    self.session.xenapi.PBD.set_device_config(pbd, dconf)
            except:
                util.logException("LVHDoISCSISR.load")
        self.iscsi = self.iscsiSRs[0]

        # Be extremely careful not to throw exceptions here since this function
        # is the main one used by all operations including probing and creating
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        # Apart from the upgrade case, user must specify a SCSIid
        if not self.dconf.has_key('SCSIid'):
            # Dual controller issue
            self.LUNs = {}  # Dict for LUNs from all the iscsi objects
            for ii in range(0, len(self.iscsiSRs)):
                self.iscsi = self.iscsiSRs[ii]
                self._LUNprint(sr_uuid)
                for key in self.iscsi.LUNs:
                    self.LUNs[key] = self.iscsi.LUNs[key]
            self.print_LUNs_XML()
            self.iscsi = self.iscsiSRs[0] # back to original value
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']

        # This block checks if the first iscsi target contains the right SCSIid.
        # If not it scans the other iscsi targets because chances are that more
        # than one controller is present
        dev_match = False
        forced_login = False
        # No need to check if only one iscsi target is present
        if len(self.iscsiSRs) == 1:
            pass
        else:
            target_success = False
            attempt_discovery = False
            for iii in range(0, len(self.iscsiSRs)):
                # Check we didn't leave any iscsi session open
                # If exceptions happened before, the cleanup function has worked on the right target.
                if forced_login == True:
                    try:
                        iscsilib.ensure_daemon_running_ok(self.iscsi.localIQN)
                        iscsilib.logout(self.iscsi.target, self.iscsi.targetIQN)
                        forced_login = False
                    except:
                        raise xs_errors.XenError('ISCSILogout')
                self.iscsi = self.iscsiSRs[iii]
                util.SMlog("path %s" %self.iscsi.path)
                util.SMlog("iscsci data: targetIQN %s, portal %s" % (self.iscsi.targetIQN, self.iscsi.target))
                iscsilib.ensure_daemon_running_ok(self.iscsi.localIQN)
                if not iscsilib._checkTGT(self.iscsi.targetIQN):
                    attempt_discovery = True
                    try:
                        # Ensure iscsi db has been populated
                        map = iscsilib.discovery(
                                  self.iscsi.target,
                                  self.iscsi.port,
                                  self.iscsi.chapuser,
                                  self.iscsi.chappassword,
                                  targetIQN=self.iscsi.targetIQN)
                        if len(map) == 0:
                            util.SMlog("Discovery for iscsi data targetIQN %s,"
                                       " portal %s returned empty list"
                                       " Trying another path if available" %
                                       (self.iscsi.targetIQN,
                                        self.iscsi.target))
                            continue
                    except:
                        util.SMlog("Discovery failed for iscsi data targetIQN"
                                   " %s, portal %s. Trying another path if"
                                   " available" %
                                   (self.iscsi.targetIQN, self.iscsi.target))
                        continue
                    try:
                        iscsilib.login(self.iscsi.target,
                                       self.iscsi.targetIQN,
                                       self.iscsi.chapuser,
                                       self.iscsi.chappassword,
                                       self.iscsi.incoming_chapuser,
                                       self.iscsi.incoming_chappassword,
                                       self.mpath == "true")
                    except:
                        util.SMlog("Login failed for iscsi data targetIQN %s,"
                                   " portal %s. Trying another path"
                                   " if available" %
                                   (self.iscsi.targetIQN, self.iscsi.target))
                        continue
                    target_success = True;
                    forced_login = True
                # A session should be active.
                if not util.wait_for_path(self.iscsi.path, ISCSISR.MAX_TIMEOUT):
                    util.SMlog("%s has no associated LUNs" % self.iscsi.targetIQN)
                    continue
                scsiid_path = "/dev/disk/by-id/scsi-" + self.SCSIid
                if not util.wait_for_path(scsiid_path, ISCSISR.MAX_TIMEOUT):
                    util.SMlog("%s not found" %scsiid_path)
                    continue
                for file in filter(self.iscsi.match_lun, util.listdir(self.iscsi.path)):
                    lun_path = os.path.join(self.iscsi.path,file)
                    lun_dev = scsiutil.getdev(lun_path)
                    try:
                        lun_scsiid = scsiutil.getSCSIid(lun_dev)
                    except:
                        util.SMlog("getSCSIid failed on %s in iscsi %s: LUN"
                                   " offline or iscsi path down" %
                                    (lun_dev, self.iscsi.path))
                        continue
                    util.SMlog("dev from lun %s %s" %(lun_dev, lun_scsiid))
                    if lun_scsiid == self.SCSIid:
                        util.SMlog("lun match in %s" %self.iscsi.path)
                        dev_match = True
                        # No more need to raise ISCSITarget exception.
                        # Resetting attempt_discovery
                        attempt_discovery = False
                        break
                if dev_match:
                    if iii == 0:
                        break
                    util.SMlog("IQN reordering needed")
                    new_iscsiSRs = []
                    IQNs = {}
                    IQNstring = ""
                    # iscsiSRs can be seen as a circular buffer: the head now is the matching one
                    for kkk in range(iii, len(self.iscsiSRs)) + range(0, iii):
                        new_iscsiSRs.append(self.iscsiSRs[kkk])
                        ipaddr = self.iscsiSRs[kkk].target
                        port = self.iscsiSRs[kkk].port
                        iqn = self.iscsiSRs[kkk].targetIQN
                        key = "%s,%s,%s" % (ipaddr,port,iqn)
                        # The final string must preserve the order without repetition
                        if not IQNs.has_key(key):
                            IQNs[key] = ""
                            IQNstring += "%s|" % key
                    util.SMlog("IQNstring is now %s" %IQNstring)
                    self.iscsiSRs = new_iscsiSRs
                    util.SMlog("iqn %s is leading now" %self.iscsiSRs[0].targetIQN)
                    # Updating pbd entry, if any
                    try:
                        pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
                        if pbd <> None and self.dconf.has_key('multiSession'):
                            util.SMlog("Updating multiSession in PBD")
                            dconf = self.session.xenapi.PBD.get_device_config(pbd)
                            dconf['multiSession'] = IQNstring
                            self.session.xenapi.PBD.set_device_config(pbd, dconf)
                    except:
                        pass
                    break
            if not target_success and attempt_discovery:
                raise xs_errors.XenError('ISCSITarget')

            # Check for any unneeded open iscsi sessions
            if forced_login == True:
                try:
                    iscsilib.ensure_daemon_running_ok(self.iscsi.localIQN)
                    iscsilib.logout(self.iscsi.target, self.iscsi.targetIQN)
                    forced_login = False
                except:
                    raise xs_errors.XenError('ISCSILogout')

        self._pathrefresh(LVHDoISCSISR, load = False)

        LVHDSR.LVHDSR.load(self, sr_uuid)
Ejemplo n.º 36
0
            raise xs_errors.XenError('VDIUnavailable')
        resp = {}
        resp['device_config'] = self.sr.dconf
        resp['sr_uuid'] = sr_uuid
        resp['vdi_uuid'] = vdi_uuid
        resp['sr_sm_config'] = self.sr.sm_config
        resp['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config, ), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        """Used for HA State-file only. Will not just attach the VDI but
        also start a tapdisk on the file"""
        util.SMlog("SMBFileVDI.attach_from_config")
        try:
            if not util.pathexists(self.sr.path):
                self.sr.attach(sr_uuid)
        except:
            util.logException("SMBFileVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach from config')


if __name__ == '__main__':
    SRCommand.run(SMBSR, DRIVER_INFO)
else:
    SR.registerSR(SMBSR)
#
Ejemplo n.º 37
0
Archivo: FileSR.py Proyecto: falaa/sm
        resp['device_config'] = self.sr.dconf
        resp['sr_uuid'] = sr_uuid
        resp['vdi_uuid'] = vdi_uuid
        resp['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        """
        Attach and activate a VDI using config generated by
        vdi_generate_config above. This is used for cases such as
        the HA state-file and the redo-log.
        """
        util.SMlog("FileVDI.attach_from_config")
        try:
            if not util.pathexists(self.sr.path):
                self.sr.attach(sr_uuid)
        except:
            util.logException("FileVDI.attach_from_config")
            raise xs_errors.XenError(
                'SRUnavailable',
                opterr='Unable to attach from config'
            )

if __name__ == '__main__':
    SRCommand.run(FileSR, DRIVER_INFO)
else:
    SR.registerSR(FileSR)
def train_continuous_model(input_list, continuous_words, number_of_states_for_each_word=5):
    number_of_frames_in_each_state_for_each_template = []
    number_of_words = len(continuous_words) + 2  # 2为首尾的silence
    number_of_states = number_of_states_for_each_word * (number_of_words)
    number_of_frames_in_each_state = []  # 第i个元素代表state i的frame数
    template = []
    covariance_matrix_in_each_state = []
    mean_in_each_state = []
    for i in xrange(number_of_words):
        if i == 0 or i == number_of_words - 1:
            word = 10  # silence
        else:
            word = int(continuous_words[i - 1])
        mfcc_list = SR.get_isolated_templates(word)
        model = k_means(mfcc_list)
        temp_number_of_frames_in_each_state = [0 for i in xrange(number_of_states_for_each_word)]
        for number_of_frames_in_each_state_in_each_template in model[5]:
            for i in xrange(number_of_states_for_each_word):
                temp_number_of_frames_in_each_state[i] += number_of_frames_in_each_state_in_each_template[i]
        number_of_frames_in_each_state.extend(temp_number_of_frames_in_each_state)
        template.extend(model[0][0])
        covariance_matrix_in_each_state.extend(model[2])
        mean_in_each_state.extend(model[3])
    for input_feature in input_list:
        print len(template), len(input_feature)
        last_state_index = [[[0, 0] for i in xrange(len(template))] for j in xrange(len(input_feature))]
        cost_matrix = [[float('inf') for i in xrange(len(template))] for j in xrange(len(input_feature))]
        cost_matrix[0][0] = get_mahalanobis_distance(covariance_matrix_in_each_state[0],
                                                     mean_in_each_state[0], input_feature[0])[1]
        for i in xrange(1, len(input_feature)):
            for j in xrange(len(template)):
                if j == 0:
                    transform_list = [j]
                else:
                    transform_list = [j - 1, j]
                for last_state in transform_list:
                    edge_cost = (number_of_frames_in_each_state[j] - 10.0) / number_of_frames_in_each_state[
                        j] if j == last_state else 10.0 / number_of_frames_in_each_state[last_state]
                    new_cost = cost_matrix[i - 1][last_state] + edge_cost
                    if cost_matrix[i][j] > new_cost:
                        min_index = last_state
                        cost_matrix[i][j] = new_cost
                cost_matrix[i][j] += get_mahalanobis_distance(covariance_matrix_in_each_state[j],
                                                              mean_in_each_state[j], input_feature[i])[1]
                last_state_index[i][j] = [i - 1, min_index]
        min_cost = min(
            cost_matrix[len(input_feature) - 1][(len(template) - number_of_states_for_each_word):len(template)])
        cur_index = cost_matrix[len(input_feature) - 1].index(min_cost)
        path = []
        i = len(input_feature) - 1
        while i >= 0:
            path.append(cur_index)
            cur_index = last_state_index[i][cur_index][1]
            i -= 1
        print path
        number_of_frames_in_each_state_in_one_template = [0 for i in xrange(number_of_states)]
        for state in path:
            number_of_frames_in_each_state_in_one_template[state] += 1
        number_of_frames_in_each_state_for_each_template.append(number_of_frames_in_each_state_in_one_template)
        print number_of_frames_in_each_state_for_each_template
    trained_model = train_model(input_list, number_of_states, number_of_frames_in_each_state_for_each_template)
    return trained_model
Ejemplo n.º 39
0
        try:
            util.pread2(["mkfs.ext3", "-F", self.remotepath])
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMFilesystem', \
                  opterr='mkfs failed error %d' % inst.code)

        #Update serial number string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                  scsiutil.devlist_to_serialstring(self.root.split(',')))

    def vdi(self, uuid, loadLocked = False):
        if not loadLocked:
            return EXTFileVDI(self, uuid)
        return EXTFileVDI(self, uuid)


class EXTFileVDI(FileSR.FileVDI):
    def attach(self, sr_uuid, vdi_uuid):
        if not hasattr(self,'xenstore_data'):
            self.xenstore_data = {}

        self.xenstore_data["storage-type"]="ext"

        return super(EXTFileVDI, self).attach(sr_uuid, vdi_uuid)


if __name__ == '__main__':
    SRCommand.run(EXTSR, DRIVER_INFO)
else:
    SR.registerSR(EXTSR)
Ejemplo n.º 40
0
            count += 1
        return count

    def _getLUNbySMconfig(self, sm_config):
        raise xs_errors.XenError('VDIUnavailable')
        
    def vdi(self, uuid):
        return LUNperVDI.RAWVDI(self, uuid)

    def srlist_toxml(self, SRs):
        dom = xml.dom.minidom.Document()
        element = dom.createElement("SRlist")
        dom.appendChild(element)

        for val in SRs:
            record = SRs[val]
            entry = dom.createElement('SR')
            element.appendChild(entry)

            subentry = dom.createElement("UUID")
            entry.appendChild(subentry)
            textnode = dom.createTextNode(val)
            subentry.appendChild(textnode)
        return dom.toprettyxml()


if __name__ == '__main__':
    SRCommand.run(HBASR, DRIVER_INFO)
else:
    SR.registerSR(HBASR)
Ejemplo n.º 41
0
                raise xs_errors.XenError('VDIUnavailable')
        resp = {}
        resp['device_config'] = self.sr.dconf
        resp['sr_uuid'] = sr_uuid
        resp['vdi_uuid'] = vdi_uuid
        resp['sr_sm_config'] = self.sr.sm_config
        resp['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        """Used for HA State-file only. Will not just attach the VDI but
        also start a tapdisk on the file"""
        util.SMlog("CIFSFileVDI.attach_from_config")
        try:
            if not util.pathexists(self.sr.path):
                self.sr.attach(sr_uuid)
        except:
            util.logException("CIFSFileVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach from config')


if __name__ == '__main__':
    SRCommand.run(CIFSSR, DRIVER_INFO)
else:
    SR.registerSR(CIFSSR)
#
Ejemplo n.º 42
0
Archivo: udevSR.py Proyecto: ESDS/sm
        self.sr.update(sr_uuid)
        return super(udevVDI, self).get_params()

    def update(self, sr_uuid, vdi_location):
        self.load(vdi_location)
        # _db_update requires self.uuid to be set
        self.uuid = self.sr.srcmd.params['vdi_uuid']
        self._db_update()
        # also reset the name-label and description since we're a bit of
        # a special SR
        # this would lead to an infinite loop as VDI.set_name_label now
        # calls VDI.update 
        # temporarily commenting this to pass quicktest
        #vdi = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid)        
        #self.sr.session.xenapi.VDI.set_name_label(vdi, self.label)
        #self.sr.session.xenapi.VDI.set_name_description(vdi, self.description)        

    def attach(self, sr_uuid, vdi_uuid):
        if self.deleted:
            raise xs_errors.XenError('VDIUnavailable')

        return super(udevVDI, self).attach(sr_uuid, vdi_uuid)

    def detach(self, sr_uuid, vdi_uuid):
        pass

if __name__ == '__main__':
    SRCommand.run(udevSR, DRIVER_INFO)
else:
    SR.registerSR(udevSR)
Ejemplo n.º 43
0
        driver = SR.driver('hba')
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if 'SCSIid' not in self.dconf or not self.dconf['SCSIid']:
            print(self.hbasr.print_devs(), file=sys.stderr)
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        LVHDSR.LVHDSR.load(self, sr_uuid)

    def vdi(self, uuid):
        return LVHDoFCoEVDI(self, uuid)


class LVHDoFCoEVDI(LVHDoHBASR.LVHDoHBAVDI):
    pass

if __name__ == '__main__':
    SRCommand.run(LVHDoFCoESR, DRIVER_INFO)
else:
    SR.registerSR(LVHDoFCoESR)
Ejemplo n.º 44
0
    def vdiExists(self, vdi_path):
        """ Reads first 8 bytes of the path and checks for the cookie """

        fd = open(vdi_path)
        cookie = fd.read(8)
        fd.close()

        if cookie == VHD_COOKIE:
            return True

        return False

    def _get_vdi_from_xapi(self, vdi_uuid):

        vdi = {}
        try:
            vdi_ref = self.sr.session.xenapi.VDI.get_by_uuid(vdi_uuid)
            vdi = self.sr.session.xenapi.VDI.get_record(vdi_ref)
        except: # Can raise exception when creating a new VDI so it is not yet in the DB
            pass

        return vdi



if __name__ == '__main__':
    SRCommand.run(VDILUNSR, DRIVER_INFO)
else:
    SR.registerSR(VDILUNSR)
Ejemplo n.º 45
0
        dict['device_config'] = self.sr.dconf
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['allocation'] =  self.sr.sm_config['allocation']
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("LVHDoHBAVDI.attach_from_config")
        self.sr.hbasr.attach(sr_uuid)
        if self.sr.mpath == "true":
            self.sr.mpathmodule.refresh(self.sr.SCSIid,0)
        try:
            return self.attach(sr_uuid, vdi_uuid)
        except:
            util.logException("LVHDoHBAVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')

def match_scsidev(s):
    regex = re.compile("^/dev/disk/by-id|^/dev/mapper")
    return regex.search(s, 0)
    
if __name__ == '__main__':
    SRCommand.run(LVHDoHBASR, DRIVER_INFO)
else:
    SR.registerSR(LVHDoHBASR)
Ejemplo n.º 46
0
Archivo: OCFSSR.py Proyecto: Sisimon/sm
        util.SMlog("OCFSFileVDI.generate_config")
        if not util.pathexists(self.path):
                raise xs_errors.XenError('VDIUnavailable')
        resp = {}
        resp['device_config'] = self.sr.dconf
        resp['sr_uuid'] = sr_uuid
        resp['vdi_uuid'] = vdi_uuid
        resp['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        """Used for HA State-file only. Will not just attach the VDI but
        also start a tapdisk on the file"""
        util.SMlog("OCFSFileVDI.attach_from_config")
        try:
            if not util.pathexists(self.sr.path):
                self.sr.attach(sr_uuid)
        except:
            util.logException("OCFSFileVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach from config')


if __name__ == '__main__':
    SRCommand.run(OCFSSR, DRIVER_INFO)
else:
    SR.registerSR(OCFSSR)
Ejemplo n.º 47
0
            element.appendChild(entry)

            subentry = dom.createElement("UUID")
            entry.appendChild(subentry)
            textnode = dom.createTextNode(val)
            subentry.appendChild(textnode)

            subentry = dom.createElement("Target")
            entry.appendChild(subentry)
            textnode = dom.createTextNode(record['target'])
            subentry.appendChild(textnode)

            subentry = dom.createElement("TargetIQN")
            entry.appendChild(subentry)
            textnode = dom.createTextNode(record['targetIQN'])
            subentry.appendChild(textnode)
        return dom.toprettyxml()

    def match_lun(self, s):
        regex = re.compile("_")
        if regex.search(s,0):
            return False
        regex = re.compile("LUN")
        return regex.search(s, 0)    
        

if __name__ == '__main__':
    SRCommand.run(ISCSISR, DRIVER_INFO)
else:
    SR.registerSR(ISCSISR)
Ejemplo n.º 48
0
    def delete(self, sr_uuid, vdi_uuid):
        util.SMlog("Raw LUN VDI delete")
        scsi_id = self.sm_config['SCSIid']
        xapi_session = self.session.xenapi

        # Cleaning up SR sm_config
        scsi_key = "scsi-" + scsi_id
        xapi_session.SR.remove_from_sm_config(self.sr.sr_ref, scsi_key)

    def detach(self, sr_uuid, vdi_uuid):
        scsi_id = self.sm_config['SCSIid']
        xapi_session = self.session.xenapi

        # Multipath disable
        if self.sr.mpath == "true":
            self.sr.mpathmodule.reset(scsi_id, explicit_unmap=True)
            util.remove_mpathcount_field(self.sr.session, self.sr.host_ref,
                                         self.sr.sr_ref, scsi_id)

        # Get size from xapi db
        vdi_ref = xapi_session.VDI.get_by_uuid(vdi_uuid)
        size = int(xapi_session.VDI.get_virtual_size(vdi_ref))

        self.sr.update_stats(-size)


if __name__ == '__main__':
    SRCommand.run(RawHBASR, DRIVER_INFO)
else:
    SR.registerSR(RawHBASR)
Ejemplo n.º 49
0
        if 'type' not in self.original_srcmd.params['device_config'] or \
                'type' in self.original_srcmd.params['device_config'] and \
                self.original_srcmd.dconf['type'] == "any":
            self.original_srcmd.dconf['type'] = "fcoe"
        self.hbasr = driver(self.original_srcmd, sr_uuid)
        pbd = None
        try:
            pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref)
        except:
            pass

        if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']:
            print >>sys.stderr, self.hbasr.print_devs()
            raise xs_errors.XenError('ConfigSCSIid')

        self.SCSIid = self.dconf['SCSIid']
        self._pathrefresh(LVHDoFCoESR)
        LVHDSR.LVHDSR.load(self, sr_uuid)

    def vdi(self, uuid):
        return LVHDoFCoEVDI(self, uuid)


class LVHDoFCoEVDI(LVHDoHBASR.LVHDoHBAVDI):
    pass

if __name__ == '__main__':
    SRCommand.run(LVHDoFCoESR, DRIVER_INFO)
else:
    SR.registerSR(LVHDoFCoESR)
Ejemplo n.º 50
0
                st = os.stat(self.path)
                self.size = long(st.st_size)
                self.utilisation = long(st.st_size)
            except OSError, inst:
                raise xs_errors.XenError('EIO', \
                      opterr='failed to star %s error is %d' % self.path % \
                      inst.sterror)

    def create(self, sr_uuid, vdi_uuid, size):
        # This is a no-op in this driver, VDI's will be introduced via 
        # separate call vdi_introduce
        raise xs_errors.XenError('Unimplemented', \
              opterr='VDI create unsupported')

    def delete(self, sr_uuid, vdi_uuid):
        raise xs_errors.XenError('Unimplemented', \
              opterr='VDI delete unsupported')

    def clone(self, sr_uuid, vdi_uuid):
        raise xs_errors.XenError('Unimplemented', \
              opterr='VDI clone unsupported')

    def snapshot(self, sr_uuid, vdi_uuid):
        raise xs_errors.XenError('Unimplemented', \
              opterr='VDI snapshot unsupported')

if __name__ == '__main__':
    SRCommand.run(RAWSR, DRIVER_INFO)
else:
    SR.registerSR(RAWSR)
Ejemplo n.º 51
0
Archivo: SHMSR.py Proyecto: rdobson/sm
            stat = os.stat(self.path)
            self.utilisation = long(stat.st_size)
            self.size = long(stat.st_size)
        except:
            pass

    def __init__(self, mysr, uuid, filename):
        self.uuid = uuid
        VDI.VDI.__init__(self, mysr, None)
        self.path = os.path.join(mysr.dconf['location'], filename)
        self.label = filename
        self.location = filename
        self.vdi_type = 'file'
        self.read_only = True
        self.shareable = True
        self.sm_config = {}

    def detach(self, sr_uuid, vdi_uuid):
	pass

    def clone(self, sr_uuid, vdi_uuid):
        return self.get_params()

    def snapshot(self, sr_uuid, vdi_uuid):
        return self.get_params()

if __name__ == '__main__':
    SRCommand.run(SHMSR, DRIVER_INFO)
else:
    SR.registerSR(SHMSR)
Ejemplo n.º 52
0
            self.physical_size += obj.size
            count += 1
        return count

    def _getLUNbySMconfig(self, sm_config):
        raise xs_errors.XenError('VDIUnavailable')
        
    def vdi(self, uuid):
        return LUNperVDI.RAWVDI(self, uuid)

    def srlist_toxml(self, SRs):
        dom = xml.dom.minidom.Document()
        element = dom.createElement("SRlist")
        dom.appendChild(element)

        for val in SRs:
            record = SRs[val]
            entry = dom.createElement('SR')
            element.appendChild(entry)

            subentry = dom.createElement("UUID")
            entry.appendChild(subentry)
            textnode = dom.createTextNode(val)
            subentry.appendChild(textnode)
        return dom.toprettyxml()

if __name__ == '__main__':
    SRCommand.run(HBASR, DRIVER_INFO)
else:
    SR.registerSR(HBASR)
Ejemplo n.º 53
0
        dict['device_config'] = self.sr.dconf
        if dict['device_config'].has_key('chappassword_secret'):
            s = util.get_secret(self.session, dict['device_config']['chappassword_secret'])
            del dict['device_config']['chappassword_secret']
            dict['device_config']['chappassword'] = s
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("OCFSoISCSIVDI.attach_from_config")
        try:
            self.sr.iscsi.attach(sr_uuid)
            if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid):
                raise xs_errors.XenError('InvalidDev')
            return OCFSSR.OCFSFileVDI.attach(self, sr_uuid, vdi_uuid)
        except:
            util.logException("OCFSoISCSIVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')


if __name__ == '__main__':
    SRCommand.run(OCFSoISCSISR, DRIVER_INFO)
else:
    SR.registerSR(OCFSoISCSISR)
Ejemplo n.º 54
0
        diskinfo = {}
        cmd = [SR.TAPDISK_UTIL, "query", vhdutil.VDI_TYPE_VHD, "-vpf", path]
        txt = util.pread(cmd).split('\n')
        diskinfo['size'] = txt[0]
        lst = [txt[1].split('/')[-1].replace(vhdutil.FILE_EXTN_VHD, "")]
        for val in filter(util.exactmatch_uuid, lst):
            diskinfo['parent'] = val
        diskinfo['hidden'] = txt[2].split()[1]
        return diskinfo

    def _create(self, size, path):
        cmd = [SR.TAPDISK_UTIL, "create", vhdutil.VDI_TYPE_VHD, size, path]
        text = util.pread(cmd)

    def _mark_hidden(self, path):
        vhdutil.setHidden(path, True)
        self.hidden = 1

    def extractUuid(path):
        fileName = os.path.basename(path)
        uuid = fileName.replace(vhdutil.FILE_EXTN_VHD, "")
        return uuid

    extractUuid = staticmethod(extractUuid)


if __name__ == '__main__':
    SRCommand.run(FileSR, DRIVER_INFO)
else:
    SR.registerSR(FileSR)
Ejemplo n.º 55
0
def runSample(params):
        #retrieving the given parameter
        ccs=params[0]
        tree=params[1]
        extantAdjacencies=params[2]
        adjacencyProbs=params[3]
        alpha=params[4]
        i=params[5]
        extantAdjacencies_species_adj=params[6]
        outputDirectory=params[7]
        reconstructedMarkerCount=params[8]
        allSampleReconstructionStatistic={}
        dict_SCJ={}
        #lock = multiprocessing.Lock()
        #output text log
        outLog="Sample: "+str(i)+"\n"

        #start sampling method like in the Main.py
        outLog+="Enumerate joint labelings...\n"
        jointLabels, first = SR.enumJointLabelings(ccs)
        outLog+="Check valid labels...\n"
        validLabels, validAtNode = SR.validLabels(jointLabels, first)

        #lock.acquire()
        outLog+= "Compute ancestral labels with SR...\n"
        topDown = SR.sampleLabelings(tree, ccs, validAtNode, extantAdjacencies, adjacencyProbs, alpha)
        #lock.release()
        reconstructedAdj = SR.reconstructedAdjacencies(topDown)
        SR.outputReconstructedAdjacencies(reconstructedAdj, outputDirectory+"/reconstructed_adjacencies_" + str(i))

        for node in reconstructedAdj:
            # count for each adjaency on each internal node, how often this adjacencies over all samples occurs there
            for adjacency in reconstructedAdj[node]:
                #lock.acquire()
                if (node,adjacency) in allSampleReconstructionStatistic:
                    allSampleReconstructionStatistic[(node,adjacency)] += 1
                else:
                    allSampleReconstructionStatistic.update({(node,adjacency):1})
                #lock.release()
        outLog+="Scaffolding...\n"
        scaffolds = scaffolding.scaffoldAdjacencies(reconstructedAdj)
        undoubled = scaffolding.undoubleScaffolds(scaffolds)
        scaffolding.outputUndoubledScaffolds(undoubled, outputDirectory+"/undoubled_scaffolds_" + str(i))
        scaffolding.outputScaffolds(scaffolds, outputDirectory+"/doubled_scaffolds_" + str(i))
        log=scaffolding.sanityCheckScaffolding(undoubled)
        outLog+=log
        for node in undoubled:
            outLog+= str(node)+'\n'
            markerCounter = 0
            for scaffold in undoubled[node]:
                first = scaffold[0]
                last = scaffold[-1]
                if not first == last:
                    markerCounter = markerCounter + len(scaffold)
                else:
                    markerCounter = markerCounter + len(scaffold) - 1
            outLog+= str(node) + " number of reconstructed undoubled marker in scaffolds: " + str(markerCounter)+'\n'
            # number of reconstructed markerIds given by reconstructedMarkerCount
            # singleton scaffolds number / number of not reconstructed marker
            notReconstructedMarkerCount = reconstructedMarkerCount - markerCounter
            # number of all scaffolds
            allScaffoldCount = len(undoubled[node]) + notReconstructedMarkerCount
            outLog+= str(node) + " number of singleton scaffolds (not reconstructed marker): " + str(
                notReconstructedMarkerCount)+'\n'
            outLog+= str(node) + " number of scaffolds: " + str(allScaffoldCount)+'\n'


        #lock.acquire()
        scj = calculate_SCJ(tree, reconstructedAdj, extantAdjacencies_species_adj)
        outLog+="Single-Cut-or-Join-Distance: " + str(scj)+'\n'
        dict_SCJ.update({'Sample_' + str(i): scj})
        #lock.release()
        return (allSampleReconstructionStatistic,dict_SCJ,outLog)
Ejemplo n.º 56
0
            
            cephutils.VDI.update(self, sr_uuid, vdi_uuid)
            
            sm_config = self.session.xenapi.VDI.get_sm_config(self_vdi_ref)
            if sm_config.has_key('reverted'):
                 if sm_config['reverted'] == 'true':
                     del sm_config['reverted']
                     self.session.xenapi.VDI.set_sm_config(self_vdi_ref, sm_config)
            else:
                if has_snapshots == True:
                    for snapshot_uuid in self.snaps.keys():
                        util.SMlog("RBDVDI.update start setting snapshots")
                        snapshot_vdi_ref = self.session.xenapi.VDI.get_by_uuid(snapshot_uuid)
                        self.session.xenapi.VDI.set_name_label(snapshot_vdi_ref, self.session.xenapi.VDI.get_name_label(self_vdi_ref))
                        self.session.xenapi.VDI.set_name_description(snapshot_vdi_ref, self.session.xenapi.VDI.get_name_description(self_vdi_ref))
                        util.SMlog("RBDVDI.update finish setting snapshots")
        else:
            self_vdi_sm_config = self.session.xenapi.VDI.get_sm_config(self_vdi_ref)
            base_vdi_uuid = self_vdi_sm_config["snapshot-of"]
            base_vdi_ref = self.session.xenapi.VDI.get_by_uuid(base_vdi_uuid)
            self.label=self.session.xenapi.VDI.get_name_label(base_vdi_ref)
            self.description=self.session.xenapi.VDI.get_name_description(base_vdi_ref)
            self.snaps = {}
            self.snaps[vdi_uuid]=self.session.xenapi.VDI.get_snapshot_time(self_vdi_ref)
            cephutils.VDI.update(self, sr_uuid, base_vdi_uuid)

if __name__ == '__main__':
    SRCommand.run(RBDSR, DRIVER_INFO)
else:
    SR.registerSR(RBDSR)
Ejemplo n.º 57
0
        if dict['device_config'].has_key('chappassword_secret'):
            s = util.get_secret(self.session, dict['device_config']['chappassword_secret'])
            del dict['device_config']['chappassword_secret']
            dict['device_config']['chappassword'] = s
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['allocation'] =  self.sr.sm_config['allocation']
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("LVHDoISCSIVDI.attach_from_config")
        try:
            self.sr.iscsi.attach(sr_uuid)
            if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid):
                raise xs_errors.XenError('InvalidDev')
            return LVHDSR.LVHDVDI.attach(self, sr_uuid, vdi_uuid)
        except:
            util.logException("LVHDoISCSIVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')


if __name__ == '__main__':
    SRCommand.run(LVHDoISCSISR, DRIVER_INFO)
else:
    SR.registerSR(LVHDoISCSISR)
Ejemplo n.º 58
0
            self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \
                    "storage-type")
            self.session.xenapi.VDI.add_to_xenstore_data(vdi_ref, \
                    "storage-type", "nfs")
        except:
            util.logException("NFSSR:attach")
            pass

        return super(NFSFileVDI, self).attach(sr_uuid, vdi_uuid)

    def clone(self, sr_uuid, vdi_uuid):
        timestamp_before = int(util.get_mtime(self.sr.path))
        ret = super(NFSFileVDI, self).clone(sr_uuid, vdi_uuid)
        timestamp_after = int(util.get_mtime(self.sr.path))
        if timestamp_after == timestamp_before:
            util.SMlog("SR dir timestamp didn't change, updating")
            timestamp_after += 1
            os.utime(self.sr.path, (timestamp_after, timestamp_after))
        return ret

class NFSFileVDINolock(NFSFileVDI):
    def load(self, vdi_uuid):
        self.lock = self.sr.lock
        self._load(vdi_uuid)


if __name__ == '__main__':
    SRCommand.run(NFSSR, DRIVER_INFO)
else:
    SR.registerSR(NFSSR)
Ejemplo n.º 59
0
        self.sr.dconf['multipathhandle'] = self.sr.mpathhandle
        dict['device_config'] = self.sr.dconf
        dict['sr_uuid'] = sr_uuid
        dict['vdi_uuid'] = vdi_uuid
        dict['command'] = 'vdi_attach_from_config'
        # Return the 'config' encoded within a normal XMLRPC response so that
        # we can use the regular response/error parsing code.
        config = xmlrpclib.dumps(tuple([dict]), "vdi_attach_from_config")
        return xmlrpclib.dumps((config,), "", True)

    def attach_from_config(self, sr_uuid, vdi_uuid):
        util.SMlog("OCFSoHBAVDI.attach_from_config")
        self.sr.hbasr.attach(sr_uuid)
        if self.sr.mpath == "true":
            self.sr.mpathmodule.refresh(self.sr.SCSIid,0)
        try:
            return self.attach(sr_uuid, vdi_uuid)
        except:
            util.logException("OCFSoHBAVDI.attach_from_config")
            raise xs_errors.XenError('SRUnavailable', \
                        opterr='Unable to attach the heartbeat disk')

def match_scsidev(s):
    regex = re.compile("^/dev/disk/by-id|^/dev/mapper")
    return regex.search(s, 0)
    
if __name__ == '__main__':
    SRCommand.run(OCFSoHBASR, DRIVER_INFO)
else:
    SR.registerSR(OCFSoHBASR)