Skip to content

Commit 89b4678

Browse files
author
lijianguo
committed
Merge branch 'main' of github.com:drycc/helmbroker into main
2 parents cdb691a + 174a6e7 commit 89b4678

6 files changed

Lines changed: 149 additions & 154 deletions

File tree

rootfs/helmbroker/broker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
UpdateDetails, UpdateServiceSpec, DeprovisionDetails, \
1414
DeprovisionServiceSpec, LastOperation, OperationState
1515

16-
from .meta import load_instance_meta, load_binding_meta, dump_instance_meta
1716
from .utils import get_instance_path, get_chart_path, get_plan_path, \
1817
get_addon_path, get_addon_updateable, get_addon_bindable, InstanceLock, \
19-
get_instance_file
18+
get_instance_file, load_instance_meta, load_binding_meta, \
19+
dump_instance_meta, load_addons_meta
2020
from .tasks import provision, bind, deprovision, update
21-
from helmbroker.meta import load_addons_meta
2221

2322

2423
class HelmServiceBroker(ServiceBroker):

rootfs/helmbroker/cleaner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
from openbrokerapi.service_broker import OperationState
77

88
from .config import INSTANCES_PATH
9-
from .meta import load_instance_meta
109
from .tasks import deprovision
11-
from .utils import get_instance_file
10+
from .utils import get_instance_file, load_instance_meta
1211

1312
logger = logging.getLogger(__name__)
1413

rootfs/helmbroker/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import yaml
66

77
from .config import ADDONS_PATH, CONFIG_PATH
8-
from .meta import dump_addons_meta
8+
from .utils import dump_addons_meta
99

1010

1111
def download_file(url, dest):

rootfs/helmbroker/meta.py

Lines changed: 0 additions & 145 deletions
This file was deleted.

rootfs/helmbroker/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
from .celery import app
1010
from .utils import command, get_plan_path, get_chart_path, get_cred_value, \
11-
InstanceLock, get_instance_file
12-
from .meta import dump_instance_meta, dump_binding_meta, load_instance_meta
11+
InstanceLock, get_instance_file, dump_instance_meta, dump_binding_meta, \
12+
load_instance_meta
1313

1414

1515
@app.task(serializer='pickle')

rootfs/helmbroker/utils.py

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import yaml
44
import json
55
import subprocess
6+
import time
7+
8+
from jsonschema import validate
69

710
from .config import INSTANCES_PATH, ADDONS_PATH
8-
from .meta import load_addons_meta
911

1012

1113
def command(cmd, *args, output_type="text"):
@@ -23,6 +25,146 @@ def command(cmd, *args, output_type="text"):
2325
get_plan_path = lambda instance_id: os.path.join(get_instance_path(instance_id), "plan") # noqa
2426

2527

28+
INSTANCE_META_SCHEMA = {
29+
"type": "object",
30+
"properties": {
31+
"id": {"type": "string"},
32+
"details": {
33+
"type": "object",
34+
"properties": {
35+
"service_id": {"type": "string"},
36+
"plan_id": {"type": "string"},
37+
"context": {"type": "object"},
38+
"parameters": {
39+
'oneOf': [{'type': 'object'}, {'type': 'null'}]
40+
},
41+
},
42+
"required": [
43+
"service_id", "plan_id", "context"
44+
]
45+
},
46+
"last_operation": {
47+
"type": "object",
48+
"properties": {
49+
"state": {"type": "string"},
50+
"description": {"type": "string"}
51+
}
52+
},
53+
"last_modified_time": {"type": "number"}
54+
},
55+
}
56+
57+
58+
def load_instance_meta(instance_id):
59+
file = get_instance_file(instance_id)
60+
with open(file) as f:
61+
data = json.load(f)
62+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
63+
return data
64+
65+
66+
def dump_instance_meta(instance_id, data):
67+
data["last_modified_time "] = time.time()
68+
file = get_instance_file(instance_id)
69+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
70+
with open(file, "w") as f:
71+
f.write(json.dumps(data, sort_keys=True, indent=2))
72+
73+
74+
BINDING_META_SCHEMA = {
75+
"type": "object",
76+
"properties": {
77+
"id": {"type": "string"},
78+
"credentials": {
79+
"type": "object",
80+
},
81+
"last_operation": {
82+
"type": "object",
83+
"properties": {
84+
"state": {"type": "string"},
85+
"description": {"type": "string"}
86+
}
87+
},
88+
"last_modified_time": {"type": "number"}
89+
}
90+
}
91+
92+
93+
def load_binding_meta(instance_id):
94+
file = os.path.join(get_instance_path(instance_id), "binding.json")
95+
with open(file, 'r') as f:
96+
data = json.loads(f.read())
97+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
98+
return data
99+
100+
101+
def dump_binding_meta(instance_id, data):
102+
data["last_modified_time "] = time.time()
103+
file = os.path.join(get_instance_path(instance_id), "binding.json")
104+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
105+
with open(file, "w") as f:
106+
f.write(json.dumps(data, sort_keys=True, indent=2))
107+
108+
109+
ADDONS_META_SCHEMA = {
110+
"type": "object",
111+
"patternProperties": {
112+
".*": {
113+
"id": {"type": "string"},
114+
"name": {"type": "string"},
115+
"version": {"type": "string"},
116+
"bindable": {"type": "boolean"},
117+
"instances_retrievable": {"type": "boolean"},
118+
"bindings_retrievable": {"type": "boolean"},
119+
"allow_context_updates": {"type": "boolean"},
120+
"description": {"type": "string"},
121+
"tags": {"type": "string"},
122+
"requires": {"type": "array"},
123+
"metadata": {"type": "object"},
124+
"plan_updateable": {"type": "boolean"},
125+
"dashboard_client": {"type": "object"},
126+
"plans": {
127+
"type": "object",
128+
"id": {"type": "string"},
129+
"name": {"type": "string"},
130+
"description": {"type": "string"},
131+
"metadata": {"type": "object"},
132+
"free": {"type": "boolean"},
133+
"bindable": {"type": "boolean"},
134+
"binding_rotatable": {"type": "boolean"},
135+
"plan_updateable": {"type": "boolean"},
136+
"schemas": {"type": "object"},
137+
"maximum_polling_duration": {"type": "integer"},
138+
"maintenance_info": {"type": "object"},
139+
"required": [
140+
"id", "name", "description"
141+
]
142+
},
143+
"required": [
144+
"id", "name", "description", "bindable", "version", "plans"
145+
]
146+
}
147+
}
148+
}
149+
150+
151+
def load_addons_meta():
152+
file = os.path.join(ADDONS_PATH, "addons.json")
153+
with open(file, 'r') as f:
154+
data = json.loads(f.read())
155+
if not data:
156+
return {}
157+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
158+
return data
159+
160+
161+
def dump_addons_meta(data):
162+
file = os.path.join(ADDONS_PATH, "addons.json")
163+
validate(instance=data, schema=INSTANCE_META_SCHEMA)
164+
with open(file, "w") as f:
165+
f.write(json.dumps(data, sort_keys=True, indent=2))
166+
167+
26168
def get_addon_meta(service_id):
27169
services = load_addons_meta()
28170
service = [addon for addon in [addons for _, addons in services.items()]

0 commit comments

Comments
 (0)