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