7177854d70b9849c7d7c7fa2f8a761f922568f18
[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 class Provision(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(dict, "options"),
28         ]
29     returns = Parameter(dict, "Provisioned Resources")
30
31     def call(self, xrns, creds, options):
32         self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, xrns, self.name))
33
34         # Find the valid credentials
35         valid_creds = self.api.auth.checkCredentialsSpeaksFor(creds, 'createsliver', xrns,
36                                                               check_sliver_callback = self.api.driver.check_sliver_credentials,
37                                                               options=options)
38         origin_hrn = Credential(cred=valid_creds[0]).get_gid_caller().get_hrn()
39         self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, xrns, self.name))
40         result = self.api.manager.Provision(self.api, xrns, creds, options)
41         return result