Exemple #1
0
    def __init__(self, sr):
        self.sr = sr
        self.__xenapi_locations = {}
        self.__xenapi_records = util.list_VDI_records_in_sr(sr)
        for vdi in self.__xenapi_records.keys():
            self.__xenapi_locations[self.__xenapi_records[vdi]['location']] = vdi
        self.__sm_records = {}
        for vdi in sr.vdis.values():
            # We initialise the sm_config field with the values from the database
            # The sm_config_overrides contains any new fields we want to add to
            # sm_config, and also any field to delete (by virtue of having 
            # sm_config_overrides[key]=None)
            try:
                if not hasattr(vdi, "sm_config"):
                    vdi.sm_config = self.__xenapi_records[self.__xenapi_locations[vdi.location]]['sm_config'].copy()
            except:
                util.SMlog("missing config for vdi: %s" % vdi.location)
                vdi.sm_config = {}

            if vdi.sm_config_override:
                if len(vdi.sm_config_override.keys())>0:
                    util.SMlog("original sm_config: %s" % repr(vdi.sm_config))
                for key in vdi.sm_config_override.keys():
                    if vdi.sm_config_override[key]:
                        vdi.sm_config[key]=vdi.sm_config_override[key]
                    else:
                        if vdi.sm_config.has_key(key):
                            del vdi.sm_config[key]
                if len(vdi.sm_config_override.keys())>0:
                    util.SMlog("overridden sm_config: %s" % repr(vdi.sm_config))
            self.__sm_records[vdi.location] = vdi

        xenapi_locations = set(self.__xenapi_locations.keys())
        sm_locations = set(self.__sm_records.keys())

        # These ones are new on disk
        self.new = sm_locations.difference(xenapi_locations)
        # These have disappeared from the disk
        self.gone = xenapi_locations.difference(sm_locations)
        # These are the ones which are still present but might have changed...
        existing = sm_locations.intersection(xenapi_locations)
        # Synchronise the uuid fields using the location as the primary key
        # This ensures we know what the UUIDs are even though they aren't stored
        # in the storage backend.
        for location in existing:
            sm_vdi = self.get_sm_vdi(location)
            xenapi_vdi = self.get_xenapi_vdi(location)
            sm_vdi.uuid = util.default(sm_vdi, "uuid", lambda: xenapi_vdi['uuid']) 
                
        # Only consider those whose configuration looks different
        self.existing = filter(lambda x:not(self.get_sm_vdi(x).in_sync_with_xenapi_record(self.get_xenapi_vdi(x))), existing)

        if len(self.new) <> 0:
            util.SMlog("new VDIs on disk: " + repr(self.new))
        if len(self.gone) <> 0:
            util.SMlog("VDIs missing from disk: " + repr(self.gone))
        if len(self.existing) <> 0:
            util.SMlog("VDIs changed on disk: " + repr(self.existing))
Exemple #2
0
 def check_no_other_vdi_operation_in_progress(self):
     vdis = util.list_VDI_records_in_sr(self.sr)
     vdi_ref = self.session.xenapi.VDI.get_by_uuid(self.uuid)
     del vdis[vdi_ref]
     active_vdis = filter(lambda v: v['current_operations'] != {}, vdis.values())
     if len(active_vdis) != 0:
         msg = "LVHDRT: found other operations in progress for VDI: %s" % active_vdis[0]['uuid']
         util.SMlog(msg)
         raise xs_errors.XenError('OtherVDIOperationInProgress')