#
import re
-
from types import StringTypes
from PLC.Faults import *
from PLC.Filter import Filter
from PLC.Table import Row, Table
+from PLC.Nodes import Nodes,Node
+from PLC.Slices import Slices,Slice
+
class Peer (Row):
"""
Stores the list of peering PLCs in the peers table.
'peername' : Parameter (str, "Peer name"),
'peer_url' : Parameter (str, "Peer API url"),
'person_id' : Parameter (int, "Person_id of the account storing credentials - temporary"),
- 'node_ids' : Parameter ([int], "This peer's nodes ids")
+ 'node_ids' : Parameter ([int], "This peer's nodes ids"),
+ 'slice_ids' : Parameter ([int], "This peer's slices ids"),
}
def validate_peer_url (self, url):
assert 'peer_id' in self
+ # remove nodes depending on this peer
+ for foreign_node in Nodes (self.api, self['node_ids']):
+ foreign_node.delete(commit)
+
+ # remove the peer
self['deleted'] = True
self.sync(commit)
Maps to the peers table in the database
"""
- def __init__ (self, api, peer_filter = None):
- Table.__init__(self, api, Peer)
+ def __init__ (self, api, peer_filter = None, columns = None):
+ Table.__init__(self, api, Peer, columns)
sql = "SELECT %s FROM view_peers WHERE deleted IS False" % \
- ", ".join(Peer.fields)
+ ", ".join(self.columns)
if peer_filter is not None:
- if isinstance(peer_filter, list):
+ if isinstance(peer_filter, (list, tuple, set)):
# Separate the list into integers and strings
ints = filter(lambda x: isinstance(x, (int, long)), peer_filter)
strs = filter(lambda x: isinstance(x, StringTypes), peer_filter)