1and1 1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/1and1/usage.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module OneAndOne
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Usage
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def initialize(test: false)
|
|
8
|
+
|
|
9
|
+
# Check if hitting mock api or live api
|
|
10
|
+
if test
|
|
11
|
+
@connection = Excon.new($base_url, :mock => true)
|
|
12
|
+
else
|
|
13
|
+
@connection = Excon.new($base_url)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil,
|
|
20
|
+
period: 'LAST_24H', start_date: nil, end_date: nil)
|
|
21
|
+
|
|
22
|
+
# Build hash for query parameters
|
|
23
|
+
keyword_args = {
|
|
24
|
+
:page => page,
|
|
25
|
+
:per_page => per_page,
|
|
26
|
+
:sort => sort,
|
|
27
|
+
:q => q,
|
|
28
|
+
:fields => fields,
|
|
29
|
+
:period => period,
|
|
30
|
+
:start_date => start_date,
|
|
31
|
+
:end_date => end_date
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Clean out null query parameters
|
|
35
|
+
params = OneAndOne.clean_hash(keyword_args)
|
|
36
|
+
|
|
37
|
+
# Build URL
|
|
38
|
+
path = OneAndOne.build_url('/usages')
|
|
39
|
+
|
|
40
|
+
# Perform request
|
|
41
|
+
response = @connection.request(:method => :get,
|
|
42
|
+
:path => path,
|
|
43
|
+
:headers => $header,
|
|
44
|
+
:query => params)
|
|
45
|
+
|
|
46
|
+
# Check response status
|
|
47
|
+
OneAndOne.check_response(response.body, response.status)
|
|
48
|
+
|
|
49
|
+
#JSON-ify the response string
|
|
50
|
+
JSON.parse(response.body)
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
data/lib/1and1/user.rb
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
module OneAndOne
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class User
|
|
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('/users')
|
|
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, description: nil, password: nil, email: nil)
|
|
58
|
+
|
|
59
|
+
# Build POST body
|
|
60
|
+
new_user = {
|
|
61
|
+
'name' => name,
|
|
62
|
+
'description' => description,
|
|
63
|
+
'password' => password,
|
|
64
|
+
'email' => email
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Clean out null keys in POST body
|
|
68
|
+
body = OneAndOne.clean_hash(new_user)
|
|
69
|
+
|
|
70
|
+
# Stringify the POST body
|
|
71
|
+
string_body = body.to_json
|
|
72
|
+
|
|
73
|
+
# Build URL
|
|
74
|
+
path = OneAndOne.build_url('/users')
|
|
75
|
+
|
|
76
|
+
# Perform request
|
|
77
|
+
response = @connection.request(:method => :post,
|
|
78
|
+
:path => path,
|
|
79
|
+
:headers => $header,
|
|
80
|
+
:body => string_body)
|
|
81
|
+
|
|
82
|
+
# Check response status
|
|
83
|
+
OneAndOne.check_response(response.body, response.status)
|
|
84
|
+
|
|
85
|
+
#JSON-ify the response string
|
|
86
|
+
json = JSON.parse(response.body)
|
|
87
|
+
|
|
88
|
+
# Save new user ID to User instance
|
|
89
|
+
@id = json['id']
|
|
90
|
+
@specs = json
|
|
91
|
+
|
|
92
|
+
# If all good, return JSON
|
|
93
|
+
json
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def get(user_id: @id)
|
|
99
|
+
|
|
100
|
+
# If user passed in user ID, reassign
|
|
101
|
+
@id = user_id
|
|
102
|
+
|
|
103
|
+
# Build URL
|
|
104
|
+
path = OneAndOne.build_url("/users/#{@id}")
|
|
105
|
+
|
|
106
|
+
# Perform request
|
|
107
|
+
response = @connection.request(:method => :get,
|
|
108
|
+
:path => path,
|
|
109
|
+
:headers => $header)
|
|
110
|
+
|
|
111
|
+
# Check response status
|
|
112
|
+
OneAndOne.check_response(response.body, response.status)
|
|
113
|
+
|
|
114
|
+
#JSON-ify the response string
|
|
115
|
+
JSON.parse(response.body)
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def modify(user_id: @id, description: nil, password: nil, email: nil,
|
|
121
|
+
state: nil)
|
|
122
|
+
|
|
123
|
+
# If user passed in user ID, reassign
|
|
124
|
+
@id = user_id
|
|
125
|
+
|
|
126
|
+
# Build PUT body
|
|
127
|
+
new_user = {
|
|
128
|
+
'description' => description,
|
|
129
|
+
'password' => password,
|
|
130
|
+
'email' => email,
|
|
131
|
+
'state' => state
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# Clean out null keys in PUT body
|
|
135
|
+
body = OneAndOne.clean_hash(new_user)
|
|
136
|
+
|
|
137
|
+
# Stringify the PUT body
|
|
138
|
+
string_body = body.to_json
|
|
139
|
+
|
|
140
|
+
# Build URL
|
|
141
|
+
path = OneAndOne.build_url("/users/#{@id}")
|
|
142
|
+
|
|
143
|
+
# Perform request
|
|
144
|
+
response = @connection.request(:method => :put,
|
|
145
|
+
:path => path,
|
|
146
|
+
:headers => $header,
|
|
147
|
+
:body => string_body)
|
|
148
|
+
|
|
149
|
+
# Check response status
|
|
150
|
+
OneAndOne.check_response(response.body, response.status)
|
|
151
|
+
|
|
152
|
+
#JSON-ify the response string
|
|
153
|
+
JSON.parse(response.body)
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def delete(user_id: @id)
|
|
159
|
+
|
|
160
|
+
# If user passed in user ID, reassign
|
|
161
|
+
@id = user_id
|
|
162
|
+
|
|
163
|
+
# Build URL
|
|
164
|
+
path = OneAndOne.build_url("/users/#{@id}")
|
|
165
|
+
|
|
166
|
+
# Perform request
|
|
167
|
+
response = @connection.request(:method => :delete,
|
|
168
|
+
:path => path,
|
|
169
|
+
:headers => $header)
|
|
170
|
+
|
|
171
|
+
# Check response status
|
|
172
|
+
OneAndOne.check_response(response.body, response.status)
|
|
173
|
+
|
|
174
|
+
#JSON-ify the response string
|
|
175
|
+
JSON.parse(response.body)
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def api(user_id: @id)
|
|
181
|
+
|
|
182
|
+
# If user passed in user ID, reassign
|
|
183
|
+
@id = user_id
|
|
184
|
+
|
|
185
|
+
# Build URL
|
|
186
|
+
path = OneAndOne.build_url("/users/#{@id}/api")
|
|
187
|
+
|
|
188
|
+
# Perform request
|
|
189
|
+
response = @connection.request(:method => :get,
|
|
190
|
+
:path => path,
|
|
191
|
+
:headers => $header)
|
|
192
|
+
|
|
193
|
+
# Check response status
|
|
194
|
+
OneAndOne.check_response(response.body, response.status)
|
|
195
|
+
|
|
196
|
+
#JSON-ify the response string
|
|
197
|
+
JSON.parse(response.body)
|
|
198
|
+
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def enable_api(user_id: @id, active: nil)
|
|
203
|
+
|
|
204
|
+
# If user passed in user ID, reassign
|
|
205
|
+
@id = user_id
|
|
206
|
+
|
|
207
|
+
# Build PUT body
|
|
208
|
+
new_api = {
|
|
209
|
+
'active' => active
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
# Stringify the PUT body
|
|
213
|
+
string_body = new_api.to_json
|
|
214
|
+
|
|
215
|
+
# Build URL
|
|
216
|
+
path = OneAndOne.build_url("/users/#{@id}/api")
|
|
217
|
+
|
|
218
|
+
# Perform request
|
|
219
|
+
response = @connection.request(:method => :put,
|
|
220
|
+
:path => path,
|
|
221
|
+
:headers => $header,
|
|
222
|
+
:body => string_body)
|
|
223
|
+
|
|
224
|
+
# Check response status
|
|
225
|
+
OneAndOne.check_response(response.body, response.status)
|
|
226
|
+
|
|
227
|
+
#JSON-ify the response string
|
|
228
|
+
JSON.parse(response.body)
|
|
229
|
+
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def api_key(user_id: @id)
|
|
234
|
+
|
|
235
|
+
# If user passed in user ID, reassign
|
|
236
|
+
@id = user_id
|
|
237
|
+
|
|
238
|
+
# Build URL
|
|
239
|
+
path = OneAndOne.build_url("/users/#{@id}/api/key")
|
|
240
|
+
|
|
241
|
+
# Perform request
|
|
242
|
+
response = @connection.request(:method => :get,
|
|
243
|
+
:path => path,
|
|
244
|
+
:headers => $header)
|
|
245
|
+
|
|
246
|
+
# Check response status
|
|
247
|
+
OneAndOne.check_response(response.body, response.status)
|
|
248
|
+
|
|
249
|
+
#JSON-ify the response string
|
|
250
|
+
JSON.parse(response.body)
|
|
251
|
+
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def change_key(user_id: @id)
|
|
256
|
+
|
|
257
|
+
# If user passed in user ID, reassign
|
|
258
|
+
@id = user_id
|
|
259
|
+
|
|
260
|
+
# Build URL
|
|
261
|
+
path = OneAndOne.build_url("/users/#{@id}/api/key")
|
|
262
|
+
|
|
263
|
+
# Perform request
|
|
264
|
+
response = @connection.request(:method => :put,
|
|
265
|
+
:path => path,
|
|
266
|
+
:headers => $header)
|
|
267
|
+
|
|
268
|
+
# Check response status
|
|
269
|
+
OneAndOne.check_response(response.body, response.status)
|
|
270
|
+
|
|
271
|
+
#JSON-ify the response string
|
|
272
|
+
JSON.parse(response.body)
|
|
273
|
+
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def ips(user_id: @id)
|
|
278
|
+
|
|
279
|
+
# If user passed in user ID, reassign
|
|
280
|
+
@id = user_id
|
|
281
|
+
|
|
282
|
+
# Build URL
|
|
283
|
+
path = OneAndOne.build_url("/users/#{@id}/api/ips")
|
|
284
|
+
|
|
285
|
+
# Perform request
|
|
286
|
+
response = @connection.request(:method => :get,
|
|
287
|
+
:path => path,
|
|
288
|
+
:headers => $header)
|
|
289
|
+
|
|
290
|
+
# Check response status
|
|
291
|
+
OneAndOne.check_response(response.body, response.status)
|
|
292
|
+
|
|
293
|
+
#JSON-ify the response string
|
|
294
|
+
JSON.parse(response.body)
|
|
295
|
+
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def add_ips(user_id: @id, ips: nil)
|
|
300
|
+
|
|
301
|
+
# If user passed in user ID, reassign
|
|
302
|
+
@id = user_id
|
|
303
|
+
|
|
304
|
+
# Build POST body
|
|
305
|
+
new_ips = {
|
|
306
|
+
'ips' => ips
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
# Stringify the POST body
|
|
310
|
+
string_body = new_ips.to_json
|
|
311
|
+
|
|
312
|
+
# Build URL
|
|
313
|
+
path = OneAndOne.build_url("/users/#{@id}/api/ips")
|
|
314
|
+
|
|
315
|
+
# Perform request
|
|
316
|
+
response = @connection.request(:method => :post,
|
|
317
|
+
:path => path,
|
|
318
|
+
:headers => $header,
|
|
319
|
+
:body => string_body)
|
|
320
|
+
|
|
321
|
+
# Check response status
|
|
322
|
+
OneAndOne.check_response(response.body, response.status)
|
|
323
|
+
|
|
324
|
+
#JSON-ify the response string
|
|
325
|
+
JSON.parse(response.body)
|
|
326
|
+
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def remove_ip(user_id: @id, ip: nil)
|
|
331
|
+
|
|
332
|
+
# If user passed in user ID, reassign
|
|
333
|
+
@id = user_id
|
|
334
|
+
|
|
335
|
+
# Build URL
|
|
336
|
+
path = OneAndOne.build_url("/users/#{@id}/api/ips/#{ip}")
|
|
337
|
+
|
|
338
|
+
# Perform request
|
|
339
|
+
response = @connection.request(:method => :delete,
|
|
340
|
+
:path => path,
|
|
341
|
+
:headers => $header)
|
|
342
|
+
|
|
343
|
+
# Check response status
|
|
344
|
+
OneAndOne.check_response(response.body, response.status)
|
|
345
|
+
|
|
346
|
+
#JSON-ify the response string
|
|
347
|
+
JSON.parse(response.body)
|
|
348
|
+
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def permissions
|
|
353
|
+
|
|
354
|
+
# Build URL
|
|
355
|
+
path = OneAndOne.build_url('/users/current_user_permissions')
|
|
356
|
+
|
|
357
|
+
# Perform request
|
|
358
|
+
response = @connection.request(:method => :get,
|
|
359
|
+
:path => path,
|
|
360
|
+
:headers => $header)
|
|
361
|
+
|
|
362
|
+
# Check response status
|
|
363
|
+
OneAndOne.check_response(response.body, response.status)
|
|
364
|
+
|
|
365
|
+
#JSON-ify the response string
|
|
366
|
+
JSON.parse(response.body)
|
|
367
|
+
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
end
|
data/lib/1and1/vpn.rb
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
module OneAndOne
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Vpn
|
|
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('/vpns')
|
|
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 get(vpn_id: @id)
|
|
58
|
+
|
|
59
|
+
# If user passed in vpn ID, reassign
|
|
60
|
+
@id = vpn_id
|
|
61
|
+
|
|
62
|
+
# Build URL
|
|
63
|
+
path = OneAndOne.build_url("/vpns/#{@id}")
|
|
64
|
+
|
|
65
|
+
# Perform request
|
|
66
|
+
response = @connection.request(:method => :get,
|
|
67
|
+
:path => path,
|
|
68
|
+
:headers => $header)
|
|
69
|
+
|
|
70
|
+
# Check response status
|
|
71
|
+
OneAndOne.check_response(response.body, response.status)
|
|
72
|
+
|
|
73
|
+
#JSON-ify the response string
|
|
74
|
+
json = JSON.parse(response.body)
|
|
75
|
+
|
|
76
|
+
# Reload specs attribute
|
|
77
|
+
@specs = json
|
|
78
|
+
|
|
79
|
+
# If all good, return JSON
|
|
80
|
+
json
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def create(name: nil, description: nil, datacenter_id: nil)
|
|
86
|
+
|
|
87
|
+
# Build POST body
|
|
88
|
+
new_vpn = {
|
|
89
|
+
'name' => name,
|
|
90
|
+
'description' => description,
|
|
91
|
+
'datacenter_id' => datacenter_id
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# Clean out null keys in POST body
|
|
95
|
+
body = OneAndOne.clean_hash(new_vpn)
|
|
96
|
+
|
|
97
|
+
# Stringify the POST body
|
|
98
|
+
string_body = body.to_json
|
|
99
|
+
|
|
100
|
+
# Build URL
|
|
101
|
+
path = OneAndOne.build_url('/vpns')
|
|
102
|
+
|
|
103
|
+
# Perform request
|
|
104
|
+
response = @connection.request(:method => :post,
|
|
105
|
+
:path => path,
|
|
106
|
+
:headers => $header,
|
|
107
|
+
:body => string_body)
|
|
108
|
+
|
|
109
|
+
# Check response status
|
|
110
|
+
OneAndOne.check_response(response.body, response.status)
|
|
111
|
+
|
|
112
|
+
#JSON-ify the response string
|
|
113
|
+
json = JSON.parse(response.body)
|
|
114
|
+
|
|
115
|
+
# Save new vpn ID to Vpn instance
|
|
116
|
+
@id = json['id']
|
|
117
|
+
@specs = json
|
|
118
|
+
|
|
119
|
+
# If all good, return JSON
|
|
120
|
+
json
|
|
121
|
+
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def modify(vpn_id: @id, name: nil, description: nil)
|
|
126
|
+
|
|
127
|
+
# If user passed in vpn ID, reassign
|
|
128
|
+
@id = vpn_id
|
|
129
|
+
|
|
130
|
+
# Build PUT body
|
|
131
|
+
vpn_specs = {
|
|
132
|
+
'name' => name,
|
|
133
|
+
'description' => description
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Clean out null keys in PUT body
|
|
137
|
+
body = OneAndOne.clean_hash(vpn_specs)
|
|
138
|
+
|
|
139
|
+
# Stringify the PUT body
|
|
140
|
+
string_body = body.to_json
|
|
141
|
+
|
|
142
|
+
# Build URL
|
|
143
|
+
path = OneAndOne.build_url("/vpns/#{@id}")
|
|
144
|
+
|
|
145
|
+
# Perform Request
|
|
146
|
+
response = @connection.request(:method => :put,
|
|
147
|
+
:path => path,
|
|
148
|
+
:headers => $header,
|
|
149
|
+
:body => string_body)
|
|
150
|
+
|
|
151
|
+
# Check response status
|
|
152
|
+
OneAndOne.check_response(response.body, response.status)
|
|
153
|
+
|
|
154
|
+
#JSON-ify the response string
|
|
155
|
+
JSON.parse(response.body)
|
|
156
|
+
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def delete(vpn_id: @id)
|
|
161
|
+
|
|
162
|
+
# If user passed in vpn ID, reassign
|
|
163
|
+
@id = vpn_id
|
|
164
|
+
|
|
165
|
+
# Build URL
|
|
166
|
+
path = OneAndOne.build_url("/vpns/#{@id}")
|
|
167
|
+
|
|
168
|
+
# Perform request
|
|
169
|
+
response = @connection.request(:method => :delete,
|
|
170
|
+
:path => path,
|
|
171
|
+
:headers => $header)
|
|
172
|
+
|
|
173
|
+
# Check response status
|
|
174
|
+
OneAndOne.check_response(response.body, response.status)
|
|
175
|
+
|
|
176
|
+
#JSON-ify the response string
|
|
177
|
+
JSON.parse(response.body)
|
|
178
|
+
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def download_config(vpn_id: @id)
|
|
183
|
+
|
|
184
|
+
# If user passed in vpn ID, reassign
|
|
185
|
+
@id = vpn_id
|
|
186
|
+
|
|
187
|
+
# Build URL
|
|
188
|
+
path = OneAndOne.build_url("/vpns/#{@id}/configuration_file")
|
|
189
|
+
|
|
190
|
+
# Perform request
|
|
191
|
+
response = @connection.request(:method => :get,
|
|
192
|
+
:path => path,
|
|
193
|
+
:headers => $header)
|
|
194
|
+
|
|
195
|
+
# Check response status
|
|
196
|
+
OneAndOne.check_response(response.body, response.status)
|
|
197
|
+
|
|
198
|
+
#JSON-ify the response string
|
|
199
|
+
JSON.parse(response.body)
|
|
200
|
+
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def reload
|
|
205
|
+
|
|
206
|
+
# This reload fx is just a wrapper for the get fx
|
|
207
|
+
get
|
|
208
|
+
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def wait_for(timeout: 25, interval: 15)
|
|
213
|
+
|
|
214
|
+
# Capture start time
|
|
215
|
+
start = Time.now
|
|
216
|
+
|
|
217
|
+
# Poll VPN and check initial state
|
|
218
|
+
initial_response = get
|
|
219
|
+
vpn_state = initial_response['state']
|
|
220
|
+
|
|
221
|
+
# Keep polling the VPN's state until good
|
|
222
|
+
until $good_states.include? vpn_state
|
|
223
|
+
|
|
224
|
+
# Wait 15 seconds before polling again
|
|
225
|
+
sleep interval
|
|
226
|
+
|
|
227
|
+
# Check VPN state again
|
|
228
|
+
current_response = get
|
|
229
|
+
vpn_state = current_response['state']
|
|
230
|
+
|
|
231
|
+
# Calculate current duration and check for timeout
|
|
232
|
+
duration = (Time.now - start) / 60
|
|
233
|
+
if duration > timeout
|
|
234
|
+
puts "The operation timed out after #{timeout} minutes.\n"
|
|
235
|
+
return
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Return Duration
|
|
241
|
+
{:duration => duration}
|
|
242
|
+
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
end
|