Пример #1
0
 def delete_if_empty(self):
     '''
     This routine checks if a DPS Client no longer hosts any Endpoint.
     If it doesn't, it unlinks itself from all the domain
     '''
     if len(self.Endpoint_Hash_MAC) != 0:
         return
     if not self.valid:
         return
     self.valid = False
     #Remove self from all DVGs
     for client_type in DpsClientType.types.keys():
         for dvg in self.DVG_Hash[client_type].values():
             DVG.tunnel_endpoint_delete(dvg, self, client_type)
     #Clear the VNID/DVG Hash
     self.DVG_Hash.clear()
     #Remove from DPS Client Collection
     DPSClient.tunnel_endpoint_delete(self.dps_client, self)
     #Remove from Domain Collection
     Domain.tunnel_endpoint_delete(self.domain, self)
     #Clear IPs
     self.ip_listv4.clear()
     self.ip_listv6.clear()
     return
Пример #2
0
 def delete_if_empty(self):
     '''
     This routine checks if a DPS Client no longer hosts any Endpoint.
     If it doesn't, it unlinks itself from all the domain
     '''
     if len(self.Endpoint_Hash_MAC) != 0:
         return
     if not self.valid:
         return
     self.valid = False
     #Remove self from all DVGs
     for client_type in DpsClientType.types.keys():
         for dvg in self.DVG_Hash[client_type].values():
             DVG.tunnel_endpoint_delete(dvg, self, client_type)
     #Clear the VNID/DVG Hash
     self.DVG_Hash.clear()
     #Remove from DPS Client Collection
     DPSClient.tunnel_endpoint_delete(self.dps_client, self)
     #Remove from Domain Collection
     Domain.tunnel_endpoint_delete(self.domain, self)
     #Clear IPs
     self.ip_listv4.clear()
     self.ip_listv6.clear()
     return
Пример #3
0
 def ip_delete(self, dvg, client_type, inet_type, ip_value):
     '''
     This deletes a tunnel IP address from a DVG and client type
     @param dvg: The DVG on which this registration occurred
     @type dvg: DVG
     @param client_type: The Type of Client: should be in DpsClientType.types
     @type client_type: Integer 
     @param inet_type: AF_INET or AF_INET6
     @type inet_type: Integer
     @param ip_value: The IP address value
     @type ip_value: Integer or String
     '''
     fdeleteVNID = False
     fdeleteIP = False
     while True:
         try:
             client_type_value = DpsClientType.types[client_type]
         except Exception:
             break
         try:
             vnid_hash_ip = self.VNID_Hash_IP[client_type][dvg.unique_id]
             del vnid_hash_ip[ip_value]
             if len(vnid_hash_ip) == 0:
                 del self.VNID_Hash_IP[client_type][dvg.unique_id]
                 fdeleteVNID = True
         except Exception:
             pass
         try:
             ip_hash_vnid = self.IP_Hash_VNID[client_type][ip_value]
             del ip_hash_vnid[dvg.unique_id]
             if len(ip_hash_vnid) == 0:
                 del self.IP_Hash_VNID[client_type][ip_value]
                 fdeleteIP = True
         except Exception:
             pass
         if fdeleteVNID:
             #Remove Tunnel from DVG
             DVG.tunnel_endpoint_delete(dvg, self, client_type)
             try:
                 del self.DVG_Hash[client_type][dvg.unique_id]
                 if len(self.DVG_Hash[client_type]) == 0:
                     #print 'Delete all Endpoints with client_type %s\r'%client_type_value
                     self.delete_client_type(client_type)
             except Exception:
                 pass
         if not fdeleteIP:
             break
         if fdeleteIP:
             #Remove only the IP from the DVG
             DVG.tunnel_endpoint_delete_IP(dvg, client_type, inet_type, ip_value)
         #Check if IP is present in any client type
         ip_present = False
         for ctype in self.IP_Hash_VNID.keys():
             try:
                 ip_hash_vnid = self.IP_Hash_VNID[ctype][ip_value]
                 ip_present = True
                 break
             except Exception:
                 continue
         if ip_present:
             break
         #Actually delete the IP from Domain and DPS Clients since no DVGs have it
         if inet_type == socket.AF_INET:
             self.ip_listv4.remove(inet_type, ip_value)
         elif inet_type == socket.AF_INET6:
             self.ip_listv6.remove(inet_type, ip_value)
         #Remove IP to DPS Client
         DPSClient.tunnel_endpoint_delete_IP(self.dps_client, inet_type, ip_value)
         #Remove IP from Domain
         Domain.tunnel_endpoint_delete_IP(self.domain, inet_type, ip_value)
         #Delete Self if not IP Addresses are present
         if self.ip_listv4.count() == 0 and self.ip_listv6.count() == 0:
             self.delete()
         break
     return
