blind 2to3
[plcapi.git] / PLC / Methods / DeleteSite.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Sites import Site, Sites
5 from PLC.Persons import Person, Persons
6 from PLC.Nodes import Node, Nodes
7 from PLC.PCUs import PCU, PCUs
8 from PLC.Auth import Auth
9
10 class DeleteSite(Method):
11     """
12     Mark an existing site as deleted. The accounts of people who are
13     not members of at least one other non-deleted site will also be
14     marked as deleted. Nodes, PCUs, and slices associated with the
15     site will be deleted.
16
17     Returns 1 if successful, faults otherwise.
18     """
19
20     roles = ['admin']
21
22     accepts = [
23         Auth(),
24         Mixed(Site.fields['site_id'],
25               Site.fields['login_base'])
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30     def call(self, auth, site_id_or_login_base):
31         # Get account information
32         sites = Sites(self.api, [site_id_or_login_base])
33         if not sites:
34             raise PLCInvalidArgument("No such site")
35         site = sites[0]
36
37         if site['peer_id'] is not None:
38             raise PLCInvalidArgument("Not a local site")
39
40         site.delete()
41
42         # Logging variables
43         self.event_objects = {'Site': [site['site_id']]}
44         self.message = 'Site %d deleted' % site['site_id']
45
46
47         return 1