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