cloudcontrol_sdk 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +34 -0
- data/cloudcontrol.gemspec +28 -0
- data/lib/cloudcontrol.rb +22 -0
- data/lib/cloudcontrol/api/account.rb +13 -0
- data/lib/cloudcontrol/api/core.rb +127 -0
- data/lib/cloudcontrol/api/image.rb +24 -0
- data/lib/cloudcontrol/api/infrastructure.rb +16 -0
- data/lib/cloudcontrol/api/network.rb +65 -0
- data/lib/cloudcontrol/api/report.rb +24 -0
- data/lib/cloudcontrol/api/server.rb +118 -0
- data/lib/cloudcontrol/api/vip.rb +125 -0
- data/lib/cloudcontrol/client.rb +97 -0
- data/lib/cloudcontrol/connection.rb +59 -0
- data/lib/cloudcontrol/exceptions.rb +14 -0
- data/lib/cloudcontrol/params.rb +62 -0
- data/lib/cloudcontrol/version.rb +4 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 589fa5ceedb8772df6be667c83a8e9b9dbd59a87f84b7bdf6f2c00ab4602bde7
|
4
|
+
data.tar.gz: e44127510cd833d8b72e9b874a50795814d0dca11fdb55b0f955e6bd0ca2a176
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d146dc22a04375aea377c08491446f08406b8f0944e0197d7863021075bce3b819b9104f788fb658def3dfc9dbf79f77786a1f0d57bfdce3be9b6f17fbda83f3
|
7
|
+
data.tar.gz: 88c0e99bea294228c5e700037e8811ae34bcf7a31f9670294d6110ff49c3229c12b365640cb0a9fa717a9492e1fa7795b9900dd9c564bb29f50b17278dc2797c
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 tintoy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
## Cloud Control Ruby gem
|
2
|
+
|
3
|
+
Cloud Control Cloud API gem designed for easy extensibility.
|
4
|
+
Note: This gem at present ONLY provides read functionality across the API. This is so that the Chef Inspec plugin written for Cloud Control can operate successfully. All the existing gems for this are 6 years old and appear abandoned, so I'm not sure there is much of a demand for this. There is also a lot of work to change the API calls to leverage MCP 2.0 apis.
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
### Install
|
9
|
+
|
10
|
+
either install as a gem via Bundler
|
11
|
+
```
|
12
|
+
gem install cloudcontrol_sdk
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
### Usage
|
18
|
+
|
19
|
+
```
|
20
|
+
require "cloudcontrol_sdk"
|
21
|
+
api_base = CloudControl::Client::API_URL[:au]
|
22
|
+
dev_org_id = 'my-super-secret-org-numbersandletters'
|
23
|
+
dev_user = 'me'
|
24
|
+
dev_password = 'very secret'
|
25
|
+
|
26
|
+
c = CloudControl::Client.new(api_base, dev_org_id, dev_user, dev_password)
|
27
|
+
|
28
|
+
server = c.server.list(name: 'myfavoritevm')
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Based on : https://github.com/udayakiran/opsource.
|
34
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cloudcontrol/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "cloudcontrol_sdk"
|
7
|
+
s.version = CloudControl::VERSION
|
8
|
+
s.authors = ["Nigel Wright"]
|
9
|
+
s.email = ["nigel.wright@global.ntt"]
|
10
|
+
s.licenses = ['MIT']
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{NTT Cloud Control REST API client gem}
|
13
|
+
s.description = %q{SDK to access NTT Cloud Control api'}
|
14
|
+
|
15
|
+
s.rubyforge_project = "cloudcontrol"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'i18n'
|
23
|
+
s.add_dependency 'activesupport'
|
24
|
+
s.add_dependency 'typhoeus'
|
25
|
+
s.add_dependency 'xml-simple'
|
26
|
+
s.add_dependency 'hashie'
|
27
|
+
s.add_dependency 'colorize'
|
28
|
+
end
|
data/lib/cloudcontrol.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
require 'typhoeus'
|
4
|
+
require 'xmlsimple'
|
5
|
+
require 'hashie'
|
6
|
+
|
7
|
+
require 'cloudcontrol/version.rb'
|
8
|
+
require 'cloudcontrol/exceptions.rb'
|
9
|
+
|
10
|
+
require 'cloudcontrol/connection.rb'
|
11
|
+
require 'cloudcontrol/params.rb'
|
12
|
+
# require 'cloudcontrol/xml.rb'
|
13
|
+
require 'cloudcontrol/client.rb'
|
14
|
+
|
15
|
+
require 'cloudcontrol/api/core.rb'
|
16
|
+
# require 'cloudcontrol/api/directory.rb'
|
17
|
+
require 'cloudcontrol/api/image.rb'
|
18
|
+
require 'cloudcontrol/api/network.rb'
|
19
|
+
require 'cloudcontrol/api/server.rb'
|
20
|
+
require 'cloudcontrol/api/vip.rb'
|
21
|
+
require 'cloudcontrol/api/account.rb'
|
22
|
+
require 'cloudcontrol/api/report.rb'
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Core
|
3
|
+
attr_reader :client
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
### client methods
|
10
|
+
|
11
|
+
def log(*args)
|
12
|
+
@client.log(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def org_id
|
16
|
+
@client.org_id
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
### request options
|
21
|
+
|
22
|
+
def endpoint(e)
|
23
|
+
@endpoint = e
|
24
|
+
end
|
25
|
+
|
26
|
+
def org_endpoint(e)
|
27
|
+
endpoint("/#{org_id}" + e)
|
28
|
+
end
|
29
|
+
|
30
|
+
def query_params(q)
|
31
|
+
@query_params = q
|
32
|
+
end
|
33
|
+
|
34
|
+
def xml_params(x)
|
35
|
+
@xml_params = x
|
36
|
+
end
|
37
|
+
|
38
|
+
def simple_params(x)
|
39
|
+
@simple_params = x
|
40
|
+
end
|
41
|
+
|
42
|
+
### perform request
|
43
|
+
|
44
|
+
def get
|
45
|
+
perform :get
|
46
|
+
end
|
47
|
+
|
48
|
+
def post
|
49
|
+
perform :post
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_simple
|
53
|
+
perform :get, true
|
54
|
+
end
|
55
|
+
|
56
|
+
def post_simple
|
57
|
+
perform :post, true
|
58
|
+
end
|
59
|
+
|
60
|
+
#do not parse response if simple
|
61
|
+
#if simple, post body is also simple...
|
62
|
+
def perform(method, simple=false)
|
63
|
+
if simple
|
64
|
+
request = @client.build_request(method, @endpoint, request_query_string, request_simple_body, false)
|
65
|
+
else
|
66
|
+
request = @client.build_request(method, @endpoint, request_query_string, request_xml_body)
|
67
|
+
end
|
68
|
+
response = @client.perform_request(request)
|
69
|
+
|
70
|
+
@client.log_response(request, response)
|
71
|
+
|
72
|
+
# return parsed object if it's good
|
73
|
+
if response.success?
|
74
|
+
if simple
|
75
|
+
result = response.body
|
76
|
+
else
|
77
|
+
result = @client.parse_response_xml_body(response.body)
|
78
|
+
if result['total_count']
|
79
|
+
log "#{result['total_count']} total", :yellow, :bold
|
80
|
+
result.delete('page_size')
|
81
|
+
result.delete('total_count')
|
82
|
+
result.delete('page_count')
|
83
|
+
result.delete('page_number')
|
84
|
+
end
|
85
|
+
# unwind some arrays of elements
|
86
|
+
result.values.count == 1 ? result.values.first : result
|
87
|
+
end
|
88
|
+
else
|
89
|
+
{}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def single(results)
|
94
|
+
if results.is_a? Array
|
95
|
+
results.first
|
96
|
+
else
|
97
|
+
results
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
### build request
|
103
|
+
|
104
|
+
def request_query_string
|
105
|
+
fparams = @client.filter_params || {}
|
106
|
+
qparams = @query_params || {}
|
107
|
+
params = fparams.merge(qparams)
|
108
|
+
@client.url_query(params) if params.present?
|
109
|
+
end
|
110
|
+
|
111
|
+
def request_xml_body
|
112
|
+
return if @xml_params.blank?
|
113
|
+
schema = @xml_params.delete(:schema)
|
114
|
+
tag = @xml_params.delete(:tag)
|
115
|
+
|
116
|
+
body = @client.build_request_xml_body(schema, tag, @xml_params)
|
117
|
+
log(body, :green)
|
118
|
+
body
|
119
|
+
end
|
120
|
+
def request_simple_body
|
121
|
+
return if @simple_params.blank?
|
122
|
+
body = @client.build_request_simple_body(@simple_params)
|
123
|
+
log(body, :green)
|
124
|
+
body
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Image < Core
|
3
|
+
def server_list
|
4
|
+
endpoint '/base/image'
|
5
|
+
get
|
6
|
+
end
|
7
|
+
|
8
|
+
def deployed_list(options = {})
|
9
|
+
endpoint "/#{org_id}/image/deployed"
|
10
|
+
query_params options
|
11
|
+
get
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_by_name(name, options = {})
|
15
|
+
options[:name] = name
|
16
|
+
single(deployed_list(options))
|
17
|
+
end
|
18
|
+
|
19
|
+
def show(image_id)
|
20
|
+
endpoint "/#{org_id}/image/#{image_id}"
|
21
|
+
get
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Infrastructure < Core
|
3
|
+
def list_regions(options = {})
|
4
|
+
endpoint "/#{org_id}/infrastructure/geographicRegion"
|
5
|
+
query_params options
|
6
|
+
get
|
7
|
+
end
|
8
|
+
|
9
|
+
def list_datacenters(options = {})
|
10
|
+
endpoint "/#{org_id}/infrastructure/datacenter"
|
11
|
+
query_params options
|
12
|
+
get
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Network < Core
|
3
|
+
def list
|
4
|
+
org_endpoint '/network'
|
5
|
+
get
|
6
|
+
end
|
7
|
+
|
8
|
+
def create(name, description="", datacenter=@client.datacenter)
|
9
|
+
org_endpoint "/networkWithLocation"
|
10
|
+
xml_params(schema: "network", tag: "NewNetworkWithLocation", name: name, description: description, location: datacenter)
|
11
|
+
post
|
12
|
+
end
|
13
|
+
|
14
|
+
def list_with_location
|
15
|
+
org_endpoint "/networkWithLocation"
|
16
|
+
get
|
17
|
+
end
|
18
|
+
|
19
|
+
def list_in_location(location_id)
|
20
|
+
org_endpoint "/networkWithLocation/#{location_id}"
|
21
|
+
get
|
22
|
+
end
|
23
|
+
|
24
|
+
def show(network_id)
|
25
|
+
list_with_location.find {|n| n.id == network_id}
|
26
|
+
end
|
27
|
+
|
28
|
+
def show_by_name(name)
|
29
|
+
list_with_location.find {|n| n.name == name}
|
30
|
+
end
|
31
|
+
|
32
|
+
def natrule_list(network_id)
|
33
|
+
org_endpoint "/network/#{network_id}/natrule"
|
34
|
+
get
|
35
|
+
end
|
36
|
+
|
37
|
+
# name = "10.147.15.11", source_ip = "10.147.15.11"
|
38
|
+
def natrule_create(network_id, name, source_ip)
|
39
|
+
org_endpoint "/network/#{network_id}/natrule"
|
40
|
+
xml_params(schema: "network", tag: "NatRule", name: name, source_ip: source_ip)
|
41
|
+
post
|
42
|
+
end
|
43
|
+
|
44
|
+
def natrule_delete(network_id, natrule_id)
|
45
|
+
org_endpoint "/network/#{network_id}/natrule/#{natrule_id}?delete"
|
46
|
+
get
|
47
|
+
end
|
48
|
+
|
49
|
+
def aclrule_list(network_id)
|
50
|
+
org_endpoint "/network/#{network_id}/aclrule"
|
51
|
+
get
|
52
|
+
end
|
53
|
+
|
54
|
+
def aclrule_delete(network_id, aclrule_id)
|
55
|
+
org_endpoint "/network/#{network_id}/aclrule/#{aclrule_id}?delete"
|
56
|
+
get
|
57
|
+
end
|
58
|
+
|
59
|
+
def aclrule_create(network_id, name, position, inbound, protocol, port, allow)
|
60
|
+
org_endpoint "/network/#{network_id}/aclrule"
|
61
|
+
xml_params(schema: "network", tag: "AclRule", name: name, position: position, action: (allow ? "PERMIT" : "DENY"), protocol: protocol, source_ip_range: {}, destination_ip_range: {}, port_range: {type: "EQUAL_TO", port1: port}, type: (inbound ? "OUTSIDE_ACL" : "INSIDE_ACL"))
|
62
|
+
post
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Report < Core
|
3
|
+
def auditlog(start_date, end_date)
|
4
|
+
start = start_date.strftime("%Y-%m-%d")
|
5
|
+
stop = end_date.strftime("%Y-%m-%d")
|
6
|
+
org_endpoint "/auditlog?startDate=#{start}&endDate=#{stop}"
|
7
|
+
get_simple
|
8
|
+
end
|
9
|
+
|
10
|
+
def summary_usage(start_date, end_date)
|
11
|
+
start = start_date.strftime("%Y-%m-%d")
|
12
|
+
stop = end_date.strftime("%Y-%m-%d")
|
13
|
+
org_endpoint "/report/usage?startDate=#{start}&endDate=#{stop}"
|
14
|
+
get_simple
|
15
|
+
end
|
16
|
+
|
17
|
+
def detailed_usage(start_date, end_date)
|
18
|
+
start = start_date.strftime("%Y-%m-%d")
|
19
|
+
stop = end_date.strftime("%Y-%m-%d")
|
20
|
+
org_endpoint "/report/usageDetailed?startDate=#{start}&endDate=#{stop}"
|
21
|
+
get_simple
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class Server < Core
|
3
|
+
|
4
|
+
|
5
|
+
def list(options = {})
|
6
|
+
endpoint "/#{org_id}/server/server"
|
7
|
+
query_params options
|
8
|
+
get
|
9
|
+
end
|
10
|
+
|
11
|
+
def show(server_id, options = {})
|
12
|
+
endpoint "/#{org_id}/server/server/#{server_id}"
|
13
|
+
get
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_by_name(name, options = {})
|
17
|
+
options[:name] = name
|
18
|
+
single(list(options))
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_by_id(id, options = {})
|
22
|
+
options[:id] = id
|
23
|
+
single(list(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def list_nics(vlan_id, options = {})
|
28
|
+
endpoint "/#{org_id}/server/nic"
|
29
|
+
get
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_anti_affinity(target_id, options = {})
|
33
|
+
endpoint "/#{org_id}/server/nic"
|
34
|
+
get
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_by_ip(ip, options = {})
|
38
|
+
options[:private_ip] = ip
|
39
|
+
single(list(options))
|
40
|
+
end
|
41
|
+
|
42
|
+
# def create(name,
|
43
|
+
# description,
|
44
|
+
# network_id,
|
45
|
+
# image_id,
|
46
|
+
# administrator_password=@client.default_password)
|
47
|
+
# org_endpoint "/server"
|
48
|
+
|
49
|
+
# xml_params(
|
50
|
+
# tag: "Server",
|
51
|
+
# schema: "server",
|
52
|
+
# name: name,
|
53
|
+
# description: description,
|
54
|
+
# vlan_resource_path: "/oec/#{org_id}/network/#{network_id}",
|
55
|
+
# image_resource_path: "/oec/base/image/#{image_id}",
|
56
|
+
# is_started: 'true',
|
57
|
+
# administrator_password: administrator_password
|
58
|
+
# )
|
59
|
+
# post
|
60
|
+
# end
|
61
|
+
|
62
|
+
# def delete(server_id)
|
63
|
+
# org_endpoint "/server/#{server_id}?delete"
|
64
|
+
# get
|
65
|
+
# end
|
66
|
+
|
67
|
+
# # memory in MB, ust be multiple of 1024
|
68
|
+
# def modify(server_id, name = nil, description = nil, cpu_count = nil, memory = nil)
|
69
|
+
# query_params(
|
70
|
+
# name: name,
|
71
|
+
# description: description,
|
72
|
+
# cpu_count: cpu_count,
|
73
|
+
# memory: memory
|
74
|
+
# )
|
75
|
+
# org_endpoint "/server/#{server_id}"
|
76
|
+
# post
|
77
|
+
# end
|
78
|
+
|
79
|
+
# def start(server_id)
|
80
|
+
# org_endpoint "/server/#{server_id}?start"
|
81
|
+
# get
|
82
|
+
# end
|
83
|
+
|
84
|
+
# def shutdown(server_id)
|
85
|
+
# org_endpoint "/server/#{server_id}?shutdown"
|
86
|
+
# get
|
87
|
+
# end
|
88
|
+
|
89
|
+
# def poweroff(server_id)
|
90
|
+
# org_endpoint "/server/#{server_id}?poweroff"
|
91
|
+
# get
|
92
|
+
# end
|
93
|
+
|
94
|
+
# def reboot(server_id)
|
95
|
+
# org_endpoint "/server/#{server_id}?reboot"
|
96
|
+
# get
|
97
|
+
# end
|
98
|
+
|
99
|
+
# def reset(server_id)
|
100
|
+
# org_endpoint "/server/#{server_id}?reset"
|
101
|
+
# get
|
102
|
+
# end
|
103
|
+
|
104
|
+
# # amount is # of GBs
|
105
|
+
# def add_storage(server_id, amount)
|
106
|
+
# org_endpoint "/server/#{server_id}?addLocalStorage"
|
107
|
+
# query_params(amount: amount)
|
108
|
+
# get
|
109
|
+
# end
|
110
|
+
|
111
|
+
# def remove_storage(server_id, disk_id)
|
112
|
+
# org_endpoint "/server/#{server_id}/disk/#{disk_id}?delete"
|
113
|
+
# get
|
114
|
+
# end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module CloudControl::API
|
2
|
+
class VIP < Core
|
3
|
+
|
4
|
+
# Real Server section
|
5
|
+
def real_servers_list (network_id)
|
6
|
+
org_endpoint "/network/#{network_id}/realServer"
|
7
|
+
get
|
8
|
+
end
|
9
|
+
|
10
|
+
# Examples name = RealServer1, server_id = "415a7f70-1008-42a3-8375-5dcf52636cc5", in_service = true/false
|
11
|
+
def real_server_create (network_id, name, server_id, in_service)
|
12
|
+
org_endpoint "/network/#{network_id}/realServer"
|
13
|
+
xml_params(tag: "NewRealServer", schema: "vip", name: name, server_id: server_id, in_service: in_service)
|
14
|
+
post
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def real_server_delete (network_id, rserver_id)
|
19
|
+
org_endpoint "/network/#{network_id}/realServer/#{rserver_id}?delete"
|
20
|
+
get
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def real_server_modify (network_id, rserver_id, in_service)
|
25
|
+
org_endpoint "/network/#{network_id}/realServer/#{rserver_id}"
|
26
|
+
xml_params(in_service: in_service)
|
27
|
+
post
|
28
|
+
end
|
29
|
+
|
30
|
+
# Probe section
|
31
|
+
def probe_list (network_id)
|
32
|
+
org_endpoint "/network/#{network_id}/probe"
|
33
|
+
get
|
34
|
+
end
|
35
|
+
|
36
|
+
# Note this is for TCP, UDP & ICMP only additional xml fields need to be added to be complete
|
37
|
+
# Examples name = Probe1, type = TCP, probeIntervalSeconds = "60", errorCountBeforeServerFail = "5" maxReplyWaitSeconds = "10"
|
38
|
+
def probe_create
|
39
|
+
org_endpoint "/network/#{network_id}/probe"
|
40
|
+
xml_params(name: name, type: type, probeIntervalSeconds: probeIntervalSeconds, errorCountBeforeServerFail: errorCountBeforeServerFail, successCountBeforeServerEnable: successCountBeforeServerEnable, failedProbeIntervalSeconds: failedProbeIntervalSeconds, maxReplyWaitSeconds: maxReplyWaitSeconds)
|
41
|
+
post
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def probe_delete (network_id, probe_id)
|
46
|
+
org_endpoint "/network/#{network_id}/probe/{probe_id}?delete"
|
47
|
+
get
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Server Farm Section
|
52
|
+
def server_farm_list (network_id)
|
53
|
+
org_endpoint "/network/#{network_id}/serverFarm"
|
54
|
+
get
|
55
|
+
end
|
56
|
+
|
57
|
+
def server_farm_details (network_id, server_farm_id)
|
58
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}"
|
59
|
+
get
|
60
|
+
end
|
61
|
+
|
62
|
+
def server_farm_create (network_id, name, real_server_id, port, predictor)
|
63
|
+
if ["ROUND_ROBIN", "LEAST_CONNECTIONS"].include? predictor
|
64
|
+
org_endpoint "/network/#{network_id}/serverFarm"
|
65
|
+
xml_params(schema: "vip", tag: "NewServerFarm", name: name, predictor: predictor, real_server: {id: real_server_id, port: port})
|
66
|
+
post
|
67
|
+
else
|
68
|
+
raise "Unknown predictor: #{predictor}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def server_farm_delete (network_id, server_farm_id)
|
73
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}?delete"
|
74
|
+
get
|
75
|
+
end
|
76
|
+
|
77
|
+
# Examples realServerId = "RealServer1", realSeverPort = "80"
|
78
|
+
def real_server_to_server_farm (network_id, server_farm_id, real_server_id, real_server_port)
|
79
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}/addRealServer"
|
80
|
+
simple_params(real_server_id: real_server_id, real_server_port: real_server_port)
|
81
|
+
post_simple
|
82
|
+
end
|
83
|
+
|
84
|
+
# Examples realServerId = "RealServer1", realSeverPort = "80"
|
85
|
+
def real_server_from_server_farm (network_id, server_farm_id, real_server_id, real_server_port)
|
86
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}/removeRealServer"
|
87
|
+
simple_params(real_server_id: real_server_id, real_server_port: real_server_port)
|
88
|
+
post_simple
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# Examples probe_id = TCP1
|
93
|
+
def probe_to_server_farm (network_id, server_farm_id, probe_id)
|
94
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}/addProbe"
|
95
|
+
xml_params(probe_id: probe_id)
|
96
|
+
post
|
97
|
+
end
|
98
|
+
|
99
|
+
# Examples probe_id = TCP1
|
100
|
+
def probe_from_server_farm (network_id, server_farm_id, probe_id)
|
101
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}/removeProbe"
|
102
|
+
xml_params(probe_id: probe_id)
|
103
|
+
post
|
104
|
+
end
|
105
|
+
|
106
|
+
# Examples predictor= LEAST_CONNECTIONS | ROUND_ROBIN
|
107
|
+
def server_farm_predictor(network_id, server_farm_id, predictor)
|
108
|
+
org_endpoint "/network/#{network_id}/serverFarm/#{server_farm_id}"
|
109
|
+
xml_params(predictor: predictor)
|
110
|
+
post
|
111
|
+
end
|
112
|
+
|
113
|
+
def vip_list(network_id)
|
114
|
+
org_endpoint "/network/#{network_id}/vip"
|
115
|
+
get
|
116
|
+
end
|
117
|
+
|
118
|
+
def vip_create(network_id, name, port, protocol, server_farm_id)
|
119
|
+
org_endpoint "/network/#{network_id}/vip"
|
120
|
+
xml_params(schema: "vip", tag: "NewVip", name: name, port: port, protocol: protocol, vip_target_type: "SERVER_FARM", vip_target_id: server_farm_id, reply_to_icmp: true, in_service: true)
|
121
|
+
post
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module CloudControl
|
2
|
+
class Client
|
3
|
+
include CloudControl::Connection
|
4
|
+
include CloudControl::Params
|
5
|
+
# include CloudControl::XML
|
6
|
+
|
7
|
+
attr_reader :api_base, :org_id, :username, :password
|
8
|
+
attr_reader :image, :network, :server, :account, :report
|
9
|
+
attr_reader :datacenter, :default_password
|
10
|
+
|
11
|
+
### FILTERS
|
12
|
+
# client.page_size = 10
|
13
|
+
# client.page_number = 1
|
14
|
+
# client.order_by = 'location,created.DESCENDING'
|
15
|
+
# client.filter_with = {location: %w(NA1 NA2), key: 'value'}
|
16
|
+
attr_accessor :silent, :colors # log setting
|
17
|
+
attr_accessor :page_size, :page_number, :order_by, :filter_with
|
18
|
+
|
19
|
+
IMAGES = {suse_ent_64: "d4edfe22-e2f0-11e2-84e5-180373fb68df", ubuntu_14_04: "abef3a94-3361-4ce4-a937-5e587042586a", ubuntu_12_04: "d4ed6d40-e2f0-11e2-84e5-180373fb68df", ubuntu_10_04: "d4edba02-e2f0-11e2-84e5-180373fb68df"}
|
20
|
+
API_URL = {na: "https://api-na.dimensiondata.com/caas/2.8",
|
21
|
+
eu: "https://api-eu.dimensiondata.com/caas/2.8",
|
22
|
+
au: "https://api-au.dimensiondata.com/caas/2.8",
|
23
|
+
mea: "https://api-mea.dimensiondata.com/caas/2.8",
|
24
|
+
ap: "https://api-ap.dimensiondata.com/caas/2.8"}
|
25
|
+
|
26
|
+
|
27
|
+
def initialize(api_base, org_id, username, password, colors = true, silent = true)
|
28
|
+
@api_base = api_base
|
29
|
+
@org_id = org_id
|
30
|
+
@username = username
|
31
|
+
@password = password
|
32
|
+
@colors = colors
|
33
|
+
@silent = silent
|
34
|
+
|
35
|
+
if @colors
|
36
|
+
require 'colorize'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# def directory
|
41
|
+
# CloudControl::API::Directory.new(self)
|
42
|
+
# end
|
43
|
+
|
44
|
+
def image
|
45
|
+
CloudControl::API::Image.new(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def network
|
49
|
+
CloudControl::API::Network.new(self)
|
50
|
+
end
|
51
|
+
|
52
|
+
def server
|
53
|
+
CloudControl::API::Server.new(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
def account
|
57
|
+
CloudControl::API::Account.new(self)
|
58
|
+
end
|
59
|
+
|
60
|
+
def report
|
61
|
+
CloudControl::API::Report.new(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def vip
|
65
|
+
CloudControl::API::VIP.new(self)
|
66
|
+
end
|
67
|
+
|
68
|
+
def filter_params
|
69
|
+
params = {}
|
70
|
+
params[:page_size] = @page_size if @page_size.present?
|
71
|
+
params[:page_number] = @page_number if @page_number.present?
|
72
|
+
params[:order_by] = @order_by if @order_by.present?
|
73
|
+
|
74
|
+
if @filter_with.present?
|
75
|
+
@filter_with.each do |k, val|
|
76
|
+
params[k.to_sym] = val
|
77
|
+
end
|
78
|
+
end
|
79
|
+
params
|
80
|
+
end
|
81
|
+
|
82
|
+
# mode: bold, underscore, default
|
83
|
+
def log_error(message, color=nil, mode=nil)
|
84
|
+
log message, color, mode, true
|
85
|
+
end
|
86
|
+
def log(message, color = nil, mode = nil, error=nil)
|
87
|
+
return if (@silent && (not error))
|
88
|
+
if @colors
|
89
|
+
color = color.to_sym if color
|
90
|
+
mode = mode.to_sym if mode
|
91
|
+
puts message.colorize(:color => color, :mode => mode)
|
92
|
+
else
|
93
|
+
puts message
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module CloudControl
|
2
|
+
module Connection
|
3
|
+
def build_request(type, endpoint, query = nil, body = nil, xml=true)
|
4
|
+
uri = api_base + endpoint
|
5
|
+
append_query(uri, query) if query
|
6
|
+
|
7
|
+
if xml
|
8
|
+
request = Typhoeus::Request.new(
|
9
|
+
uri,
|
10
|
+
method: type,
|
11
|
+
body: body,
|
12
|
+
userpwd: "#{@username}:#{@password}",
|
13
|
+
headers: { 'Content-Type' =>'text/xml', 'User-Agent' => 'ACP Ruby SDK' }
|
14
|
+
)
|
15
|
+
else
|
16
|
+
request = Typhoeus::Request.new(
|
17
|
+
uri,
|
18
|
+
method: type,
|
19
|
+
body: body,
|
20
|
+
userpwd: "#{@username}:#{@password}",
|
21
|
+
headers: { 'User-Agent' => 'ACP Ruby SDK' }
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_query(uri, query)
|
27
|
+
if uri.include?('?')
|
28
|
+
uri << '&'
|
29
|
+
else
|
30
|
+
uri << '?'
|
31
|
+
end
|
32
|
+
uri << query
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def perform_request(request)
|
37
|
+
log "\nrequesting #{request.url}...", :yellow
|
38
|
+
request.run
|
39
|
+
end
|
40
|
+
|
41
|
+
def log_response(request, response)
|
42
|
+
if response.success?
|
43
|
+
log "...........success!", :yellow
|
44
|
+
elsif response.timed_out?
|
45
|
+
log_error "ERROR\n-----", :red
|
46
|
+
log_error "got a time out"
|
47
|
+
elsif response.code == 0
|
48
|
+
# Could not get an http response, something's wrong.
|
49
|
+
log_error "ERROR\n-----", :red
|
50
|
+
log_error response.return_message
|
51
|
+
else
|
52
|
+
# Received a non-successful http response.
|
53
|
+
log_error "ERROR\n-----", :red
|
54
|
+
log_error "HTTP request failed: " + response.code.to_s, :red
|
55
|
+
log_error response.body, :yellow
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module CloudControl
|
2
|
+
module Exceptions
|
3
|
+
CODES = {
|
4
|
+
"REASON_10" => "Failure at network",
|
5
|
+
"REASON_20" => "Unrecoverable failure cause by a timeout.",
|
6
|
+
"REASON_250" => "Network does not exist for this organization.",
|
7
|
+
"REASON_320" => "Invalid Input Data - SourceIP must be a valid IPv4 address."
|
8
|
+
}
|
9
|
+
|
10
|
+
class ApiError < StandardError; end
|
11
|
+
class ConnectionError < StandardError; end
|
12
|
+
class RequestError < StandardError; end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module CloudControl
|
2
|
+
module Params
|
3
|
+
def url_query(params)
|
4
|
+
params = camelize_keys(params)
|
5
|
+
qitems = []
|
6
|
+
params.each do |k, vs|
|
7
|
+
vs = [vs].flatten.compact # remove nil values
|
8
|
+
vs.each {|v| qitems << "#{k}=#{v}"}
|
9
|
+
end
|
10
|
+
qitems.join('&')
|
11
|
+
end
|
12
|
+
|
13
|
+
def symbolize_keys(arg)
|
14
|
+
case arg
|
15
|
+
when Array
|
16
|
+
arg.map { |elem| symbolize_keys elem }
|
17
|
+
when Hash
|
18
|
+
Hash[
|
19
|
+
arg.map { |key, value|
|
20
|
+
k = key.is_a?(String) ? key.to_sym : key
|
21
|
+
v = symbolize_keys value
|
22
|
+
[k,v]
|
23
|
+
}]
|
24
|
+
else
|
25
|
+
arg
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def underscore_keys(arg)
|
30
|
+
case arg
|
31
|
+
when Array
|
32
|
+
arg.map { |elem| underscore_keys elem }
|
33
|
+
when Hash
|
34
|
+
Hash[
|
35
|
+
arg.map { |key, value|
|
36
|
+
k = key.is_a?(String) ? key.underscore : key
|
37
|
+
v = underscore_keys value
|
38
|
+
[k,v]
|
39
|
+
}]
|
40
|
+
else
|
41
|
+
arg
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def camelize_keys(arg)
|
46
|
+
case arg
|
47
|
+
when Array
|
48
|
+
arg.map { |elem| camelize_keys elem }
|
49
|
+
when Hash
|
50
|
+
Hash[
|
51
|
+
arg.map { |key, value|
|
52
|
+
k = key.is_a?(String) ? key.camelize(:lower) : key
|
53
|
+
k = key.is_a?(Symbol) ? key.to_s.camelize(:lower).to_sym : key
|
54
|
+
v = camelize_keys value
|
55
|
+
[k,v]
|
56
|
+
}]
|
57
|
+
else
|
58
|
+
arg
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudcontrol_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nigel Wright
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: typhoeus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: xml-simple
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: SDK to access NTT Cloud Control api'
|
98
|
+
email:
|
99
|
+
- nigel.wright@global.ntt
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE
|
107
|
+
- README.md
|
108
|
+
- cloudcontrol.gemspec
|
109
|
+
- lib/cloudcontrol.rb
|
110
|
+
- lib/cloudcontrol/api/account.rb
|
111
|
+
- lib/cloudcontrol/api/core.rb
|
112
|
+
- lib/cloudcontrol/api/image.rb
|
113
|
+
- lib/cloudcontrol/api/infrastructure.rb
|
114
|
+
- lib/cloudcontrol/api/network.rb
|
115
|
+
- lib/cloudcontrol/api/report.rb
|
116
|
+
- lib/cloudcontrol/api/server.rb
|
117
|
+
- lib/cloudcontrol/api/vip.rb
|
118
|
+
- lib/cloudcontrol/client.rb
|
119
|
+
- lib/cloudcontrol/connection.rb
|
120
|
+
- lib/cloudcontrol/exceptions.rb
|
121
|
+
- lib/cloudcontrol/params.rb
|
122
|
+
- lib/cloudcontrol/version.rb
|
123
|
+
homepage: ''
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubygems_version: 3.0.6
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: NTT Cloud Control REST API client gem
|
146
|
+
test_files: []
|