Code

Updated getFullProductHostInformation to handle non objectID elements, too
[gosa.git] / gosa-si / contrib / 90_gosa.conf
1 ''' Add a couple of additional functions to retrieve needed information with
2     just one call. '''
4 logger= Logger()
6 def getClientsInformation_listOfHashes(self, serverId=None, depotIds=[], groupId=None, productId=None, installationStatus=None, actionRequest=None, productVersion=None, packageVersion=None):
8     # Get backend instance and load client list
9     bi= self.backends[self.clientManagingBackend]['instance']
10     clients= bi.getClients_listOfHashes(serverId, depotIds, groupId, productId, installationStatus, actionRequest, productVersion, packageVersion)
12     # Get MAC and IP for every client
13     for client in clients:
14         client['macAddress']= bi.getMacAddress(client['hostId'])
16     return clients
20 def getProductHostInformation_list(self, objectId=None, installationStatus=None, type='localboot'):
21     result = []
23     # Generate a dictionary for faster lookup of product IDs
24     products= {}
25     productIds= self.getProductIds_list(type, objectId, installationStatus)
26     for productId in productIds:
27         products[productId]= 1
29     # Load product states
30     productStates= self.getProductStates_hash(objectId)
32     # Extend every entry by name and description
33     for product in productStates[objectId]:
34         if not products.has_key(product['productId']):
35             continue
37          # Add missing information to the productInfo
38         if product['installationStatus'] != "not_installed" or product['actionRequest'] == "setup":
39             productInfo= self.getProduct_hash(product['productId'])
40             productInfo['installationStatus']= product['installationStatus']
41             productInfo['actionRequest']= product['actionRequest']
42             productInfo['productId']= product['productId']
43             result.append(productInfo)
45     return result
49 def getProductInformation_list(self, installationStatus=None, type='localboot'):
50     result = []
52     # Generate a dictionary for faster lookup of product IDs
53     productIds= self.getProductIds_list(type, None, installationStatus)
55     # Extend every entry by name and description
56     for productId in productIds:
58          # Add missing information to the productInfo
59          productInfo= self.getProduct_hash(productId)
60          productInfo['productId']= productId
61          result.append(productInfo)
63     return result
66 def getFullProductHostInformation_list(self, objectId=None, installationStatus=None):
67     result = []
69     types = ['localboot','netboot']
70     for type in types:
72         # Load product ids
73         productIds= self.getProductIds_list(type, None, installationStatus)
74         
75         # Load product states
76         if objectId != None:
77             productStates= self.getProductStates_hash(objectId)
79         # Extend every entry by name and description
80         for productId in productIds:
82             # Add missing information to the productInfo
83             productInfo= self.getProduct_hash(productId)
84             productInfo['productId']= productId
85             productInfo['type']= type;
87             # Find product entry
88             currentState= None
89             if objectId != None:
90                 for state in productStates[objectId]:
91                     if state['productId'] == productId:
92                         currentState= state
93                         break
94             else:
95                 state = {}
96                 state['installationStatus'] = "not_installed"
97                 state['actionRequest'] = "none"
98                 currentState= state
100             # Add missing information to the productInfo
101             if currentState['installationStatus'] != "not_installed" or \
102                 currentState['actionRequest'] == "setup":
104                 # Add state for enabled products
105                 productInfo['installationStatus']= currentState['installationStatus']
106                 productInfo['actionRequest']= currentState['actionRequest']
108                 # Add properties
109                 productInfo['action']= self.getPossibleProductActions_list(productId)
111                 # Load actual property values
112                 propertyDefinitions= self.getProductPropertyDefinitions_listOfHashes(productId)
113                 propertyValues= dict()
114                 propertyDescriptions= dict()
115                 propertyDefaults= dict()
116                 
117                 for property in propertyDefinitions:
118                     if property.has_key('values'):
119                         propertyValues[property['name']]= property['values']
120                     if property.has_key('description'):
121                         propertyDescriptions[property['name']]= property['description']
122                     if property.has_key('default'):
123                         propertyDefaults[property['name']]= property['default']
125                 # Load all properties and complete with values/descriptions
126                 combinedProperties= dict()
127                 productProperties= self.getProductProperties_hash(productId, objectId)
128                 properties= productProperties.keys()
129                 for property in properties:
130                     combinedProperties[property]= dict()
131                     if propertyDescriptions.has_key(property):
132                         combinedProperties[property]['description']= propertyDescriptions[property]
133                     if propertyValues.has_key(property):
134                         combinedProperties[property]['values']= propertyValues[property]
135                     if propertyDefaults.has_key(property):
136                         combinedProperties[property]['default']= propertyDefaults[property]
137                     combinedProperties[property]['current']= productProperties[property]
139                 # Add product properties to current product info
140                 productInfo['properties']= combinedProperties
142             # Push information
143             result.append(productInfo)
145     return result