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