Пример #4
0
 def ip_delete(self, dvg, client_type, inet_type, ip_value):
     '''
     This deletes a tunnel IP address from a DVG and client type
     @param dvg: The DVG on which this registration occurred
     @type dvg: DVG
     @param client_type: The Type of Client: should be in DpsClientType.types
     @type client_type: Integer 
     @param inet_type: AF_INET or AF_INET6
     @type inet_type: Integer
     @param ip_value: The IP address value
     @type ip_value: Integer or String
     '''
     fdeleteVNID = False
     fdeleteIP = False
     while True:
         try:
             client_type_value = DpsClientType.types[client_type]
         except Exception:
             break
         try:
             vnid_hash_ip = self.VNID_Hash_IP[client_type][dvg.unique_id]
             del vnid_hash_ip[ip_value]
             if len(vnid_hash_ip) == 0:
                 del self.VNID_Hash_IP[client_type][dvg.unique_id]
                 fdeleteVNID = True
         except Exception:
             pass
         try:
             ip_hash_vnid = self.IP_Hash_VNID[client_type][ip_value]
             del ip_hash_vnid[dvg.unique_id]
             if len(ip_hash_vnid) == 0:
                 del self.IP_Hash_VNID[client_type][ip_value]
                 fdeleteIP = True
         except Exception:
             pass
         if fdeleteVNID:
             #Remove Tunnel from DVG
             DVG.tunnel_endpoint_delete(dvg, self, client_type)
             try:
                 del self.DVG_Hash[client_type][dvg.unique_id]
                 if len(self.DVG_Hash[client_type]) == 0:
                     #print 'Delete all Endpoints with client_type %s\r'%client_type_value
                     self.delete_client_type(client_type)
             except Exception:
                 pass
         if not fdeleteIP:
             break
         if fdeleteIP:
             #Remove only the IP from the DVG
             DVG.tunnel_endpoint_delete_IP(dvg, client_type, inet_type,
                                           ip_value)
         #Check if IP is present in any client type
         ip_present = False
         for ctype in self.IP_Hash_VNID.keys():
             try:
                 ip_hash_vnid = self.IP_Hash_VNID[ctype][ip_value]
                 ip_present = True
                 break
             except Exception:
                 continue
         if ip_present:
             break
         #Actually delete the IP from Domain and DPS Clients since no DVGs have it
         if inet_type == socket.AF_INET:
             self.ip_listv4.remove(inet_type, ip_value)
         elif inet_type == socket.AF_INET6:
             self.ip_listv6.remove(inet_type, ip_value)
         #Remove IP to DPS Client
         DPSClient.tunnel_endpoint_delete_IP(self.dps_client, inet_type,
                                             ip_value)
         #Remove IP from Domain
         Domain.tunnel_endpoint_delete_IP(self.domain, inet_type, ip_value)
         #Delete Self if not IP Addresses are present
         if self.ip_listv4.count() == 0 and self.ip_listv6.count() == 0:
             self.delete()
         break
     return