Package pyvb :: Module hdd
[hide private]
[frames] | no frames]

Source Code for Module pyvb.hdd

  1  """ 
  2  hdd - pyvb module that holds the implementation of HDD related abstractions. 
  3  """ 
  4  from pyvb.constants import * 
  5  from pyvb.parser import * 
  6   
7 -class vbHddParser(vbParser):
8 """A parser for parsing the command line output related to HDDs."""
9 - def __init__(self):
10 """Constructor. Initialize the found attributes dictionary as 11 well as the attributes we are looking for. 12 @return: A new L{pyvb.hdd.vbHddParser} instance. 13 @rtype: L{pyvb.hdd.vbHddParser}""" 14 self.found_attributes={} 15 self.attributes={'uuid':VB_RE_UUID,\ 16 'storagetype':VB_RE_STORAGETYPE,\ 17 'path':VB_RE_PATH,\ 18 'accessible':VB_RE_ACCESSIBLE,\ 19 'usage':VB_RE_USAGE}
20
21 - def parse(self, file):
22 """Parse the specified file and return a list of results. 23 @param file: The file to parse. 24 @type file: File/List 25 @return: A list of L{pyvb.hdd.vbHdd} instances. 26 @rtype: List""" 27 hdds=[] 28 for result in self._parse(file): 29 found_hdd=vbHdd() 30 try: 31 found_hdd.setUUID(result['uuid']) 32 except KeyError: 33 pass 34 try: 35 found_hdd.setStoragetype(result['storagetype']) 36 except KeyError: 37 pass 38 try: 39 found_hdd.setPath(result['path']) 40 except KeyError: 41 pass 42 try: 43 found_hdd.setAccessible(result['accessible']) 44 except KeyError: 45 pass 46 try: 47 found_hdd.setUsage(result['usage']) 48 except KeyError: 49 pass 50 hdds.append(found_hdd) 51 return hdds
52
53 - def parseSingle(self, file):
54 self.removeAttribute('usage') 55 hdds=[] 56 for result in self._parse(file): 57 found_hdd=vbHdd(uuid=result['uuid'],\ 58 storagetype=result['storagetype'],\ 59 path=result['path'],\ 60 accessible=result['accessible']) 61 hdds.append(found_hdd) 62 return hdds
63
64 -class vbHdd:
65 """An abstraction representing an HDD in VirtualBox."""
66 - def __init__(self, **kw):
67 """Constructor. Initialize the attributes. 68 @return: A new L{pyvb.hdd.vbHdd} instance. 69 @rtype: L{pyvb.hdd.vbHdd}""" 70 try: 71 self.setUUID(kw['uuid']) 72 except KeyError: 73 self.setUUID('') 74 try: 75 self.setStoragetype(kw['storagetype']) 76 except KeyError: 77 self.setStoragetype('') 78 try: 79 self.setPath(kw['path']) 80 except KeyError: 81 self.setPath('') 82 try: 83 self.setAccessible(kw['accessible']) 84 except KeyError: 85 self.setAccessible('') 86 try: 87 self.setUsage(kw['usage']) 88 except KeyError: 89 self.setUsage('') 90 try: 91 self.setRegistered(kw['registered']) 92 except KeyError: 93 self.setRegistered('') 94 try: 95 self.setSize(kw['size']) 96 except KeyError: 97 self.setSize('') 98 try: 99 self.setDiskSize(kw['disksize']) 100 except KeyError: 101 self.setDiskSize('')
102
103 - def setUUID(self, uuid):
104 """Set the uuid attribute of this L{pyvb.hdd.vbHdd} instance. 105 @param uuid: The uuid attribute. 106 @type uuid: String 107 @return: None 108 @rtype: None""" 109 self.uuid=uuid
110
111 - def setStoragetype(self, storagetype):
112 """Set the storagetype attribute of this L{pyvb.hdd.vbHdd} instance. 113 @param storagetype: The storagetype attribute. 114 @type storagetype: String 115 @return: None 116 @rtype: None""" 117 self.storagetype=storagetype
118
119 - def setPath(self, path):
120 """Set the path attribute of this L{pyvb.hdd.vbHdd} instance. 121 @param path: The path attribute. 122 @type path: String 123 @return: None 124 @rtype: None""" 125 self.path=path
126
127 - def setAccessible(self, accessible):
128 """Set the accessible attribute of this L{pyvb.hdd.vbHdd} instance. 129 @param accessible: The accessible attribute. 130 @type accessible: String 131 @return: None 132 @rtype: None""" 133 self.accessible=accessible
134
135 - def setUsage(self, usage):
136 """Set the usage attribute of this L{pyvb.hdd.vbHdd} instance. 137 @param usage: The usage attribute. 138 @type usage: String 139 @return: None 140 @rtype: None""" 141 self.usage=usage
142
143 - def setRegistered(self, registered):
144 self.registered=registered
145
146 - def setSize(self, size):
147 self.size=size
148
149 - def setDiskSize(self, disksize):
150 self.disksize=disksize
151
152 - def getUUID(self):
153 """Return the uuid attribute of this L{pyvb.hdd.vbHdd} instance. 154 @return: The uuid attribute. 155 @rtype: String""" 156 return self.uuid
157
158 - def getStoragetype(self):
159 """Return the storagetype attribute of this L{pyvb.hdd.vbHdd} instance. 160 @return: The storagetype attribute. 161 @rtype: String""" 162 return self.storagetype
163
164 - def getPath(self):
165 """Return the path attribute of this L{pyvb.hdd.vbHdd} instance. 166 @return: The path attribute. 167 @rtype: String""" 168 return self.path
169
170 - def getAccessible(self):
171 """Return the accessible attribute of this L{pyvb.hdd.vbHdd} instance. 172 @return: The accessible attribute. 173 @rtype: String""" 174 return self.accessible
175
176 - def getUsage(self):
177 """Return the usage attribute of this L{pyvb.hdd.vbHdd} instance. 178 @return: The usage attribute. 179 @rtype: String""" 180 return self.usage
181
182 - def getRegistered(self):
183 return self.registered
184
185 - def getSize(self):
186 return self.size
187
188 - def getDiskSize(self):
189 return self.disksize
190