Coverage for drivers/udevSR : 34%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/python # # Copyright (C) Citrix Systems Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; version 2.1 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # udevSR: represents VDIs which are hotplugged into dom0 via udev e.g. # USB CDROM/disk devices
[ [ 'location', 'path to mount (required) (e.g. server:/path)' ] ]
'name': 'udev', 'description': 'SR plugin which represents devices plugged in via udev as VDIs', 'vendor': 'Citrix Systems Inc', 'copyright': '(C) 2008 Citrix Systems Inc', 'driver_version': '1.0', 'required_api_version': '1.1', 'capabilities': CAPABILITIES, 'configuration': CONFIGURATION }
"""udev-driven storage repository""" if type == TYPE: return True return False
return super(udevSR, self).content_type(sr_uuid)
vdi_location = self.srcmd.params['vdi_location'] else:
vdi = self.session.xenapi.VDI vdi_ref = vdi.get_by_uuid(uuid) return vdi.get_location(vdi_ref)
# First of all, check we've got the correct keys in dconf if not self.dconf.has_key('location'): raise xs_errors.XenError('ConfigLocationMissing') self.sr_vditype = 'phy' # Cache the sm_config self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref)
# Return as much information as we have sr_root =self.dconf['location']
if util.pathexists(sr_root): for filename in os.listdir(sr_root): path = os.path.join(sr_root, filename) x = udevVDI(self, path) self.vdis[path] = x
the_sum = 0L for vdi in self.vdis.values(): the_sum = the_sum + vdi.size
self.physical_size = the_sum self.physical_utilisation = the_sum self.virtual_allocation = the_sum
self._db_update()
self.update(sr_uuid)
# base class scan does all the work: return super(udevSR, self).scan(sr_uuid)
pass
pass
pass
pass
f = open(filename, 'r') try: return f.readlines() finally: f.close()
self.deleted = False
# Use the CTIME of the symlink to mean "time it was hotplugged" iso8601 = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(s[stat.ST_CTIME])) self.sm_config['hotplugged_at'] = iso8601
dev = os.path.basename(self.path) info = sysdevice.stat(dev) if "size" in info.keys(): self.size = info["size"] self.utilisation = self.size
self.label = "%s %s" % (info["bus"], info["bus_path"]) self.description = info["hwinfo"]
# XXX: what other information can we recover? if self.sr.sm_config.has_key('type'): self.read_only = self.sr.sm_config['type'] == "cd"
usb_path = info.get("usb_path") if usb_path: self.sm_config["usb_path"] = info["usb_path"] pusbs = self.session.xenapi.PUSB.get_all_records() for pusb in pusbs.itervalues(): if usb_path == pusb.get("path"): if pusb.get("passthrough_enabled"): raise xs_errors.XenError('VDIUnavailable') break
self.uuid = vdi_uuid self.location = self.sr.srcmd.params['vdi_location'] self._db_introduce() # Update the physical_utilisation etc self.sr.update(sr_uuid) return super(udevVDI, self).get_params()
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)
if self.deleted: raise xs_errors.XenError('VDIUnavailable')
return super(udevVDI, self).attach(sr_uuid, vdi_uuid)
pass
SRCommand.run(udevSR, DRIVER_INFO) else: |