ad196692d4df8db802416c192b29e575ad12266d
[sfa.git] / sfa / methods / Provision.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 from sfa.rspecs.rspec import RSpec
8
9
10 class Provision(Method):
11     """
12     Request that the named geni_allocated slivers be made 
13     geni_provisioned, instantiating or otherwise realizing the 
14     resources, such that they have a valid geni_operational_status 
15     and may possibly be made geni_ready for experimenter use. This 
16     operation is synchronous, but may start a longer process, such 
17     as creating and imaging a virtual machine
18
19     @param slice urns ([string]) URNs of slivers to provision to
20     @param credentials (dict) of credentials
21     @param options (dict) options
22
23     """
24     interfaces = ['aggregate', 'slicemgr']
25     accepts = [
26         Parameter(type([str]), "URNs"),
27         Parameter(type([dict]), "Credentials"),
28         Parameter(dict, "options"),
29     ]
30     returns = Parameter(dict, "Provisioned Resources")
31
32     def call(self, xrns, creds, options):
33         self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s" %
34                              (self.api.interface, xrns, self.name))
35
36         # Find the valid credentials
37         valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'createsliver', xrns,
38                                                               check_sliver_callback=self.api.driver.check_sliver_credentials,
39                                                               options=options)
40         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
41         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s" %
42                              (self.api.interface, origin_hrn, xrns, self.name))
43         result = self.api.manager.Provision(self.api, xrns, creds, options)
44         return result