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,57 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
def OneAndOne.start(api_token)
|
5
|
+
|
6
|
+
# Set core values to be used across the module
|
7
|
+
$api_token = api_token
|
8
|
+
$base_url = 'https://cloudpanel-api.1and1.com'
|
9
|
+
$version = '/v1'
|
10
|
+
$header = {
|
11
|
+
'X-TOKEN' => $api_token,
|
12
|
+
'Content-Type' => 'application/json'
|
13
|
+
}
|
14
|
+
$success_codes = [200, 201, 202]
|
15
|
+
$good_states = ['ACTIVE', 'ENABLED', 'POWERED_ON', 'POWERED_OFF']
|
16
|
+
|
17
|
+
true
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def OneAndOne.clean_hash(hash)
|
23
|
+
|
24
|
+
hash.each do |key, value|
|
25
|
+
if value == nil
|
26
|
+
hash.delete(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def OneAndOne.build_url(endpoint)
|
34
|
+
|
35
|
+
$version + endpoint
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def OneAndOne.check_response(message, status)
|
41
|
+
|
42
|
+
# Check for server error
|
43
|
+
if status == 500
|
44
|
+
raise "Internal Server Error. Please try again."
|
45
|
+
end
|
46
|
+
|
47
|
+
# Raise exception if a bad status code is received
|
48
|
+
unless $success_codes.include? status
|
49
|
+
raise message
|
50
|
+
end
|
51
|
+
|
52
|
+
true
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
data/lib/1and1/ping.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class Ping
|
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 get
|
20
|
+
|
21
|
+
# Build URL
|
22
|
+
path = OneAndOne.build_url('/ping')
|
23
|
+
|
24
|
+
# Perform request
|
25
|
+
response = @connection.request(:method => :get,
|
26
|
+
:path => path,
|
27
|
+
:headers => $header)
|
28
|
+
|
29
|
+
# Check response status
|
30
|
+
OneAndOne.check_response(response.body, response.status)
|
31
|
+
|
32
|
+
#JSON-ify the response string
|
33
|
+
JSON.parse(response.body)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class PingAuth
|
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 get
|
20
|
+
|
21
|
+
# Build URL
|
22
|
+
path = OneAndOne.build_url('/ping_auth')
|
23
|
+
|
24
|
+
# Perform request
|
25
|
+
response = @connection.request(:method => :get,
|
26
|
+
:path => path,
|
27
|
+
:headers => $header)
|
28
|
+
|
29
|
+
# Check response status
|
30
|
+
OneAndOne.check_response(response.body, response.status)
|
31
|
+
|
32
|
+
#JSON-ify the response string
|
33
|
+
JSON.parse(response.body)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class Pricing
|
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
|
20
|
+
|
21
|
+
# Build URL
|
22
|
+
path = OneAndOne.build_url('/pricing')
|
23
|
+
|
24
|
+
# Perform request
|
25
|
+
response = @connection.request(:method => :get,
|
26
|
+
:path => path,
|
27
|
+
:headers => $header)
|
28
|
+
|
29
|
+
# Check response status
|
30
|
+
OneAndOne.check_response(response.body, response.status)
|
31
|
+
|
32
|
+
#JSON-ify the response string
|
33
|
+
JSON.parse(response.body)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
module OneAndOne
|
2
|
+
|
3
|
+
|
4
|
+
class PrivateNetwork
|
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('/private_networks')
|
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, network_address: nil,
|
58
|
+
subnet_mask: nil, datacenter_id: nil)
|
59
|
+
|
60
|
+
# Build POST body
|
61
|
+
new_private_network = {
|
62
|
+
'name' => name,
|
63
|
+
'description' => description,
|
64
|
+
'network_address' => network_address,
|
65
|
+
'subnet_mask' => subnet_mask,
|
66
|
+
'datacenter_id' => datacenter_id
|
67
|
+
}
|
68
|
+
|
69
|
+
# Clean out null keys in POST body
|
70
|
+
body = OneAndOne.clean_hash(new_private_network)
|
71
|
+
|
72
|
+
# Stringify the POST body
|
73
|
+
string_body = body.to_json
|
74
|
+
|
75
|
+
# Build URL
|
76
|
+
path = OneAndOne.build_url('/private_networks')
|
77
|
+
|
78
|
+
# Perform request
|
79
|
+
response = @connection.request(:method => :post,
|
80
|
+
:path => path,
|
81
|
+
:headers => $header,
|
82
|
+
:body => string_body)
|
83
|
+
|
84
|
+
# Check response status
|
85
|
+
OneAndOne.check_response(response.body, response.status)
|
86
|
+
|
87
|
+
#JSON-ify the response string
|
88
|
+
json = JSON.parse(response.body)
|
89
|
+
|
90
|
+
# Save new private network ID to PrivateNetwork instance
|
91
|
+
@id = json['id']
|
92
|
+
@specs = json
|
93
|
+
|
94
|
+
# If all good, return JSON
|
95
|
+
json
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def get(private_network_id: @id)
|
101
|
+
|
102
|
+
# If user passed in private network ID, reassign
|
103
|
+
@id = private_network_id
|
104
|
+
|
105
|
+
# Build URL
|
106
|
+
path = OneAndOne.build_url("/private_networks/#{@id}")
|
107
|
+
|
108
|
+
# Perform request
|
109
|
+
response = @connection.request(:method => :get,
|
110
|
+
:path => path,
|
111
|
+
:headers => $header)
|
112
|
+
|
113
|
+
# Check response status
|
114
|
+
OneAndOne.check_response(response.body, response.status)
|
115
|
+
|
116
|
+
#JSON-ify the response string
|
117
|
+
json = JSON.parse(response.body)
|
118
|
+
|
119
|
+
# Reload specs attribute
|
120
|
+
@specs = json
|
121
|
+
|
122
|
+
# If all good, return JSON
|
123
|
+
json
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
def modify(private_network_id: @id, name: nil, description: nil,
|
129
|
+
network_address: nil, subnet_mask: nil)
|
130
|
+
|
131
|
+
# If user passed in private network ID, reassign
|
132
|
+
@id = private_network_id
|
133
|
+
|
134
|
+
# Build PUT body
|
135
|
+
new_private_network = {
|
136
|
+
'name' => name,
|
137
|
+
'description' => description,
|
138
|
+
'network_address' => network_address,
|
139
|
+
'subnet_mask' => subnet_mask
|
140
|
+
}
|
141
|
+
|
142
|
+
# Clean out null keys in PUT body
|
143
|
+
body = OneAndOne.clean_hash(new_private_network)
|
144
|
+
|
145
|
+
# Stringify the PUT body
|
146
|
+
string_body = body.to_json
|
147
|
+
|
148
|
+
# Build URL
|
149
|
+
path = OneAndOne.build_url("/private_networks/#{@id}")
|
150
|
+
|
151
|
+
# Perform request
|
152
|
+
response = @connection.request(:method => :put,
|
153
|
+
:path => path,
|
154
|
+
:headers => $header,
|
155
|
+
:body => string_body)
|
156
|
+
|
157
|
+
# Check response status
|
158
|
+
OneAndOne.check_response(response.body, response.status)
|
159
|
+
|
160
|
+
#JSON-ify the response string
|
161
|
+
JSON.parse(response.body)
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
def delete(private_network_id: @id)
|
167
|
+
|
168
|
+
# If user passed in private network ID, reassign
|
169
|
+
@id = private_network_id
|
170
|
+
|
171
|
+
# Build URL
|
172
|
+
path = OneAndOne.build_url("/private_networks/#{@id}")
|
173
|
+
|
174
|
+
# Perform request
|
175
|
+
response = @connection.request(:method => :delete,
|
176
|
+
:path => path,
|
177
|
+
:headers => $header)
|
178
|
+
|
179
|
+
# Check response status
|
180
|
+
OneAndOne.check_response(response.body, response.status)
|
181
|
+
|
182
|
+
#JSON-ify the response string
|
183
|
+
JSON.parse(response.body)
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
def servers(private_network_id: @id)
|
189
|
+
|
190
|
+
# If user passed in private network ID, reassign
|
191
|
+
@id = private_network_id
|
192
|
+
|
193
|
+
# Build URL
|
194
|
+
path = OneAndOne.build_url("/private_networks/#{@id}/servers")
|
195
|
+
|
196
|
+
# Perform request
|
197
|
+
response = @connection.request(:method => :get,
|
198
|
+
:path => path,
|
199
|
+
:headers => $header)
|
200
|
+
|
201
|
+
# Check response status
|
202
|
+
OneAndOne.check_response(response.body, response.status)
|
203
|
+
|
204
|
+
#JSON-ify the response string
|
205
|
+
JSON.parse(response.body)
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
def server(private_network_id: @id, server_id: nil)
|
211
|
+
|
212
|
+
# If user passed in private network ID, reassign
|
213
|
+
@id = private_network_id
|
214
|
+
|
215
|
+
# Build URL
|
216
|
+
path = OneAndOne.build_url("/private_networks/#{@id}/servers/#{server_id}")
|
217
|
+
|
218
|
+
# Perform request
|
219
|
+
response = @connection.request(:method => :get,
|
220
|
+
:path => path,
|
221
|
+
:headers => $header)
|
222
|
+
|
223
|
+
# Check response status
|
224
|
+
OneAndOne.check_response(response.body, response.status)
|
225
|
+
|
226
|
+
#JSON-ify the response string
|
227
|
+
JSON.parse(response.body)
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
def remove_server(private_network_id: @id, server_id: nil)
|
233
|
+
|
234
|
+
# If user passed in private network ID, reassign
|
235
|
+
@id = private_network_id
|
236
|
+
|
237
|
+
# Build URL
|
238
|
+
path = OneAndOne.build_url("/private_networks/#{@id}/servers/#{server_id}")
|
239
|
+
|
240
|
+
# Perform request
|
241
|
+
response = @connection.request(:method => :delete,
|
242
|
+
:path => path,
|
243
|
+
:headers => $header)
|
244
|
+
|
245
|
+
# Check response status
|
246
|
+
OneAndOne.check_response(response.body, response.status)
|
247
|
+
|
248
|
+
#JSON-ify the response string
|
249
|
+
JSON.parse(response.body)
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
def add_servers(private_network_id: @id, servers: nil)
|
255
|
+
|
256
|
+
# If user passed in private network ID, reassign
|
257
|
+
@id = private_network_id
|
258
|
+
|
259
|
+
# Build POST body
|
260
|
+
new_servers = {
|
261
|
+
'servers' => servers
|
262
|
+
}
|
263
|
+
|
264
|
+
# Clean out null keys in POST body
|
265
|
+
body = OneAndOne.clean_hash(new_servers)
|
266
|
+
|
267
|
+
# Stringify the PUT body
|
268
|
+
string_body = body.to_json
|
269
|
+
|
270
|
+
# Build URL
|
271
|
+
path = OneAndOne.build_url("/private_networks/#{@id}/servers")
|
272
|
+
|
273
|
+
# Perform request
|
274
|
+
response = @connection.request(:method => :post,
|
275
|
+
:path => path,
|
276
|
+
:headers => $header,
|
277
|
+
:body => string_body)
|
278
|
+
|
279
|
+
# Check response status
|
280
|
+
OneAndOne.check_response(response.body, response.status)
|
281
|
+
|
282
|
+
#JSON-ify the response string
|
283
|
+
JSON.parse(response.body)
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
def reload
|
289
|
+
|
290
|
+
# This reload fx is just a wrapper for the get fx
|
291
|
+
get
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
def wait_for(timeout: 25, interval: 5)
|
297
|
+
|
298
|
+
# Capture start time
|
299
|
+
start = Time.now
|
300
|
+
|
301
|
+
# Poll private network and check initial state
|
302
|
+
initial_response = get
|
303
|
+
private_network_state = initial_response['state']
|
304
|
+
|
305
|
+
# Keep polling the private network's state until good
|
306
|
+
until $good_states.include? private_network_state
|
307
|
+
|
308
|
+
# Wait 5 seconds before polling again
|
309
|
+
sleep interval
|
310
|
+
|
311
|
+
# Check private network state again
|
312
|
+
current_response = get
|
313
|
+
private_network_state = current_response['state']
|
314
|
+
|
315
|
+
# Calculate current duration and check for timeout
|
316
|
+
duration = (Time.now - start) / 60
|
317
|
+
if duration > timeout
|
318
|
+
puts "The operation timed out after #{timeout} minutes.\n"
|
319
|
+
return
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
# Return Duration
|
325
|
+
{:duration => duration}
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
|
333
|
+
end
|