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