1and1 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/1and1-1.0.gem +0 -0
- data/1and1.gemspec +20 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +499 -0
- data/docs/reference.md +2447 -0
- data/examples/dvd_examples.rb +15 -0
- data/examples/example_app.rb +100 -0
- data/examples/firewall_examples.rb +137 -0
- data/examples/image_examples.rb +48 -0
- data/examples/load_balancer_examples.rb +145 -0
- data/examples/log_examples.rb +15 -0
- data/examples/monitoring_center_examples.rb +15 -0
- data/examples/monitoring_policy_examples.rb +343 -0
- data/examples/private_network_examples.rb +86 -0
- data/examples/public_ip_examples.rb +42 -0
- data/examples/role_examples.rb +113 -0
- data/examples/server_appliance_examples.rb +15 -0
- data/examples/server_examples.rb +438 -0
- data/examples/shared_storage_examples.rb +108 -0
- data/examples/usage_examples.rb +6 -0
- data/examples/user_examples.rb +113 -0
- data/examples/vpn_examples.rb +56 -0
- data/lib/1and1/datacenter.rb +73 -0
- data/lib/1and1/dvd.rb +73 -0
- data/lib/1and1/firewall.rb +427 -0
- data/lib/1and1/image.rb +231 -0
- data/lib/1and1/load_balancer.rb +448 -0
- data/lib/1and1/log.rb +77 -0
- data/lib/1and1/monitoring_center.rb +84 -0
- data/lib/1and1/monitoring_policy.rb +598 -0
- data/lib/1and1/oneandone.rb +57 -0
- data/lib/1and1/ping.rb +41 -0
- data/lib/1and1/ping_auth.rb +41 -0
- data/lib/1and1/pricing.rb +41 -0
- data/lib/1and1/private_network.rb +333 -0
- data/lib/1and1/public_ip.rb +192 -0
- data/lib/1and1/role.rb +381 -0
- data/lib/1and1/server.rb +1208 -0
- data/lib/1and1/server_appliance.rb +73 -0
- data/lib/1and1/shared_storage.rb +379 -0
- data/lib/1and1/usage.rb +58 -0
- data/lib/1and1/user.rb +374 -0
- data/lib/1and1/vpn.rb +249 -0
- data/lib/oneandone.rb +27 -0
- data/sphinx/Makefile +192 -0
- data/sphinx/_build/doctrees/dvds.doctree +0 -0
- data/sphinx/_build/doctrees/environment.pickle +0 -0
- data/sphinx/_build/doctrees/firewalls.doctree +0 -0
- data/sphinx/_build/doctrees/images.doctree +0 -0
- data/sphinx/_build/doctrees/index.doctree +0 -0
- data/sphinx/_build/doctrees/load_balancers.doctree +0 -0
- data/sphinx/_build/doctrees/logs.doctree +0 -0
- data/sphinx/_build/doctrees/monitoring_center.doctree +0 -0
- data/sphinx/_build/doctrees/monitoring_policies.doctree +0 -0
- data/sphinx/_build/doctrees/private_networks.doctree +0 -0
- data/sphinx/_build/doctrees/public_ips.doctree +0 -0
- data/sphinx/_build/doctrees/server_appliances.doctree +0 -0
- data/sphinx/_build/doctrees/servers.doctree +0 -0
- data/sphinx/_build/doctrees/shared_storages.doctree +0 -0
- data/sphinx/_build/doctrees/usages.doctree +0 -0
- data/sphinx/_build/doctrees/users.doctree +0 -0
- data/sphinx/_build/html/.buildinfo +4 -0
- data/sphinx/_build/html/_sources/dvds.txt +42 -0
- data/sphinx/_build/html/_sources/firewalls.txt +189 -0
- data/sphinx/_build/html/_sources/images.txt +101 -0
- data/sphinx/_build/html/_sources/index.txt +499 -0
- data/sphinx/_build/html/_sources/load_balancers.txt +231 -0
- data/sphinx/_build/html/_sources/logs.txt +55 -0
- data/sphinx/_build/html/_sources/monitoring_center.txt +55 -0
- data/sphinx/_build/html/_sources/monitoring_policies.txt +288 -0
- data/sphinx/_build/html/_sources/private_networks.txt +146 -0
- data/sphinx/_build/html/_sources/public_ips.txt +78 -0
- data/sphinx/_build/html/_sources/server_appliances.txt +42 -0
- data/sphinx/_build/html/_sources/servers.txt +630 -0
- data/sphinx/_build/html/_sources/shared_storages.txt +160 -0
- data/sphinx/_build/html/_sources/usages.txt +45 -0
- data/sphinx/_build/html/_sources/users.txt +172 -0
- data/sphinx/_build/html/_static/ajax-loader.gif +0 -0
- data/sphinx/_build/html/_static/alabaster.css +585 -0
- data/sphinx/_build/html/_static/basic.css +599 -0
- data/sphinx/_build/html/_static/comment-bright.png +0 -0
- data/sphinx/_build/html/_static/comment-close.png +0 -0
- data/sphinx/_build/html/_static/comment.png +0 -0
- data/sphinx/_build/html/_static/doctools.js +263 -0
- data/sphinx/_build/html/_static/down-pressed.png +0 -0
- data/sphinx/_build/html/_static/down.png +0 -0
- data/sphinx/_build/html/_static/file.png +0 -0
- data/sphinx/_build/html/_static/jquery-1.11.1.js +10308 -0
- data/sphinx/_build/html/_static/jquery.js +4 -0
- data/sphinx/_build/html/_static/minus.png +0 -0
- data/sphinx/_build/html/_static/plus.png +0 -0
- data/sphinx/_build/html/_static/pygments.css +63 -0
- data/sphinx/_build/html/_static/searchtools.js +651 -0
- data/sphinx/_build/html/_static/underscore-1.3.1.js +999 -0
- data/sphinx/_build/html/_static/underscore.js +31 -0
- data/sphinx/_build/html/_static/up-pressed.png +0 -0
- data/sphinx/_build/html/_static/up.png +0 -0
- data/sphinx/_build/html/_static/websupport.js +808 -0
- data/sphinx/_build/html/dvds.html +151 -0
- data/sphinx/_build/html/firewalls.html +397 -0
- data/sphinx/_build/html/genindex.html +114 -0
- data/sphinx/_build/html/images.html +236 -0
- data/sphinx/_build/html/index.html +571 -0
- data/sphinx/_build/html/load_balancers.html +409 -0
- data/sphinx/_build/html/logs.html +160 -0
- data/sphinx/_build/html/monitoring_center.html +160 -0
- data/sphinx/_build/html/monitoring_policies.html +530 -0
- data/sphinx/_build/html/objects.inv +0 -0
- data/sphinx/_build/html/private_networks.html +316 -0
- data/sphinx/_build/html/public_ips.html +215 -0
- data/sphinx/_build/html/rb-modindex.html +106 -0
- data/sphinx/_build/html/search.html +99 -0
- data/sphinx/_build/html/searchindex.js +1 -0
- data/sphinx/_build/html/server_appliances.html +153 -0
- data/sphinx/_build/html/servers.html +994 -0
- data/sphinx/_build/html/shared_storages.html +349 -0
- data/sphinx/_build/html/usages.html +140 -0
- data/sphinx/_build/html/users.html +363 -0
- data/sphinx/conf.py +287 -0
- data/sphinx/dvds.rst +42 -0
- data/sphinx/firewalls.rst +189 -0
- data/sphinx/images.rst +101 -0
- data/sphinx/index.rst +499 -0
- data/sphinx/load_balancers.rst +231 -0
- data/sphinx/logs.rst +55 -0
- data/sphinx/make.bat +263 -0
- data/sphinx/monitoring_center.rst +55 -0
- data/sphinx/monitoring_policies.rst +288 -0
- data/sphinx/private_networks.rst +146 -0
- data/sphinx/public_ips.rst +78 -0
- data/sphinx/server_appliances.rst +42 -0
- data/sphinx/servers.rst +630 -0
- data/sphinx/shared_storages.rst +160 -0
- data/sphinx/usages.rst +45 -0
- data/sphinx/users.rst +172 -0
- data/test/mock-api/add-firewall.json +66 -0
- data/test/mock-api/add-hdd.json +49 -0
- data/test/mock-api/add-lb.json +71 -0
- data/test/mock-api/add-new-ip.json +18 -0
- data/test/mock-api/add-pn.json +66 -0
- data/test/mock-api/add-port-mp.json +81 -0
- data/test/mock-api/add-process-mp.json +20 -0
- data/test/mock-api/add-rule-fp.json +33 -0
- data/test/mock-api/add-rule-lb.json +40 -0
- data/test/mock-api/add-server-ip.json +66 -0
- data/test/mock-api/add-server-mp.json +66 -0
- data/test/mock-api/assign-ip-fp.json +32 -0
- data/test/mock-api/assign-server-lb.json +39 -0
- data/test/mock-api/attach-server-pn.json +14 -0
- data/test/mock-api/attach-server-storage.json +24 -0
- data/test/mock-api/change-api-key.json +15 -0
- data/test/mock-api/change-password.json +5 -0
- data/test/mock-api/change-server-status.json +70 -0
- data/test/mock-api/clone-server.json +29 -0
- data/test/mock-api/create-fp.json +26 -0
- data/test/mock-api/create-image.json +30 -0
- data/test/mock-api/create-lb.json +33 -0
- data/test/mock-api/create-mp.json +81 -0
- data/test/mock-api/create-pn.json +11 -0
- data/test/mock-api/create-public-ip.json +10 -0
- data/test/mock-api/create-server.json +34 -0
- data/test/mock-api/create-snapshot.json +74 -0
- data/test/mock-api/create-storage.json +13 -0
- data/test/mock-api/create-user.json +14 -0
- data/test/mock-api/delete-fp.json +26 -0
- data/test/mock-api/delete-image.json +26 -0
- data/test/mock-api/delete-ip.json +15 -0
- data/test/mock-api/delete-lb.json +33 -0
- data/test/mock-api/delete-mp.json +71 -0
- data/test/mock-api/delete-pn.json +11 -0
- data/test/mock-api/delete-public-ip.json +10 -0
- data/test/mock-api/delete-rule-fp.json +26 -0
- data/test/mock-api/delete-server.json +50 -0
- data/test/mock-api/delete-snapshot.json +74 -0
- data/test/mock-api/delete-storage.json +24 -0
- data/test/mock-api/delete-user.json +15 -0
- data/test/mock-api/detach-server-lb.json +33 -0
- data/test/mock-api/detach-server-mp.json +65 -0
- data/test/mock-api/detach-server-storage.json +19 -0
- data/test/mock-api/edit-image.json +26 -0
- data/test/mock-api/eject-dvd.json +66 -0
- data/test/mock-api/fixed-server-flavors.json +70 -0
- data/test/mock-api/get-appliance.json +16 -0
- data/test/mock-api/get-dvd.json +9 -0
- data/test/mock-api/get-firewall.json +26 -0
- data/test/mock-api/get-fixed-server.json +17 -0
- data/test/mock-api/get-fp-rule.json +7 -0
- data/test/mock-api/get-hardware.json +13 -0
- data/test/mock-api/get-hdd.json +5 -0
- data/test/mock-api/get-image.json +26 -0
- data/test/mock-api/get-lb-rule.json +7 -0
- data/test/mock-api/get-lb-server.json +5 -0
- data/test/mock-api/get-load-balancer.json +33 -0
- data/test/mock-api/get-log.json +23 -0
- data/test/mock-api/get-monitoring-center.json +161 -0
- data/test/mock-api/get-mp-port.json +7 -0
- data/test/mock-api/get-mp-process.json +6 -0
- data/test/mock-api/get-mp-server.json +4 -0
- data/test/mock-api/get-mp.json +65 -0
- data/test/mock-api/get-pn-server.json +4 -0
- data/test/mock-api/get-private-network.json +20 -0
- data/test/mock-api/get-public-ip.json +10 -0
- data/test/mock-api/get-server-dvd.json +4 -0
- data/test/mock-api/get-server-image.json +4 -0
- data/test/mock-api/get-server-ip-fp.json +4 -0
- data/test/mock-api/get-server-ip.json +8 -0
- data/test/mock-api/get-server-pn.json +16 -0
- data/test/mock-api/get-server-status.json +4 -0
- data/test/mock-api/get-server-storage.json +5 -0
- data/test/mock-api/get-server.json +44 -0
- data/test/mock-api/get-storage.json +19 -0
- data/test/mock-api/get-usage.json +161 -0
- data/test/mock-api/get-user-api-key.json +3 -0
- data/test/mock-api/get-user-api.json +7 -0
- data/test/mock-api/get-user.json +15 -0
- data/test/mock-api/list-appliances.json +66 -0
- data/test/mock-api/list-credentials.json +5 -0
- data/test/mock-api/list-dvds.json +128 -0
- data/test/mock-api/list-firewalls.json +54 -0
- data/test/mock-api/list-fp-rules.json +16 -0
- data/test/mock-api/list-hdds.json +7 -0
- data/test/mock-api/list-images.json +54 -0
- data/test/mock-api/list-lb-rules.json +16 -0
- data/test/mock-api/list-lb-servers.json +12 -0
- data/test/mock-api/list-load-balancers.json +68 -0
- data/test/mock-api/list-logs.json +49 -0
- data/test/mock-api/list-monitoring-center-usages.json +90 -0
- data/test/mock-api/list-mp-ports.json +16 -0
- data/test/mock-api/list-mp-processes.json +14 -0
- data/test/mock-api/list-mp-servers.json +10 -0
- data/test/mock-api/list-mps.json +152 -0
- data/test/mock-api/list-pn-servers.json +10 -0
- data/test/mock-api/list-private-networks.json +24 -0
- data/test/mock-api/list-public-ips.json +44 -0
- data/test/mock-api/list-server-fps.json +4 -0
- data/test/mock-api/list-server-ips-fp.json +7 -0
- data/test/mock-api/list-server-ips.json +10 -0
- data/test/mock-api/list-server-lbs.json +6 -0
- data/test/mock-api/list-server-pns.json +6 -0
- data/test/mock-api/list-servers.json +66 -0
- data/test/mock-api/list-snapshots.json +7 -0
- data/test/mock-api/list-storages.json +47 -0
- data/test/mock-api/list-usages.json +144 -0
- data/test/mock-api/list-user-ips.json +5 -0
- data/test/mock-api/list-users.json +31 -0
- data/test/mock-api/load-dvd.json +63 -0
- data/test/mock-api/modify-fp.json +26 -0
- data/test/mock-api/modify-lb.json +33 -0
- data/test/mock-api/modify-mp.json +81 -0
- data/test/mock-api/modify-pn.json +20 -0
- data/test/mock-api/modify-port-mp.json +81 -0
- data/test/mock-api/modify-process-mp.json +73 -0
- data/test/mock-api/modify-public-ip.json +10 -0
- data/test/mock-api/modify-server-hardware.json +44 -0
- data/test/mock-api/modify-server-hdd.json +54 -0
- data/test/mock-api/modify-server.json +44 -0
- data/test/mock-api/modify-storage.json +19 -0
- data/test/mock-api/modify-user-api.json +15 -0
- data/test/mock-api/modify-user.json +15 -0
- data/test/mock-api/reinstall-image.json +52 -0
- data/test/mock-api/remove-firewall-policy.json +26 -0
- data/test/mock-api/remove-hdd.json +54 -0
- data/test/mock-api/remove-ip-fp.json +26 -0
- data/test/mock-api/remove-lb.json +66 -0
- data/test/mock-api/remove-pn.json +71 -0
- data/test/mock-api/remove-port-mp.json +73 -0
- data/test/mock-api/remove-process-mp.json +66 -0
- data/test/mock-api/remove-rule-lb.json +33 -0
- data/test/mock-api/remove-server-ip.json +58 -0
- data/test/mock-api/remove-server-pn.json +16 -0
- data/test/mock-api/restore-snapshot.json +55 -0
- data/test/mock-api/storage-servers.json +12 -0
- data/test/test_mock_dvd.rb +55 -0
- data/test/test_mock_firewall.rb +309 -0
- data/test/test_mock_image.rb +123 -0
- data/test/test_mock_load_balancer.rb +312 -0
- data/test/test_mock_log.rb +55 -0
- data/test/test_mock_monitoring_center.rb +55 -0
- data/test/test_mock_monitoring_policy.rb +587 -0
- data/test/test_mock_private_network.rb +206 -0
- data/test/test_mock_public_ip.rb +118 -0
- data/test/test_mock_server.rb +929 -0
- data/test/test_mock_server_appliance.rb +55 -0
- data/test/test_mock_shared_storage.rb +256 -0
- data/test/test_mock_usage.rb +34 -0
- data/test/test_mock_user.rb +270 -0
- metadata +360 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class PublicIP
|
5
|
+
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :specs
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(test: false)
|
12
|
+
@id = nil
|
13
|
+
@specs = nil
|
14
|
+
|
15
|
+
# Check if hitting mock api or live api
|
16
|
+
if test
|
17
|
+
@connection = Excon.new($base_url, :mock => true)
|
18
|
+
else
|
19
|
+
@connection = Excon.new($base_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
|
26
|
+
|
27
|
+
# Build hash for query parameters
|
28
|
+
keyword_args = {
|
29
|
+
:page => page,
|
30
|
+
:per_page => per_page,
|
31
|
+
:sort => sort,
|
32
|
+
:q => q,
|
33
|
+
:fields => fields
|
34
|
+
}
|
35
|
+
|
36
|
+
# Clean out null query parameters
|
37
|
+
params = OneAndOne.clean_hash(keyword_args)
|
38
|
+
|
39
|
+
# Build URL
|
40
|
+
path = OneAndOne.build_url('/public_ips')
|
41
|
+
|
42
|
+
# Perform request
|
43
|
+
response = @connection.request(:method => :get,
|
44
|
+
:path => path,
|
45
|
+
:headers => $header,
|
46
|
+
:query => params)
|
47
|
+
|
48
|
+
# Check response status
|
49
|
+
OneAndOne.check_response(response.body, response.status)
|
50
|
+
|
51
|
+
#JSON-ify the response string
|
52
|
+
JSON.parse(response.body)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def create(reverse_dns: nil, type: nil, datacenter_id: nil)
|
58
|
+
|
59
|
+
# Build POST body
|
60
|
+
new_ip = {
|
61
|
+
'reverse_dns' => reverse_dns,
|
62
|
+
'type' => type,
|
63
|
+
'datacenter_id' => datacenter_id
|
64
|
+
}
|
65
|
+
|
66
|
+
# Clean out null keys in POST body
|
67
|
+
body = OneAndOne.clean_hash(new_ip)
|
68
|
+
|
69
|
+
# Stringify the POST body
|
70
|
+
string_body = body.to_json
|
71
|
+
|
72
|
+
# Build URL
|
73
|
+
path = OneAndOne.build_url('/public_ips')
|
74
|
+
|
75
|
+
# Perform request
|
76
|
+
response = @connection.request(:method => :post,
|
77
|
+
:path => path,
|
78
|
+
:headers => $header,
|
79
|
+
:body => string_body)
|
80
|
+
|
81
|
+
# Check response status
|
82
|
+
OneAndOne.check_response(response.body, response.status)
|
83
|
+
|
84
|
+
#JSON-ify the response string
|
85
|
+
json = JSON.parse(response.body)
|
86
|
+
|
87
|
+
# Save new IP ID to PublicIP instance
|
88
|
+
@id = json['id']
|
89
|
+
@specs = json
|
90
|
+
|
91
|
+
# If all good, return JSON
|
92
|
+
json
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
def get(ip_id: @id)
|
98
|
+
|
99
|
+
# If user passed in IP ID, reassign
|
100
|
+
@id = ip_id
|
101
|
+
|
102
|
+
# Build URL
|
103
|
+
path = OneAndOne.build_url("/public_ips/#{@id}")
|
104
|
+
|
105
|
+
# Perform request
|
106
|
+
response = @connection.request(:method => :get,
|
107
|
+
:path => path,
|
108
|
+
:headers => $header)
|
109
|
+
|
110
|
+
# Check response status
|
111
|
+
OneAndOne.check_response(response.body, response.status)
|
112
|
+
|
113
|
+
#JSON-ify the response string
|
114
|
+
json = JSON.parse(response.body)
|
115
|
+
|
116
|
+
# Reload specs attribute
|
117
|
+
@specs = json
|
118
|
+
|
119
|
+
# If all good, return JSON
|
120
|
+
json
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
def modify(ip_id: @id, reverse_dns: nil)
|
126
|
+
|
127
|
+
# If user passed in shared_storage ID, reassign
|
128
|
+
@id = ip_id
|
129
|
+
|
130
|
+
# Build PUT body
|
131
|
+
new_ip = {
|
132
|
+
'reverse_dns' => reverse_dns
|
133
|
+
}
|
134
|
+
|
135
|
+
# Clean out null keys in POST body
|
136
|
+
body = OneAndOne.clean_hash(new_ip)
|
137
|
+
|
138
|
+
# Stringify the POST body
|
139
|
+
string_body = body.to_json
|
140
|
+
|
141
|
+
# Build URL
|
142
|
+
path = OneAndOne.build_url("/public_ips/#{@id}")
|
143
|
+
|
144
|
+
# Perform request
|
145
|
+
response = @connection.request(:method => :put,
|
146
|
+
:path => path,
|
147
|
+
:headers => $header,
|
148
|
+
:body => string_body)
|
149
|
+
|
150
|
+
# Check response status
|
151
|
+
OneAndOne.check_response(response.body, response.status)
|
152
|
+
|
153
|
+
#JSON-ify the response string
|
154
|
+
JSON.parse(response.body)
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def delete(ip_id: @id)
|
160
|
+
|
161
|
+
# If user passed in IP ID, reassign
|
162
|
+
@id = ip_id
|
163
|
+
|
164
|
+
# Build URL
|
165
|
+
path = OneAndOne.build_url("/public_ips/#{@id}")
|
166
|
+
|
167
|
+
# Perform request
|
168
|
+
response = @connection.request(:method => :delete,
|
169
|
+
:path => path,
|
170
|
+
:headers => $header)
|
171
|
+
|
172
|
+
# Check response status
|
173
|
+
OneAndOne.check_response(response.body, response.status)
|
174
|
+
|
175
|
+
#JSON-ify the response string
|
176
|
+
JSON.parse(response.body)
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def reload
|
182
|
+
|
183
|
+
# This reload fx is just a wrapper for the get fx
|
184
|
+
get
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
end
|
data/lib/1and1/role.rb
ADDED
@@ -0,0 +1,381 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class Role
|
5
|
+
|
6
|
+
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :specs
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(test: false)
|
12
|
+
@id = nil
|
13
|
+
@specs = nil
|
14
|
+
|
15
|
+
# Check if hitting mock api or live api
|
16
|
+
if test
|
17
|
+
@connection = Excon.new($base_url, :mock => true)
|
18
|
+
else
|
19
|
+
@connection = Excon.new($base_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
|
26
|
+
|
27
|
+
# Build hash for query parameters
|
28
|
+
keyword_args = {
|
29
|
+
:page => page,
|
30
|
+
:per_page => per_page,
|
31
|
+
:sort => sort,
|
32
|
+
:q => q,
|
33
|
+
:fields => fields
|
34
|
+
}
|
35
|
+
|
36
|
+
# Clean out null query parameters
|
37
|
+
params = OneAndOne.clean_hash(keyword_args)
|
38
|
+
|
39
|
+
# Build URL
|
40
|
+
path = OneAndOne.build_url('/roles')
|
41
|
+
|
42
|
+
# Perform request
|
43
|
+
response = @connection.request(:method => :get,
|
44
|
+
:path => path,
|
45
|
+
:headers => $header,
|
46
|
+
:query => params)
|
47
|
+
|
48
|
+
# Check response status
|
49
|
+
OneAndOne.check_response(response.body, response.status)
|
50
|
+
|
51
|
+
#JSON-ify the response string
|
52
|
+
JSON.parse(response.body)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def create(name: nil)
|
58
|
+
|
59
|
+
# Build POST body
|
60
|
+
new_role = {
|
61
|
+
'name' => name
|
62
|
+
}
|
63
|
+
|
64
|
+
# Clean out null keys in POST body
|
65
|
+
body = OneAndOne.clean_hash(new_role)
|
66
|
+
|
67
|
+
# Stringify the POST body
|
68
|
+
string_body = body.to_json
|
69
|
+
|
70
|
+
# Build URL
|
71
|
+
path = OneAndOne.build_url('/roles')
|
72
|
+
|
73
|
+
# Perform request
|
74
|
+
response = @connection.request(:method => :post,
|
75
|
+
:path => path,
|
76
|
+
:headers => $header,
|
77
|
+
:body => string_body)
|
78
|
+
|
79
|
+
# Check response status
|
80
|
+
OneAndOne.check_response(response.body, response.status)
|
81
|
+
|
82
|
+
#JSON-ify the response string
|
83
|
+
json = JSON.parse(response.body)
|
84
|
+
|
85
|
+
# Save new role ID to Role instance
|
86
|
+
@id = json['id']
|
87
|
+
@specs = json
|
88
|
+
|
89
|
+
# If all good, return JSON
|
90
|
+
json
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def get(role_id: @id)
|
96
|
+
|
97
|
+
# If user passed in role ID, reassign
|
98
|
+
@id = role_id
|
99
|
+
|
100
|
+
# Build URL
|
101
|
+
path = OneAndOne.build_url("/roles/#{@id}")
|
102
|
+
|
103
|
+
# Perform request
|
104
|
+
response = @connection.request(:method => :get,
|
105
|
+
:path => path,
|
106
|
+
:headers => $header)
|
107
|
+
|
108
|
+
# Check response status
|
109
|
+
OneAndOne.check_response(response.body, response.status)
|
110
|
+
|
111
|
+
#JSON-ify the response string
|
112
|
+
JSON.parse(response.body)
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def modify(role_id: @id, name: nil, description: nil, state: nil)
|
118
|
+
|
119
|
+
# If user passed in role ID, reassign
|
120
|
+
@id = role_id
|
121
|
+
|
122
|
+
# Build PUT body
|
123
|
+
new_role = {
|
124
|
+
'name' => name,
|
125
|
+
'description' => description,
|
126
|
+
'state' => state
|
127
|
+
}
|
128
|
+
|
129
|
+
# Clean out null keys in PUT body
|
130
|
+
body = OneAndOne.clean_hash(new_role)
|
131
|
+
|
132
|
+
# Stringify the PUT body
|
133
|
+
string_body = body.to_json
|
134
|
+
|
135
|
+
# Build URL
|
136
|
+
path = OneAndOne.build_url("/roles/#{@id}")
|
137
|
+
|
138
|
+
# Perform request
|
139
|
+
response = @connection.request(:method => :put,
|
140
|
+
:path => path,
|
141
|
+
:headers => $header,
|
142
|
+
:body => string_body)
|
143
|
+
|
144
|
+
# Check response status
|
145
|
+
OneAndOne.check_response(response.body, response.status)
|
146
|
+
|
147
|
+
#JSON-ify the response string
|
148
|
+
JSON.parse(response.body)
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
def delete(role_id: @id)
|
154
|
+
|
155
|
+
# If user passed in role ID, reassign
|
156
|
+
@id = role_id
|
157
|
+
|
158
|
+
# Build URL
|
159
|
+
path = OneAndOne.build_url("/roles/#{@id}")
|
160
|
+
|
161
|
+
# Perform request
|
162
|
+
response = @connection.request(:method => :delete,
|
163
|
+
:path => path,
|
164
|
+
:headers => $header)
|
165
|
+
|
166
|
+
# Check response status
|
167
|
+
OneAndOne.check_response(response.body, response.status)
|
168
|
+
|
169
|
+
#JSON-ify the response string
|
170
|
+
JSON.parse(response.body)
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
def permissions(role_id: @id)
|
176
|
+
|
177
|
+
# If user passed in role ID, reassign
|
178
|
+
@id = role_id
|
179
|
+
|
180
|
+
# Build URL
|
181
|
+
path = OneAndOne.build_url("/roles/#{@id}/permissions")
|
182
|
+
|
183
|
+
# Perform request
|
184
|
+
response = @connection.request(:method => :get,
|
185
|
+
:path => path,
|
186
|
+
:headers => $header)
|
187
|
+
|
188
|
+
# Check response status
|
189
|
+
OneAndOne.check_response(response.body, response.status)
|
190
|
+
|
191
|
+
#JSON-ify the response string
|
192
|
+
JSON.parse(response.body)
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
def modify_permissions(role_id: @id, servers: nil, images: nil,
|
198
|
+
shared_storages: nil, firewalls: nil, load_balancers: nil, ips: nil,
|
199
|
+
private_networks: nil, vpns: nil, monitoring_centers: nil,
|
200
|
+
monitoring_policies: nil, backups: nil, logs: nil, users: nil,
|
201
|
+
roles: nil, usages: nil, interactive_invoices: nil)
|
202
|
+
|
203
|
+
# If user passed in role ID, reassign
|
204
|
+
@id = role_id
|
205
|
+
|
206
|
+
# Build PUT body
|
207
|
+
new_perms = {
|
208
|
+
'servers' => servers,
|
209
|
+
'images' => images,
|
210
|
+
'sharedstorages' => shared_storages,
|
211
|
+
'firewalls' => firewalls,
|
212
|
+
'loadbalancers' => load_balancers,
|
213
|
+
'ips' => ips,
|
214
|
+
'privatenetwork' => private_networks,
|
215
|
+
'vpn' => vpns,
|
216
|
+
'monitoringcenter' => monitoring_centers,
|
217
|
+
'monitoringpolicies' => monitoring_policies,
|
218
|
+
'backups' => backups,
|
219
|
+
'logs' => logs,
|
220
|
+
'users' => users,
|
221
|
+
'roles' => roles,
|
222
|
+
'usages' => usages,
|
223
|
+
'interactiveinvoice' => interactive_invoices
|
224
|
+
}
|
225
|
+
|
226
|
+
# Clean out null keys in PUT body
|
227
|
+
body = OneAndOne.clean_hash(new_perms)
|
228
|
+
|
229
|
+
# Stringify the PUT body
|
230
|
+
string_body = body.to_json
|
231
|
+
|
232
|
+
# Build URL
|
233
|
+
path = OneAndOne.build_url("/roles/#{@id}/permissions")
|
234
|
+
|
235
|
+
# Perform request
|
236
|
+
response = @connection.request(:method => :put,
|
237
|
+
:path => path,
|
238
|
+
:headers => $header,
|
239
|
+
:body => string_body)
|
240
|
+
|
241
|
+
# Check response status
|
242
|
+
OneAndOne.check_response(response.body, response.status)
|
243
|
+
|
244
|
+
#JSON-ify the response string
|
245
|
+
JSON.parse(response.body)
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
def users(role_id: @id)
|
251
|
+
|
252
|
+
# If user passed in role ID, reassign
|
253
|
+
@id = role_id
|
254
|
+
|
255
|
+
# Build URL
|
256
|
+
path = OneAndOne.build_url("/roles/#{@id}/users")
|
257
|
+
|
258
|
+
# Perform request
|
259
|
+
response = @connection.request(:method => :get,
|
260
|
+
:path => path,
|
261
|
+
:headers => $header)
|
262
|
+
|
263
|
+
# Check response status
|
264
|
+
OneAndOne.check_response(response.body, response.status)
|
265
|
+
|
266
|
+
#JSON-ify the response string
|
267
|
+
JSON.parse(response.body)
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
def add_users(role_id: @id, users: nil)
|
273
|
+
|
274
|
+
# If user passed in role ID, reassign
|
275
|
+
@id = role_id
|
276
|
+
|
277
|
+
# Create POST body
|
278
|
+
new_users = {
|
279
|
+
'users' => users
|
280
|
+
}
|
281
|
+
|
282
|
+
# Stringify the POST body
|
283
|
+
string_body = new_users.to_json
|
284
|
+
|
285
|
+
# Build URL
|
286
|
+
path = OneAndOne.build_url("/roles/#{@id}/users")
|
287
|
+
|
288
|
+
# Perform request
|
289
|
+
response = @connection.request(:method => :post,
|
290
|
+
:path => path,
|
291
|
+
:headers => $header,
|
292
|
+
:body => string_body)
|
293
|
+
|
294
|
+
# Check response status
|
295
|
+
OneAndOne.check_response(response.body, response.status)
|
296
|
+
|
297
|
+
#JSON-ify the response string
|
298
|
+
JSON.parse(response.body)
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
|
303
|
+
def get_user(role_id: @id, user_id: nil)
|
304
|
+
|
305
|
+
# If user passed in role ID, reassign
|
306
|
+
@id = role_id
|
307
|
+
|
308
|
+
# Build URL
|
309
|
+
path = OneAndOne.build_url("/roles/#{@id}/users/#{user_id}")
|
310
|
+
|
311
|
+
# Perform request
|
312
|
+
response = @connection.request(:method => :get,
|
313
|
+
:path => path,
|
314
|
+
:headers => $header)
|
315
|
+
|
316
|
+
# Check response status
|
317
|
+
OneAndOne.check_response(response.body, response.status)
|
318
|
+
|
319
|
+
#JSON-ify the response string
|
320
|
+
JSON.parse(response.body)
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
def remove_user(role_id: @id, user_id: nil)
|
326
|
+
|
327
|
+
# If user passed in role ID, reassign
|
328
|
+
@id = role_id
|
329
|
+
|
330
|
+
# Build URL
|
331
|
+
path = OneAndOne.build_url("/roles/#{@id}/users/#{user_id}")
|
332
|
+
|
333
|
+
# Perform request
|
334
|
+
response = @connection.request(:method => :delete,
|
335
|
+
:path => path,
|
336
|
+
:headers => $header)
|
337
|
+
|
338
|
+
# Check response status
|
339
|
+
OneAndOne.check_response(response.body, response.status)
|
340
|
+
|
341
|
+
#JSON-ify the response string
|
342
|
+
JSON.parse(response.body)
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def clone(role_id: @id, name: nil)
|
348
|
+
|
349
|
+
# If user passed in role ID, reassign
|
350
|
+
@id = role_id
|
351
|
+
|
352
|
+
# Build POST body
|
353
|
+
new_role = {
|
354
|
+
'name' => name
|
355
|
+
}
|
356
|
+
|
357
|
+
# Stringify the POST body
|
358
|
+
string_body = new_role.to_json
|
359
|
+
|
360
|
+
# Build URL
|
361
|
+
path = OneAndOne.build_url("/roles/#{@id}/clone")
|
362
|
+
|
363
|
+
# Perform request
|
364
|
+
response = @connection.request(:method => :post,
|
365
|
+
:path => path,
|
366
|
+
:headers => $header,
|
367
|
+
:body => string_body)
|
368
|
+
|
369
|
+
# Check response status
|
370
|
+
OneAndOne.check_response(response.body, response.status)
|
371
|
+
|
372
|
+
#JSON-ify the response string
|
373
|
+
JSON.parse(response.body)
|
374
|
+
|
375
|
+
end
|
376
|
+
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
|
381
|
+
end
|