2 # Thierry Parmentelat - INRIA
4 # utility to clear all entries from a peer
5 # initially duplicated from RefreshPeer
10 from PLC.Logger import logger
11 from PLC.Faults import *
12 from PLC.Method import Method
13 from PLC.Parameter import Parameter, Mixed
14 from PLC.Auth import Auth
16 from PLC.Peers import Peer, Peers
17 from PLC.Sites import Site, Sites
18 from PLC.Persons import Person, Persons
19 from PLC.KeyTypes import KeyType, KeyTypes
20 from PLC.Keys import Key, Keys
21 from PLC.BootStates import BootState, BootStates
22 from PLC.Nodes import Node, Nodes
23 from PLC.SliceInstantiations import SliceInstantiations
24 from PLC.Slices import Slice, Slices
25 from PLC.Roles import Role, Roles
35 def message(to_print=None, verbose_only=False):
36 if verbose_only and not verbose:
41 def message_verbose(to_print=None, header='VERBOSE'):
42 message("{}> {}".format(header, to_print), verbose_only=True)
45 class DeleteAllPeerEntries(Method):
47 This method is designed for situations where a federation link
48 is misbehaving and one wants to restart from a clean slate.
49 It is *not* designed for regular operations, but as a repairing
52 As the name suggests, clear all local entries that are marked as
53 belonging to peer peer_id - or peername
54 if verbose is True said entries are only printed
56 Note that remote/foreign entities cannot be deleted
59 Returns 1 if successful, faults otherwise.
66 Mixed(Peer.fields['peer_id'],
67 Peer.fields['peername']),
70 returns = Parameter(int, "1 if successful")
72 def call(self, auth, peer_id_or_peername):
74 peer = Peers(self.api, [peer_id_or_peername])[0]
75 peer_id = peer['peer_id']
76 peername = peer['peername']
78 logger.info("DeleteAllPeerEntries on peer {} = {}"
79 .format(peername, peer_id))
80 for singular, plural in (
86 classname = singular.__name__
87 objs = plural(self.api, {'peer_id': peer_id})
88 print("Found {len} {classname}s from peer {peername}"
89 .format(len=len(objs),
93 print("dry-run mode: skipping actual deletion")
95 print("Deleting {classname}s".format(classname=classname))
99 obj.delete(commit=commit_mode)
102 # Update peer itself and commit
103 peer.sync(commit=True)