|
11 | 11 | from environment.users.tenants import cleanup_default_tenants
|
12 | 12 | from environment.users.tenants import create_default_tenants
|
13 | 13 | from kahuna.config import ConfigLoader
|
14 |
| -from kahuna.session import ContextLoader |
15 | 14 | from org.jclouds.abiquo.domain.exception import AbiquoException
|
16 | 15 | from org.jclouds.rest import AuthorizationException
|
| 16 | +from kahuna.abstract import AbsPlugin |
17 | 17 |
|
18 | 18 |
|
19 |
| -class EnvironmentPlugin: |
20 |
| - """ Environment generator plugin """ |
| 19 | +class EnvironmentPlugin(AbsPlugin): |
| 20 | + """ Environment generator plugin. """ |
21 | 21 | def __init__(self):
|
22 | 22 | self.__config = ConfigLoader().load("env.conf", "config/env.conf")
|
23 | 23 |
|
24 |
| - def commands(self): |
25 |
| - """ Returns the available commands in this plugin """ |
26 |
| - commands = {} |
27 |
| - commands['create'] = self.create |
28 |
| - commands['clean'] = self.cleanup |
29 |
| - return commands |
30 |
| - |
31 | 24 | def create(self, args):
|
32 |
| - """ Creates the environment """ |
33 |
| - context = ContextLoader().load() |
| 25 | + """ Creates the environment. """ |
34 | 26 | try:
|
35 |
| - apply_default_configuration(self.__config, context) |
36 |
| - dc = create_infrastructure_compute(self.__config, context) |
37 |
| - create_infrastructure_storage(self.__config, context, dc) |
38 |
| - create_infrastructure_network(self.__config, context, dc) |
39 |
| - create_default_tenants(self.__config, context, dc) |
40 |
| - vdc = create_cloud_compute(self.__config, context, dc) |
41 |
| - create_cloud_storage(self.__config, context, vdc) |
| 27 | + apply_default_configuration(self.__config, self._context) |
| 28 | + dc = create_infrastructure_compute(self.__config, self._context) |
| 29 | + create_infrastructure_storage(self.__config, self._context, dc) |
| 30 | + create_infrastructure_network(self.__config, self._context, dc) |
| 31 | + create_default_tenants(self.__config, self._context, dc) |
| 32 | + vdc = create_cloud_compute(self.__config, self._context, dc) |
| 33 | + create_cloud_storage(self.__config, self._context, vdc) |
42 | 34 | except (AbiquoException, AuthorizationException), ex:
|
43 | 35 | print "Error: %s" % ex.getMessage()
|
44 |
| - finally: |
45 |
| - context.close() |
46 | 36 |
|
47 |
| - def cleanup(self, args): |
48 |
| - """ Cleans up the environment """ |
49 |
| - context = ContextLoader().load() |
| 37 | + def clean(self, args): |
| 38 | + """ Cleans up the environment. """ |
50 | 39 | try:
|
51 |
| - cleanup_cloud_compute(self.__config, context) |
52 |
| - cleanup_default_tenants(self.__config, context) |
53 |
| - cleanup_infrastructure_compute(self.__config, context) |
| 40 | + cleanup_cloud_compute(self.__config, self._context) |
| 41 | + cleanup_default_tenants(self.__config, self._context) |
| 42 | + cleanup_infrastructure_compute(self.__config, self._context) |
54 | 43 | except (AbiquoException, AuthorizationException), ex:
|
55 | 44 | print "Error: %s" % ex.getMessage()
|
56 |
| - finally: |
57 |
| - context.close() |
58 | 45 |
|
59 | 46 |
|
60 | 47 | def load():
|
|
0 commit comments