Code

1ae7362c77758afc2c2c04f8f6776aa3b52ec2bf
[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, type='localboot'):
67     result = []
69     # Load product ids
70     productIds= self.getProductIds_list(type, None, installationStatus)
71     
72     # Load product states
73     productStates= self.getProductStates_hash(objectId)
75     # Extend every entry by name and description
76     for productId in productIds:
78         # Add missing information to the productInfo
79         productInfo= self.getProduct_hash(productId)
80         productInfo['productId']= productId
82         # Find product entry
83         currentState= None
84         for state in productStates[objectId]:
85             if state['productId'] == productId:
86                 currentState= state
87                 break
89         # Add missing information to the productInfo
90         if currentState['installationStatus'] != "not_installed" or \
91             currentState['actionRequest'] == "setup":
93             # Add state for enabled products
94             productInfo['installationStatus']= currentState['installationStatus']
95             productInfo['actionRequest']= currentState['actionRequest']
97             # Add properties
98             productInfo['action']= self.getPossibleProductActions_list(productId)
100             # Load actual property values
101             propertyDefinitions= self.getProductPropertyDefinitions_listOfHashes(productId)
102             propertyValues= dict()
103             propertyDescriptions= dict()
104             propertyDefaults= dict()
105             
106             for property in propertyDefinitions:
107                 if property.has_key('values'):
108                     propertyValues[property['name']]= property['values']
109                 if property.has_key('description'):
110                     propertyDescriptions[property['name']]= property['description']
111                 if property.has_key('default'):
112                     propertyDefaults[property['name']]= property['default']
114             # Load all properties and complete with values/descriptions
115             combinedProperties= dict()
116             productProperties= self.getProductProperties_hash(productId, objectId)
117             properties= productProperties.keys()
118             for property in properties:
119                 combinedProperties[property]= dict()
120                 if propertyDescriptions.has_key(property):
121                     combinedProperties[property]['description']= propertyDescriptions[property]
122                 if propertyValues.has_key(property):
123                     combinedProperties[property]['values']= propertyValues[property]
124                 if propertyDefaults.has_key(property):
125                     combinedProperties[property]['default']= propertyDefaults[property]
126                 combinedProperties[property]['current']= productProperties[property]
128             # Add product properties to current product info
129             productInfo['properties']= combinedProperties
131         # Push information
132         result.append(productInfo)
134     return result