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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

#!/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 

 

import SR, VDI, SRCommand, util 

import os 

import xs_errors 

 

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

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

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

DRIVER_INFO = { 

    'name': 'SHM', 

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

    'vendor': 'Citrix Systems Inc.', 

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

    'driver_version': '1.0', 

    'required_api_version': '1.0', 

    'capabilities': CAPABILITIES, 

    'configuration': CONFIGURATION 

    } 

 

TYPE = "shm" 

 

class SHMSR(SR.SR): 

    """Shared memory storage repository""" 

 

    def _loadvdis(self): 

        """Scan the location directory.""" 

        if self.vdis: 

            return 

 

        try: 

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

                if name != "": 

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

        except: 

            pass 

 

    def handles(type): 

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

        if type == TYPE: 

            return True 

        return False 

    handles = staticmethod(handles) 

 

    def content_type(self, sr_uuid): 

        """Returns the content_type XML""" 

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

 

    def vdi(self, uuid): 

        """Create a VDI class""" 

        if self.srcmd.params.has_key('vdi_location'): 

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

        else: 

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

 

    def load(self, sr_uuid): 

        """Initialises the SR""" 

        if not self.dconf.has_key('location'): 

            raise xs_errors.XenError('ConfigLocationMissing') 

 

        self.sr_vditype = 'file' 

        self.physical_size = 0 

        self.physical_utilisation = 0 

        self.virtual_allocation = 0 

 

    def attach(self, sr_uuid): 

        """Std. attach""" 

        self._loadvdis() 

 

    def detach(self, sr_uuid): 

        """Std. detach""" 

        pass 

 

    def scan(self, sr_uuid): 

        """Scan""" 

        self._loadvdis() 

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

 

    def create(self, sr_uuid, size): 

        self.attach(sr_uuid) 

        self.detach(sr_uuid) 

 

 

class SHMVDI(VDI.VDI): 

    def load(self, vdi_uuid): 

        try: 

            stat = os.stat(self.path) 

            self.utilisation = long(stat.st_size) 

            self.size = long(stat.st_size) 

        except: 

            pass 

 

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

        self.uuid = uuid 

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

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

        self.label = filename 

        self.location = filename 

        self.vdi_type = 'file' 

        self.read_only = True 

        self.shareable = True 

        self.sm_config = {} 

 

    def detach(self, sr_uuid, vdi_uuid): 

        pass 

 

    def clone(self, sr_uuid, vdi_uuid): 

        return self.get_params() 

 

    def snapshot(self, sr_uuid, vdi_uuid): 

        return self.get_params() 

 

if __name__ == '__main__': 

    SRCommand.run(SHMSR, DRIVER_INFO) 

else: 

    SR.registerSR(SHMSR)