-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtasks.py
More file actions
101 lines (76 loc) · 2.45 KB
/
tasks.py
File metadata and controls
101 lines (76 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Core Deis API functions that interact with providers and
configuration management.
This module orchestrates the real "heavy lifting" of Deis, and as such these
functions are decorated to run as asynchronous celery tasks.
"""
from __future__ import unicode_literals
import importlib
from celery import task
from deis import settings
from provider import import_provider_module
from .exceptions import BuildNodeError
# import user-defined config management module
CM = importlib.import_module(settings.CM_MODULE)
@task
def build_layer(layer):
"""
Build a layer using its cloud provider.
:param layer: a :class:`~api.models.Layer` to build
"""
provider = import_provider_module(layer.flavor.provider.type)
provider.build_layer(layer.flat())
@task
def destroy_layer(layer):
"""
Destroy a layer.
:param layer: a :class:`~api.models.Layer` to destroy
"""
provider = import_provider_module(layer.flavor.provider.type)
provider.destroy_layer(layer.flat())
layer.delete()
@task
def build_node(node):
"""
Build a node using its cloud provider.
:param node: a :class:`~api.models.Node` to build
"""
provider = import_provider_module(node.layer.flavor.provider.type)
provider_id, fqdn, metadata = provider.build_node(node.flat())
node.provider_id = provider_id
node.fqdn = fqdn
node.metadata = metadata
node.save()
try:
CM.bootstrap_node(node.flat())
except RuntimeError as err:
raise BuildNodeError(str(err))
@task
def destroy_node(node):
"""
Destroy a node.
:param node: a :class:`~api.models.Node` to destroy
"""
provider = import_provider_module(node.layer.flavor.provider.type)
provider.destroy_node(node.flat())
CM.purge_node(node.flat())
node.delete()
@task
def converge_node(node):
"""
Converge a node, aligning it with an intended configuration.
:param node: a :class:`~api.models.Node` to converge
"""
output, rc = CM.converge_node(node.flat())
return output, rc
@task
def run_node(node, command):
"""
Run a single shell command on a container on a node.
Does not support interactive commands.
:param node: a :class:`~api.models.Node` on which to run a command
"""
output, rc = CM.run_node(node.flat(), command)
if rc != 0 and 'failed to setup the container' in output:
output = '\033[35mPlease run `git push deis master` first.\033[0m\n' + output
return output, rc