Пример #1
0
    def _loadvdis(self):
        """Scan the directory and get uuids either from the VDI filename,
        or by creating a new one."""
        if self.vdis:
            return

        for name in filter(is_image_utf8_compatible,
                           util.listdir(self.path, quiet=True)):
            self.vdis[name] = LocalISOVDI(self, name)
            # Set the VDI UUID if the filename is of the correct form.
            # Otherwise, one will be generated later in VDI._db_introduce.
            m = uuid_file_regex.match(name)
            if m:
                self.vdis[name].uuid = m.group(1)

        # Synchronise the read-only status with existing VDI records
        __xenapi_records = util.list_VDI_records_in_sr(self)
        __xenapi_locations = {}
        for vdi in __xenapi_records.keys():
            __xenapi_locations[__xenapi_records[vdi]['location']] = vdi
        for vdi in self.vdis.values():
            if vdi.location in __xenapi_locations:
                v = __xenapi_records[__xenapi_locations[vdi.location]]
                sm_config = v['sm_config']
                if 'created' in sm_config:
                    vdi.sm_config['created'] = sm_config['created']
                    vdi.read_only = False
Пример #2
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))
Пример #3
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')
Пример #4
0
Файл: SR.py Проект: euanh/sm
    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[util.to_plain_string(
                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 = {}

            vdi._override_sm_config(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))
Пример #5
0
Файл: ISOSR.py Проект: xcp-ng/sm
    def _loadvdis(self):
        """Scan the directory and get uuids either from the VDI filename, \
        or by creating a new one."""
        if self.vdis:
            return

        for name in filter(is_image_utf8_compatible,
                           util.listdir(self.path, quiet=True)):
            fileName = self.path + "/" + name
            if os.path.isdir(fileName):
                util.SMlog("_loadvdis : %s is a directory. Ignore" % fileName)
                continue

            # CA-80254: Check for iso/img files whose name consists of extended
            # characters.
            try:
                name.decode('ascii')
            except UnicodeDecodeError:
                raise xs_errors.XenError('CIFSExtendedCharsNotSupported', \
                        opterr='The repository contains at least one file whose name consists of extended characters.')

            self.vdis[name] = ISOVDI(self, name)
            # Set the VDI UUID if the filename is of the correct form.
            # Otherwise, one will be generated later in VDI._db_introduce.
            m = self.uuid_file_regex.match(name)
            if m:
                self.vdis[name].uuid = m.group(1)

        # Synchronise the read-only status with existing VDI records
        __xenapi_records = util.list_VDI_records_in_sr(self)
        __xenapi_locations = {}
        for vdi in __xenapi_records.keys():
            __xenapi_locations[__xenapi_records[vdi]['location']] = vdi
        for vdi in self.vdis.values():
            if vdi.location in __xenapi_locations:
                v = __xenapi_records[__xenapi_locations[vdi.location]]
                sm_config = v['sm_config']
                if 'created' in sm_config:
                    vdi.sm_config['created'] = sm_config['created']
                    vdi.read_only = False