def destroy_vdi(self, vdi_uuid, del_file=False, transient = False):
     if vdi_uuid in self.images:
         if del_file:
             self.del_img_file_from_ssh(vdi_uuid)
         del self.images[vdi_uuid]
     self.save_state(transient)
     XendNode.instance().save_SRs()
 def destroy_vdi(self, vdi_uuid, del_file=True, transient = False):
     if vdi_uuid in self.images:
         if del_file:
             log.debug('destroy_vdi')
             log.debug(self.images[vdi_uuid])
             self.del_img_file(vdi_uuid)
         del self.images[vdi_uuid]
     self.save_state(transient)
     XendNode.instance().save_local_SRs()
    def destroy_vdi(self, vdi_uuid, del_file=False, transient = False):
#        if vdi_name:
#            for vdi_ref, image in self.images.items():
#                if image.name_label == vdi_name:
#                    vdi_uuid = vdi_ref
        if vdi_uuid in self.images:
            if del_file:
                self.del_img_file_from_ssh(vdi_uuid)
            del self.images[vdi_uuid]
        self.save_state(transient)
        XendNode.instance().save_SRs()        
    def destroy_vdi(self, vdi_uuid, del_file=True, transient = False):
#        if vdi_name:
#            for vdi_ref, image in self.images.items():
#                if image.name_label == vdi_name:
#                    vdi_uuid = vdi_ref
        if vdi_uuid in self.images:
            tmp = self.other_config['location'].split(':')
            exists = os.path.exists(tmp[len(tmp)-1])
            log.debug("in images")
            if exists and del_file:
                self.del_img_file_from_ssh(vdi_uuid)
            del self.images[vdi_uuid]
        else:
            log.debug("error: must not be here")
        self.save_state(transient)
        XendNode.instance().save_SRs()
    def destroy_vdi(self, vdi_uuid, del_file=True, has_no_snapshot = False, transient = False):    
        if vdi_uuid in self.images:
            log.debug(self.images[vdi_uuid])
            if  has_no_snapshot:  
                log.debug('===========>destroy_vdi============')
                vdi_struct = self.images[vdi_uuid].get_record()
                log.debug(vdi_struct)
                self.del_img_file(vdi_uuid, del_file)
                del self.images[vdi_uuid]
            else:
                self.change_vdi_state(vdi_uuid, False) # make vdi not in relation with vm
#                 self.images[vdi_uuid]['inUse'] = False # make vdi not in relation with vm
        log.debug('destroy vdi in ocfs2>>>>>>>>>>>>')
               
        self.save_state(transient)
        XendNode.instance().save_local_SRs()
 def get_record(self, transient = True):
     retval = {'uuid': self.uuid,
               'name_label': self.name_label,
               'name_description': self.name_description,
               'resident_on' : XendNode.instance().uuid,
               'virtual_allocation': 0,
               'physical_utilisation': self.get_physical_utilisation(),
               'physical_size': self.get_physical_size(),
               'type': self.type,
               'content_type': self.content_type,
               'VDIs': self.images.keys(),
               'PBDs': XendPBD.get_by_SR(self.uuid),
               'other_config': self.other_config,
               'shared': self.shared,
               'mount_point': self.mount_point, 
               'sm_config': self.sm_config,}
     return retval
    def get_record(self, transient = True):
        retval = {'uuid': self.uuid,
                  'name_label': self.name_label,
                  'name_description': self.name_description,
                  'resident_on' : XendNode.instance().uuid,
                  'virtual_allocation': self.virtual_allocation,
                  'physical_utilisation': self.physical_utilisation,
                  'physical_size': self.physical_size,
                  'type': self.type,
                  'content_type': self.content_type,
                  'VDIs': self.images.keys(),
                  'PBDs': XendPBD.get_by_SR(self.uuid)}
        
        if self.physical_size == XEND_STORAGE_NO_MAXIMUM:
            stfs = os.statvfs(self.location)
            retval['physical_size'] = stfs.f_blocks * stfs.f_frsize

        return retval
 def get_record(self, transient = True):
     if self.record_changed:
         self.cached_record = {'uuid': self.uuid,
               'name_label': self.name_label,
               'name_description': self.name_description,
               'resident_on' : XendNode.instance().uuid,
               'virtual_allocation': 0,
               'physical_utilisation': self.get_physical_utilisation(),
               'physical_size': self.get_physical_size(),
               'type': self.type,
               'content_type': self.content_type,
               'VDIs': self.images.keys(),
               'PBDs': XendPBD.get_by_SR(self.uuid),
               'other_config': self.other_config,
               'shared': self.shared,
               'sm_config': self.sm_config,}
         self.record_changed = False
     return self.cached_record
    def update(self, auto=True, del_vdi=True):
        location = self.other_config.get('location')
        local = os.path.join(location.split(':')[1], self.uuid)
        log.debug(local)
#        local = location.split(':')[1]
        stored_images = self.state.load_state('vdi')
        images_path = {}
        if stored_images:
            for image_uuid, image in stored_images.items():
                images_path[image['location']] = image_uuid
                self.images[image_uuid] = XendLocalVDI(image)
        if auto:
            sxps = sxp_files(local)
            log.debug(sxps)
            vdi_struct = {}
            if sxps:
                for sxp in sxps.keys():
                    if sxp not in images_path.keys():
                        vdi_struct['other_config'] = {'virtual_machine' : self.get_domain_name_by_sxp(sxp),\
                                                      'vm_uuid' : self.get_domain_uuid_by_sxp(sxp)}
                        log.debug(vdi_struct['other_config'])
                        vdi_struct['location'] = sxp
                        vdi_struct['type'] = 'system'
                        vdi_struct['physical_utilisation'] = sxps[sxp]
                        vdi_struct['VBDs'] = []
#                        dir_name = os.path.dirname(sxp)
                        vdi_struct['name_label'] = XendNode.instance().get_name()
                        #XendTask.log_progress(0, 100, self.create_vdi_append_state, vdi_struct)
        #                self.images[image_new] = XendLocalVDI(image)
                        self.create_vdi_append_state(vdi_struct)
        stored_images = self.state.load_state('vdi')
        images_path = {}
        if stored_images:
            for image_uuid, image in stored_images.items():
                images_path[image['location']] = image_uuid
                self.images[image_uuid] = XendLocalVDI(image)
        if del_vdi and images_path: 
            log.debug(images_path.items())
            for img,vdi_uuid in images_path.items():
                if img not in sxps.keys():
                    self.destroy_vdi(vdi_uuid)