1081b0e1797fd777eaf6b8a5a789fd6c3e59d788
[sfa.git] / sfa / methods / PerformOperationalAction.py
1 from sfa.util.faults import SfaInvalidArgument, InvalidRSpec
2 from sfa.util.xrn import urn_to_hrn
3 from sfa.util.method import Method
4 from sfa.util.sfatablesRuntime import run_sfatables
5 from sfa.trust.credential import Credential
6 from sfa.storage.parameter import Parameter, Mixed
7
8
9 class PerformOperationalAction(Method):
10     """
11     Request that the named geni_allocated slivers be made 
12     geni_provisioned, instantiating or otherwise realizing the 
13     resources, such that they have a valid geni_operational_status 
14     and may possibly be made geni_ready for experimenter use. This 
15     operation is synchronous, but may start a longer process, such 
16     as creating and imaging a virtual machine
17
18     @param slice urns ([string]) URNs of slivers to provision to
19     @param credentials (dict) of credentials
20     @param options (dict) options
21
22     """
23     interfaces = ['aggregate', 'slicemgr']
24     accepts = [
25         Parameter(type([str]), "URNs"),
26         Parameter(type([dict]), "Credentials"),
27         Parameter(str, "Action"),
28         Parameter(dict, "Options"),
29     ]
30     returns = Parameter(dict, "Provisioned Resources")
31
32     def call(self, xrns, creds, action, options):
33         self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s" %
34                              (self.api.interface, xrns, self.name))
35
36         (speaking_for, _) = urn_to_hrn(options.get('geni_speaking_for'))
37
38         # Find the valid credentials
39         valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'createsliver', xrns,
40                                                               check_sliver_callback=self.api.driver.check_sliver_credentials,
41                                                               options=options)
42         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
43         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
44                              (self.api.interface, origin_hrn, xrns, self.name))
45         result = self.api.manager.PerformOperationalAction(
46             self.api, xrns, creds, action, options)
47         return result