Hide keyboard shortcuts

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

1#!/usr/bin/python3 

2# 

3# Copyright (C) Citrix Systems Inc. 

4# 

5# This program is free software; you can redistribute it and/or modify 

6# it under the terms of the GNU Lesser General Public License as published 

7# by the Free Software Foundation; version 2.1 only. 

8# 

9# This program is distributed in the hope that it will be useful, 

10# but WITHOUT ANY WARRANTY; without even the implied warranty of 

11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

12# GNU Lesser General Public License for more details. 

13# 

14# You should have received a copy of the GNU Lesser General Public License 

15# along with this program; if not, write to the Free Software Foundation, Inc., 

16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 

17 

18import SR 

19import VDI 

20import SRCommand 

21import util 

22import os 

23import xs_errors 

24 

25CAPABILITIES = ["VDI_ATTACH", "VDI_DETACH", "VDI_CLONE", "VDI_SNAPSHOT", 

26 "SR_SCAN", "SR_ATTACH", "SR_DETACH"] 

27CONFIGURATION = ['location', '/dev/shm subdirectory'] 

28DRIVER_INFO = { 

29 'name': 'SHM', 

30 'description': 'Handles shared memory virtual disks', 

31 'vendor': 'Citrix Systems Inc.', 

32 'copyright': '(c) 2009 Citrix Systems, Inc.', 

33 'driver_version': '1.0', 

34 'required_api_version': '1.0', 

35 'capabilities': CAPABILITIES, 

36 'configuration': CONFIGURATION 

37 } 

38 

39TYPE = "shm" 

40 

41 

42class SHMSR(SR.SR): 

43 """Shared memory storage repository""" 

44 

45 def _loadvdis(self): 

46 """Scan the location directory.""" 

47 if self.vdis: 

48 return 

49 

50 try: 

51 for name in util.listdir(self.dconf['location']): 

52 if name != "": 

53 self.vdis[name] = SHMVDI(self, util.gen_uuid(), name) 

54 except: 

55 pass 

56 

57 def handles(type): 

58 """Do we handle this type?""" 

59 if type == TYPE: 

60 return True 

61 return False 

62 handles = staticmethod(handles) 

63 

64 def content_type(self, sr_uuid): 

65 """Returns the content_type XML""" 

66 return super(SHMSR, self).content_type(sr_uuid) 

67 

68 def vdi(self, uuid): 

69 """Create a VDI class""" 

70 if 'vdi_location' in self.srcmd.params: 

71 return SHMVDI(self, uuid, self.srcmd.params['vdi_location']) 

72 else: 

73 return SHMVDI(self, uuid, self.srcmd.params['device_config']['location']) 

74 

75 def load(self, sr_uuid): 

76 """Initialises the SR""" 

77 if 'location' not in self.dconf: 

78 raise xs_errors.XenError('ConfigLocationMissing') 

79 

80 self.sr_vditype = 'file' 

81 self.physical_size = 0 

82 self.physical_utilisation = 0 

83 self.virtual_allocation = 0 

84 

85 def attach(self, sr_uuid): 

86 """Std. attach""" 

87 self._loadvdis() 

88 

89 def detach(self, sr_uuid): 

90 """Std. detach""" 

91 pass 

92 

93 def scan(self, sr_uuid): 

94 """Scan""" 

95 self._loadvdis() 

96 return super(SHMSR, self).scan(sr_uuid) 

97 

98 def create(self, sr_uuid, size): 

99 self.attach(sr_uuid) 

100 self.detach(sr_uuid) 

101 

102 

103class SHMVDI(VDI.VDI): 

104 def load(self, vdi_uuid): 

105 try: 

106 stat = os.stat(self.path) 

107 self.utilisation = int(stat.st_size) 

108 self.size = int(stat.st_size) 

109 except: 

110 pass 

111 

112 def __init__(self, mysr, uuid, filename): 

113 self.uuid = uuid 

114 self.path = os.path.join(mysr.dconf['location'], filename) 

115 VDI.VDI.__init__(self, mysr, None) 

116 self.label = filename 

117 self.location = filename 

118 self.vdi_type = 'file' 

119 self.read_only = True 

120 self.shareable = True 

121 self.sm_config = {} 

122 

123 def detach(self, sr_uuid, vdi_uuid): 

124 pass 

125 

126 def clone(self, sr_uuid, vdi_uuid): 

127 return self.get_params() 

128 

129 def snapshot(self, sr_uuid, vdi_uuid): 

130 return self.get_params() 

131 

132if __name__ == '__main__': 

133 SRCommand.run(SHMSR, DRIVER_INFO) 

134else: 

135 SR.registerSR(SHMSR)