From e98e07348e8e89400e0e4f3705f16f958e647f49 Mon Sep 17 00:00:00 2001 From: Alain Takoudjou <talino@tiolive.com> Date: Wed, 25 Mar 2015 16:39:56 +0100 Subject: [PATCH] get all ip addresses used in hosting subscription --- master/product/Vifib/Tool/SlapTool.py | 58 +++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/master/product/Vifib/Tool/SlapTool.py b/master/product/Vifib/Tool/SlapTool.py index 74c81e6c1..a3867d59b 100644 --- a/master/product/Vifib/Tool/SlapTool.py +++ b/master/product/Vifib/Tool/SlapTool.py @@ -272,6 +272,42 @@ class SlapTool(BaseTool): self._getSlapPartitionByPackingList(_assertACI(computer_partition.getObject()))) return xml_marshaller.xml_marshaller.dumps(slap_computer) + @UnrestrictedMethod + def _getHostingSubscriptionIpList(self, computer_id, computer_partition_id): + def getHostingSubscriptionInstanceList(software_instance): + pred_list = [] + if software_instance is None or software_instance.getSlapState() == 'destroy_requested': + return pred_list + else: + if software_instance.getPortalType() == 'Software Instance': + pred_list.append(software_instance) + predecessor_list = software_instance.getPredecessorValueList( + portal_type="Software Instance") + for instance in predecessor_list: + pred_list.extend(getHostingSubscriptionInstanceList(instance)) + return pred_list + + software_instance = self._getSoftwareInstanceForComputerPartition( + computer_id, computer_partition_id) + + # Search hosting subscription + hosting = software_instance.getSpecialiseValue() + while hosting and hosting.getPortalType() != "Hosting Subscription": + hosting = hosting.getSpecialiseValue() + ip_address_list = [] + for instance in getHostingSubscriptionInstanceList(hosting): + computer_partition = instance.getAggregateValue(portal_type="Computer Partition") + if not computer_partition: + continue + for internet_protocol_address in computer_partition.contentValues( + portal_type='Internet Protocol Address'): + ip_address_list.append( + (internet_protocol_address.getNetworkInterface('').decode("UTF-8"), + internet_protocol_address.getIpAddress().decode("UTF-8")) + ) + + return xml_marshaller.xml_marshaller.dumps(ip_address_list) + security.declareProtected(Permissions.AccessContentsInformation, 'getFullComputerInformation') def getFullComputerInformation(self, computer_id): @@ -298,6 +334,28 @@ class SlapTool(BaseTool): else: return result + security.declareProtected(Permissions.AccessContentsInformation, + 'getHostingSubscriptionIpList') + def getHostingSubscriptionIpList(self, computer_id, computer_partition_id): + """ + Search and return all Computer Partition IP address related to one + Hosting Subscription + """ + result = self._getHostingSubscriptionIpList(computer_id, + computer_partition_id) + + if self.REQUEST.response.getStatus() == 200: + # Keep in cache server for 7 days + self.REQUEST.response.setHeader('Cache-Control', + 'public, max-age=1, stale-if-error=604800') + self.REQUEST.response.setHeader('Vary', + 'REMOTE_USER') + self.REQUEST.response.setHeader('Last-Modified', rfc1123_date(DateTime())) + self.REQUEST.response.setBody(result) + return self.REQUEST.response + else: + return result + security.declareProtected(Permissions.AccessContentsInformation, 'getComputerPartitionCertificate') def getComputerPartitionCertificate(self, computer_id, computer_partition_id): -- 2.30.9