-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdev_samples.py
More file actions
95 lines (65 loc) · 2.61 KB
/
dev_samples.py
File metadata and controls
95 lines (65 loc) · 2.61 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
#!/usr/bin/env python
import sys
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack import service
from billingstack.samples import get_samples
from billingstack.storage import get_connection
from billingstack.openstack.common.context import get_admin_context
from billingstack.storage.impl_sqlalchemy import models
cfg.CONF.import_opt('storage_driver', 'billingstack.central',
group='service:central')
cfg.CONF.import_opt('database_connection', 'billingstack.storage.impl_sqlalchemy',
group='storage:sqlalchemy')
SAMPLES = get_samples()
def get_fixture(name, fixture=0, values={}):
f = SAMPLES[name][fixture].copy()
f.update(values)
return f
if __name__ == '__main__':
service.prepare_service(sys.argv)
conn = get_connection()
samples = get_samples()
ctxt = get_admin_context()
currencies = {}
for c in samples['currency']:
currencies[c['name']] = conn.currency_add(ctxt, c)
languages = {}
for l in samples['language']:
languages[l['name']] = conn.language_add(ctxt, l)
for method in samples['pg_method']:
conn.pg_method_add(ctxt, method)
country_data = {
"currency_name": currencies['nok']['name'],
"language_name": languages['nor']['name']}
merchant = conn.merchant_add(
ctxt, get_fixture('merchant', values=country_data))
customer = conn.customer_add(
ctxt, merchant['id'], get_fixture('customer', values=country_data))
contact_info = get_fixture('contact_info')
merchant_user = get_fixture('user')
merchant_user['username'] = 'demo_merchant'
merchant_user['contact_info'] = contact_info
merchant_user = conn.user_add(
ctxt, merchant['id'], merchant_user)
customer_user = get_fixture('user')
customer_user['username'] = 'demo_customer'
customer_user['contact_info'] = contact_info
customer_user['customer_id'] = customer['id']
customer_user = conn.user_add(
ctxt,
merchant['id'],
customer_user)
products = {}
for p in samples['product']:
products[p['name']] = conn.product_add(ctxt, merchant['id'], p)
values = {
'plan_items': [
{'product_id': products['memory']},
{'product_id': products['vcpus']},
{'product_id': products['root_disk_size']},
{'product_id': products['network.incoming.bytes']},
{'product_id': products['network.outgoing.bytes']}
]}
plan = get_fixture('plan', values=values)
conn.plan_add(ctxt, merchant['id'], get_fixture('plan'))