-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-data-record.py
More file actions
executable file
·83 lines (66 loc) · 2.19 KB
/
create-data-record.py
File metadata and controls
executable file
·83 lines (66 loc) · 2.19 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
#!/usr/bin/env python3
import random
from pprint import pprint as pp
from nuvla.api import Api as Nuvla
from nuvla.api.resources.data import DataRecord
from nuvla.api.resources.user import User
from utils import nuvla_conf_user_pass
# Set to True to print Nuvla request / response messages to stdout.
debug = False
# Get username and password from configuration file.
username, password = nuvla_conf_user_pass()
# Create Nuvla client. No authentication required.
nuvla = Nuvla(debug=debug)
# nuvla = Nuvla(endpoint='https://localhost', insecure=True, debug=debug)
#
# Login to Nuvla.
#
user_api = User(nuvla)
user_api.login(username, password)
#
# Data record API object.
#
dr_api = DataRecord(nuvla)
#
# Add minimal data record.
#
# infrastructure-service is the only mandatory field at creation time.
dr_id = dr_api.create({}, 'infrastructure-service/1-2-3')
print('created data record:', dr_id)
assert dr_id == dr_api.delete(dr_id)
print('deleted data record:', dr_id)
#
# Add data record that describes an object on S3.
#
# s3_infra_service_id = 'infrastructure-service/09b08b49-2408-4b80-a7cc-73f420903fd5'
cred_doc = nuvla.get(s3_cred_id)
print('credential doc:', cred_doc.data['parent'])
s3_infra_service_id=cred_doc.data['parent']
if not s3_infra_service_id:
print('No infrastructure service found for the credential. Exiting.')
exit(1)
bin_object_id = 'data-object/1-2-3-4-5'
content_type = 'animals/african-lion'
data_record = {
"infrastructure-service": s3_infra_service_id,
"description": "Lions in Africa",
"name": "African Lion",
"object": "african-lion.jpg",
"bucket": "cloud.animals",
"content-type": "animals/lion", # here is where the content type is defined and the "application/taska" can be added.
"bytes": random.randint(1000, 100000),
"platform": "S3",
"another-field": "another-value", # this field will be ignored
"tags": ["zoo", "africa", "lion", "whatevs"],
}
dr_id = dr_api.add(data_record)
print('created data record:', dr_id)
pp(dr_api.get(dr_id))
#
# Delete data record.
# OR this can be commented out to keep the data record.
#
assert dr_id == dr_api.delete(dr_id)
print('deleted data record:', dr_id)
# Logs out the user.
user_api.logout()