-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmock.py
More file actions
140 lines (97 loc) · 3.37 KB
/
mock.py
File metadata and controls
140 lines (97 loc) · 3.37 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""
Deis mock configuration management implementation for testing.
"""
from __future__ import unicode_literals
import json
import os
from deis import settings
def bootstrap_node(node):
"""
Bootstrap configuration management tools onto a node.
This is a no-op for the mock provider.
:param node: a dict containing the node's fully-qualified domain name and SSH info
"""
pass
def converge_node(node):
"""
Converge a node.
"Converge" means to change a node's configuration to match that defined by
configuration management.
This is a no-op for the mock provider.
:param node: a dict containing the node's fully-qualified domain name and SSH info
:returns: a tuple of the convergence command's (output, return_code)
"""
return '', 0
def run_node(node, command):
"""
Run a command on a node.
This is a no-op for the mock provider.
:param node: a dict containing the node's fully-qualified domain name and SSH info
:param command: the command-line to execute on the node
:returns: a tuple of the command's (output, return_code)
"""
return '', 0
def purge_node(node):
"""
Purge a node and its client from Chef configuration management.
This is a no-op for the mock provider.
:param node: a dict containing the id of a node to purge
"""
pass
def publish_user(user, data):
"""
Publish a user to configuration management.
:param user: a dict containing the username
:param data: data to store with the user
"""
path = os.path.join(settings.TEMPDIR, 'user-{username}'.format(**user))
with open(path, 'w') as f:
f.write(json.dumps(data))
def purge_user(user):
"""
Purge a user from configuration management.
:param user: a dict containing the username
"""
path = os.path.join(settings.TEMPDIR, 'user-{username}'.format(**user))
os.remove(path)
def publish_app(app, data):
"""
Publish an app to configuration management.
:param app: a dict containing the id of the app
:param data: data to store with the app
"""
path = os.path.join(settings.TEMPDIR, 'app-{id}'.format(**app))
with open(path, 'w') as f:
f.write(json.dumps(data))
def purge_app(app):
"""
Purge an app from configuration management.
:param user: a dict containing the id of the app
"""
path = os.path.join(settings.TEMPDIR, 'app-{id}'.format(**app))
os.remove(path)
def publish_formation(formation, data):
"""
Publish a formation to configuration management.
:param formation: a dict containing the id of the formation
:param data: data to store with the formation
"""
path = os.path.join(settings.TEMPDIR, 'formation-{id}'.format(**formation))
with open(path, 'w') as f:
f.write(json.dumps(data))
def purge_formation(formation):
"""
Purge a formation from configuration management.
:param formation: a dict containing the id of the formation
"""
path = os.path.join(settings.TEMPDIR, 'formation-{id}'.format(**formation))
os.remove(path)
def converge_controller():
"""
Converge this controller node.
"Converge" means to change a node's configuration to match that defined by
configuration management.
This is a no-op for the mock provider.
:returns: the output of the convergence command, in this case None
"""
return None