cumulogic_client 0.0.3 → 0.0.4
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 +8 -8
- data/lib/cumulogic_client.rb +3 -0
- data/lib/cumulogic_client/base_client.rb +70 -67
- data/lib/cumulogic_client/nosql.rb +68 -66
- data/lib/cumulogic_client/version.rb +1 -1
- data/spec/base_client_spec.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGM0OTUzZWIzZTdjMzA4Y2Q5ODQ0NjNmZGJmM2RkYzEyMzI3ZGY4OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmRiNzI3ZWE4NWY4MGYyMTRlMTEwYzZiZTZjNTIzOTE2NTNhYWE5MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDdiNTY3MTI5NGZlNWU5N2FiMGU2NGU2M2MyNDczMjZhODUwNmY4YjllYmY3
|
10
|
+
Zjk4MmVlYzczNDQ5ODVjZWM2NzRkZDUwMWI2ZjRhMjE1NDE3MTU2YjdmY2Y3
|
11
|
+
NTllODJjNTU2Mzc4MjU1YjI3ZWUxZjFhZDViM2M0YTY5Yzk4OTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjljMjIwZTE2MDJhYjVmOGQ4MzY1YjU5NjY3ZDVjYTUxNTFmYjE4MGY1Njg5
|
14
|
+
Yzk5YTRkMzUxMTM3ZWVmOTIyYzhkYWFkOTBlOTdhNjVhZTMyZjM4OTRiZGEz
|
15
|
+
MTc0MmQzYjg2ZTI4NGYxMzViYjBhYzY4ODQwYmY2Nzk0NjkxYjE=
|
data/lib/cumulogic_client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# Copyright 2014 CumuLogic, Inc
|
2
1
|
#
|
3
2
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
3
|
# you may not use this file except in compliance with the License.
|
@@ -14,84 +13,88 @@
|
|
14
13
|
|
15
14
|
require 'timeout'
|
16
15
|
|
17
|
-
|
18
|
-
def initialize(api_url, username, password, use_ssl=nil, debug=false)
|
19
|
-
@api_url = api_url
|
20
|
-
@username = username
|
21
|
-
@password = password
|
22
|
-
@use_ssl = use_ssl
|
23
|
-
@debug = debug
|
24
|
-
@validationparams = nil
|
25
|
-
end
|
16
|
+
module CumulogicClient
|
26
17
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
def request(command, params=nil)
|
37
|
-
url = "#{@api_url}#{command}"
|
38
|
-
puts url if @debug
|
39
|
-
puts params.to_json if @debug
|
40
|
-
uri = URI.parse(url)
|
41
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
42
|
-
http.use_ssl = @use_ssl
|
43
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
44
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
45
|
-
request.body = URI::encode(params.to_json) if params
|
46
|
-
response = http.request(request)
|
18
|
+
class CumulogicClient::BaseClient
|
19
|
+
def initialize(api_url, username, password, use_ssl=nil, debug=false)
|
20
|
+
@api_url = api_url
|
21
|
+
@username = username
|
22
|
+
@password = password
|
23
|
+
@use_ssl = use_ssl
|
24
|
+
@debug = debug
|
25
|
+
@validationparams = nil
|
26
|
+
end
|
47
27
|
|
48
|
-
|
49
|
-
if
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
28
|
+
def call(command, params=nil)
|
29
|
+
login() if not @validationparams
|
30
|
+
callparams = Hash.new()
|
31
|
+
callparams[:inputParams] = Array.new(1)
|
32
|
+
callparams[:inputParams][0] = params if params
|
33
|
+
callparams[:validationParams] = @validationparams
|
34
|
+
request(command, callparams)
|
54
35
|
end
|
55
36
|
|
56
|
-
|
37
|
+
def request(command, params=nil)
|
38
|
+
url = "#{@api_url}#{command}"
|
39
|
+
puts url if @debug
|
40
|
+
puts params.to_json if @debug
|
41
|
+
uri = URI.parse(url)
|
42
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
43
|
+
http.use_ssl = @use_ssl
|
44
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
45
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
46
|
+
request.body = URI::encode(params.to_json) if params
|
47
|
+
response = http.request(request)
|
57
48
|
|
58
|
-
|
49
|
+
if !response.is_a?(Net::HTTPOK)
|
50
|
+
if ["431","530","404"].include?(response.code)
|
51
|
+
raise ArgumentError, response.message
|
52
|
+
end
|
53
|
+
raise RuntimeError, "Username and password not accepted" if ["401","403"].include?(response.code)
|
54
|
+
raise RuntimeError, "Unknown error: code=#{response.code} message=#{response.message}"
|
55
|
+
end
|
59
56
|
|
60
|
-
|
61
|
-
return responsedata["response"]
|
57
|
+
puts response.body if @debug
|
62
58
|
|
63
|
-
|
59
|
+
responsedata = JSON.parse(response.body)
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
credentials[0] = {
|
68
|
-
"userName" => @username,
|
69
|
-
"password" => @password
|
70
|
-
}
|
71
|
-
login_params = Hash.new
|
72
|
-
login_params["validationParams"] = Hash.new
|
73
|
-
login_params["inputParams"] = credentials
|
74
|
-
loginresponse = request("auth/login", login_params)
|
75
|
-
@validationparams = {
|
76
|
-
"userID" => loginresponse[0]["userID"],
|
77
|
-
"userName" => loginresponse[0]["userName"],
|
78
|
-
"userLoginToken" => loginresponse[0]["userLoginToken"]
|
79
|
-
}
|
61
|
+
raise RuntimeError, "Errors: #{responsedata["errors"]}" if not responsedata["success"]
|
62
|
+
return responsedata["response"]
|
80
63
|
|
81
|
-
|
64
|
+
end
|
65
|
+
|
66
|
+
def login()
|
67
|
+
credentials = Array.new(1)
|
68
|
+
credentials[0] = {
|
69
|
+
"userName" => @username,
|
70
|
+
"password" => @password
|
71
|
+
}
|
72
|
+
login_params = Hash.new
|
73
|
+
login_params["validationParams"] = Hash.new
|
74
|
+
login_params["inputParams"] = credentials
|
75
|
+
loginresponse = request("auth/login", login_params)
|
76
|
+
@validationparams = {
|
77
|
+
"userID" => loginresponse[0]["userID"],
|
78
|
+
"userName" => loginresponse[0]["userName"],
|
79
|
+
"userLoginToken" => loginresponse[0]["userLoginToken"]
|
80
|
+
}
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
82
|
+
end
|
83
|
+
|
84
|
+
def provisioning_completed(targetobject, timeout=nil)
|
85
|
+
return Timeout::timeout(timeout) do
|
86
|
+
while true do
|
87
|
+
if not targetobject.isComplete()
|
88
|
+
puts "returned false"
|
89
|
+
sleep 10
|
90
|
+
else
|
91
|
+
puts "returned true"
|
92
|
+
return true
|
93
|
+
end
|
94
|
+
end
|
93
95
|
end
|
94
96
|
end
|
97
|
+
|
95
98
|
end
|
96
99
|
|
97
100
|
end
|
@@ -12,80 +12,82 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
module CumulogicClient
|
16
|
+
class Nosql
|
17
|
+
def initialize(api_url, username, password, use_ssl=nil, debug=false)
|
18
|
+
@client = CumulogicClient::BaseClient.new(api_url, username, password, use_ssl, debug)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def engine_list()
|
22
|
+
return @client.call('nosql/nosqlengine/list')
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def list()
|
26
|
+
return @client.call('nosql/instance/list')
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
def events(instanceId)
|
30
|
+
params = {
|
31
|
+
'noSqlInstanceId' => instanceId
|
32
|
+
}
|
33
|
+
return @client.call('nosql/instance/showEvents', params)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
def delete(instanceId)
|
37
|
+
params = {
|
38
|
+
'noSqlInstanceId' => instanceId
|
39
|
+
}
|
40
|
+
return @client.call('nosql/instance/deleteNoSqlInstance', params)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
def create(spec)
|
44
|
+
response = @client.call('nosql/instance/createNoSqlInstance', spec.to_hash)
|
45
|
+
@newInstanceId = response[0]['noSqlInstanceId']
|
46
|
+
@client.provisioning_completed(self, 30)
|
47
|
+
return @newInstanceId
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
def isComplete()
|
51
|
+
instances = self.list()
|
52
|
+
puts instances
|
53
|
+
target = instances.select { |id| id["noSqlInstanceId"] = @newInstanceId }
|
54
|
+
return false if (target[0]["status"] == 2)
|
55
|
+
raise RuntimeError, "Error provisioning instance: #{target[0]["errorMessage"]}" if (target[0]["status"] == 3)
|
56
|
+
return true
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
59
|
+
NoSQLSpec = Class.new do
|
60
|
+
attr_accessor :name
|
61
|
+
attr_accessor :description
|
62
|
+
attr_accessor :nodes
|
63
|
+
attr_accessor :collectionName
|
64
|
+
attr_accessor :characterSet
|
65
|
+
attr_accessor :port
|
66
|
+
attr_accessor :noSqlEngineId
|
67
|
+
attr_accessor :targetCloudId
|
68
|
+
attr_accessor :availabilityZoneName
|
69
|
+
attr_accessor :instanceTypeId
|
70
|
+
attr_accessor :serviceTag
|
71
|
+
attr_accessor :accessGroupId
|
72
|
+
attr_accessor :noSqlParamGroupId
|
73
|
+
attr_accessor :storageSize
|
74
|
+
attr_accessor :isbackupPreferenceSet
|
75
|
+
attr_accessor :isAutoUpdateEnabled
|
76
|
+
attr_accessor :backupRetentionPeriod
|
77
|
+
attr_accessor :backupStartTime
|
78
|
+
attr_accessor :ownerType
|
79
|
+
attr_accessor :isAvailabilityZoneMandatory
|
80
|
+
attr_accessor :isInstanceTypeMandatory
|
81
|
+
attr_accessor :availabilityZone
|
82
|
+
attr_accessor :isVolumeSizeMandatory
|
83
|
+
attr_accessor :backupRetentionPeriod
|
84
|
+
attr_accessor :backupStartTime
|
85
|
+
attr_accessor :start
|
85
86
|
|
86
|
-
|
87
|
-
|
87
|
+
def to_hash
|
88
|
+
Hash[*instance_variables.map { |v| [v.to_s().tr("@", ""), instance_variable_get(v)] }.flatten]
|
89
|
+
end
|
88
90
|
end
|
89
|
-
end
|
90
91
|
|
92
|
+
end
|
91
93
|
end
|
data/spec/base_client_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cumulogic_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chip Childers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|