cloudmunch_sdk_v3 3.0.0
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/lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb +146 -0
- data/lib/cloudmunch_Ruby_sdk_v2/AppContext.rb +59 -0
- data/lib/cloudmunch_Ruby_sdk_v2/AssetHelper.rb +127 -0
- data/lib/cloudmunch_Ruby_sdk_v2/CloudmunchConstants.rb +24 -0
- data/lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb +249 -0
- data/lib/cloudmunch_Ruby_sdk_v2/ElasticBeanStalkServer.rb +52 -0
- data/lib/cloudmunch_Ruby_sdk_v2/EnvironmentHelper.rb +292 -0
- data/lib/cloudmunch_Ruby_sdk_v2/InsightHelper.rb +770 -0
- data/lib/cloudmunch_Ruby_sdk_v2/IntegrationHelper.rb +69 -0
- data/lib/cloudmunch_Ruby_sdk_v2/PluginLoaderAbstract.rb +140 -0
- data/lib/cloudmunch_Ruby_sdk_v2/PluginReporterAbstract.rb +141 -0
- data/lib/cloudmunch_Ruby_sdk_v2/RoleHelper.rb +170 -0
- data/lib/cloudmunch_Ruby_sdk_v2/Server.rb +77 -0
- data/lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb +284 -0
- data/lib/cloudmunch_Ruby_sdk_v2/ServiceProvider.rb +25 -0
- data/lib/cloudmunch_Ruby_sdk_v2/Util.rb +119 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/AppAbstract.html +1062 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/AppContext.html +1402 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/AssetHelper.html +694 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/Cloudmunch.html +117 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/CloudmunchConstants.html +184 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/CloudmunchService.html +1195 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/ElasticBeanStalkServer.html +1375 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/InsightHelper.html +2889 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/IntegrationHelper.html +400 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/RoleHelper.html +809 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/Server.html +2302 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/ServerHelper.html +1181 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/ServiceProvider.html +328 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/Util.html +540 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/_index.html +214 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/class_list.html +58 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/css/common.css +1 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/css/full_list.css +57 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/css/style.css +339 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/file_list.html +57 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/frames.html +26 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/index.html +214 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/js/app.js +219 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/js/full_list.js +181 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/js/jquery.js +4 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/method_list.html +993 -0
- data/lib/cloudmunch_Ruby_sdk_v2/doc/top-level-namespace.html +114 -0
- data/lib/cloudmunch_Ruby_sdk_v2/version.rb +3 -0
- data/lib/cloudmunch_Ruby_sdk_v3/AppAbstract.rb +146 -0
- data/lib/cloudmunch_Ruby_sdk_v3/AppContext.rb +59 -0
- data/lib/cloudmunch_Ruby_sdk_v3/AssetHelper.rb +127 -0
- data/lib/cloudmunch_Ruby_sdk_v3/CloudmunchConstants.rb +24 -0
- data/lib/cloudmunch_Ruby_sdk_v3/CloudmunchService.rb +300 -0
- data/lib/cloudmunch_Ruby_sdk_v3/ElasticBeanStalkServer.rb +52 -0
- data/lib/cloudmunch_Ruby_sdk_v3/EnvironmentHelper.rb +292 -0
- data/lib/cloudmunch_Ruby_sdk_v3/InsightHelper.rb +770 -0
- data/lib/cloudmunch_Ruby_sdk_v3/IntegrationHelper.rb +69 -0
- data/lib/cloudmunch_Ruby_sdk_v3/PluginLoaderAbstract.rb +140 -0
- data/lib/cloudmunch_Ruby_sdk_v3/PluginReporterAbstract.rb +141 -0
- data/lib/cloudmunch_Ruby_sdk_v3/RoleHelper.rb +170 -0
- data/lib/cloudmunch_Ruby_sdk_v3/Server.rb +77 -0
- data/lib/cloudmunch_Ruby_sdk_v3/ServerHelper.rb +284 -0
- data/lib/cloudmunch_Ruby_sdk_v3/ServiceProvider.rb +25 -0
- data/lib/cloudmunch_Ruby_sdk_v3/Util.rb +119 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/AppAbstract.html +1062 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/AppContext.html +1402 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/AssetHelper.html +694 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/Cloudmunch.html +117 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/CloudmunchConstants.html +184 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/CloudmunchService.html +1195 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/ElasticBeanStalkServer.html +1375 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/InsightHelper.html +2889 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/IntegrationHelper.html +400 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/RoleHelper.html +809 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/Server.html +2302 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/ServerHelper.html +1181 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/ServiceProvider.html +328 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/Util.html +540 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/_index.html +214 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/class_list.html +58 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/css/common.css +1 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/css/full_list.css +57 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/css/style.css +339 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/file_list.html +57 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/frames.html +26 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/index.html +214 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/js/app.js +219 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/js/full_list.js +181 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/js/jquery.js +4 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/method_list.html +993 -0
- data/lib/cloudmunch_Ruby_sdk_v3/doc/top-level-namespace.html +114 -0
- data/lib/cloudmunch_Ruby_sdk_v3/version.rb +3 -0
- data/lib/cloudmunch_sdk.rb +5 -0
- data/lib/cloudmunch_sdk_v3.rb +5 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a307ebe2d38a7538a9b8aafd1e93b1de349aac54
|
4
|
+
data.tar.gz: 8407081379ce3deb467a57b3e1f7a8f23d75a5f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb485f0f0af99d19a361813d03b7727a3bc15c1da48ad8c23a518c365243d78ff3303102c83891b34d2fea280a8184389a45bc6d1f3450671870d672e13fbd9f
|
7
|
+
data.tar.gz: b083500d731499aa79ce7e09352fa79b48983d949102aa6b0765a53906ab85159ed023db233e6f4c9e29d4189890c90bd2b96f8ba3adca31c834e4c4f8da7299
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
$LOAD_PATH << '.'
|
3
|
+
|
4
|
+
require_relative "CloudmunchService"
|
5
|
+
require_relative "InsightHelper"
|
6
|
+
require_relative "Util"
|
7
|
+
require_relative "ServiceProvider"
|
8
|
+
require_relative "AppContext"
|
9
|
+
|
10
|
+
class AppAbstract
|
11
|
+
include CloudmunchService
|
12
|
+
include InsightHelper
|
13
|
+
include Util
|
14
|
+
|
15
|
+
@@config = nil
|
16
|
+
|
17
|
+
def initialize(param = nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def logInit(log_level)
|
21
|
+
@logger = @logger ? @logger : Util.logInit()
|
22
|
+
@log_level = log_level
|
23
|
+
end
|
24
|
+
|
25
|
+
def log(level,logString)
|
26
|
+
if @logger.nil?
|
27
|
+
logInit("DEBUG")
|
28
|
+
end
|
29
|
+
Util.logIt(@logger, @log_level, level.to_s.downcase, logString)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def logClose()
|
34
|
+
Util.logClose(@logger)
|
35
|
+
end
|
36
|
+
|
37
|
+
def getJSONArgs()
|
38
|
+
jsonin = nil
|
39
|
+
varin=nil
|
40
|
+
integrations=nil
|
41
|
+
loop { case ARGV[0]
|
42
|
+
when '-jsoninput' then ARGV.shift; jsonin = ARGV.shift
|
43
|
+
when '-variables' then ARGV.shift; varin = ARGV.shift
|
44
|
+
when '-integrations' then ARGV.shift; integrations = ARGV.shift
|
45
|
+
|
46
|
+
when /^-/ then usage("Unknown option: #{ARGV[0].inspect}")
|
47
|
+
else break
|
48
|
+
end; }
|
49
|
+
@json_input = JSON.load(jsonin)
|
50
|
+
@var_input =JSON.load(varin)
|
51
|
+
@integration_input=JSON.load(integrations)
|
52
|
+
createAppContext();
|
53
|
+
return @json_input
|
54
|
+
end
|
55
|
+
|
56
|
+
def createAppContext()
|
57
|
+
@appContext = AppContext.new(@var_input)
|
58
|
+
end
|
59
|
+
|
60
|
+
def getAppContext()
|
61
|
+
return @appContext
|
62
|
+
end
|
63
|
+
|
64
|
+
# def getCloudmunchContext(context)
|
65
|
+
# begin
|
66
|
+
# return @@config[context+"_context"]
|
67
|
+
# rescue
|
68
|
+
# return false
|
69
|
+
# end
|
70
|
+
# end
|
71
|
+
|
72
|
+
def getCloudmunchService()
|
73
|
+
@cloudmunchservice = self.extend(CloudmunchService)
|
74
|
+
return @cloudmunchservice
|
75
|
+
end
|
76
|
+
|
77
|
+
def getInsightHelper()
|
78
|
+
@insightHelper = self.extend(InsightHelper)
|
79
|
+
return @insightHelper
|
80
|
+
end
|
81
|
+
|
82
|
+
def getIntegrationDetails(param = nil)
|
83
|
+
serviceProvider = ServiceProvider.new(@json_input["providername"])
|
84
|
+
serviceProvider.load_data(@integration_input)
|
85
|
+
return serviceProvider
|
86
|
+
end
|
87
|
+
|
88
|
+
def initializeApp()
|
89
|
+
end
|
90
|
+
|
91
|
+
def process()
|
92
|
+
end
|
93
|
+
|
94
|
+
def cleanupApp()
|
95
|
+
log("INFO", "\nExiting app")
|
96
|
+
end
|
97
|
+
|
98
|
+
def start()
|
99
|
+
initializeApp()
|
100
|
+
process()
|
101
|
+
cleanupApp()
|
102
|
+
end
|
103
|
+
|
104
|
+
# def openJSONFile(fileNameWithPath)
|
105
|
+
# Util.openJSONFile(fileNameWithPath)
|
106
|
+
# end
|
107
|
+
|
108
|
+
# def generateReport(reportFilename, reportString)
|
109
|
+
# Util.generateReport(reportFilename, reportString)
|
110
|
+
# end
|
111
|
+
|
112
|
+
# def getDataContextFromCMDB(param)
|
113
|
+
# appContext = getAppContext()
|
114
|
+
# params = {
|
115
|
+
# "username" => @@config['username'],
|
116
|
+
# "customcontext" => param["job"] + "_" + param["context"],
|
117
|
+
# "action" => "listcustomcontext"
|
118
|
+
# }
|
119
|
+
# param.delete("context")
|
120
|
+
# params = param.merge(params)
|
121
|
+
|
122
|
+
# return CloudmunchService.getDataContext(appContext.get_data('masterurl'), @@config["endpoint"], params)
|
123
|
+
# end
|
124
|
+
|
125
|
+
# def updateDataContextToCMDB(param)
|
126
|
+
# appContext = getAppContext()
|
127
|
+
# params = {
|
128
|
+
# "username" => @@config['username'],
|
129
|
+
# "customcontext" => param["job"] + "_" + param["context"],
|
130
|
+
# "action" => "updatecustomcontext"
|
131
|
+
# }
|
132
|
+
# param.delete("context")
|
133
|
+
# params = param.merge(params)
|
134
|
+
# return CloudmunchService.updateDataContext(appContext.get_data('masterurl'), @@config['endpoint'], params)
|
135
|
+
# end
|
136
|
+
|
137
|
+
# def getTemplate(template_name)
|
138
|
+
# begin
|
139
|
+
# Util.getTemplate(template_name)
|
140
|
+
# rescue
|
141
|
+
# return false
|
142
|
+
# end
|
143
|
+
# end
|
144
|
+
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
###
|
3
|
+
### (c) CloudMunch Inc.
|
4
|
+
### All Rights Reserved
|
5
|
+
### Un-authorized copying of this file, via any medium is strictly prohibited
|
6
|
+
### Proprietary and confidential
|
7
|
+
###
|
8
|
+
### ganesan@cloudmunch.com
|
9
|
+
###
|
10
|
+
|
11
|
+
$LOAD_PATH << '.'
|
12
|
+
|
13
|
+
class AppContext
|
14
|
+
attr_accessor :masterurl
|
15
|
+
attr_accessor :cloudproviders
|
16
|
+
attr_accessor :domainName
|
17
|
+
attr_accessor :project
|
18
|
+
attr_accessor :job
|
19
|
+
attr_accessor :workspaceLocation
|
20
|
+
attr_accessor :archiveLocation
|
21
|
+
attr_accessor :stepid
|
22
|
+
attr_accessor :targetServer
|
23
|
+
attr_accessor :integrations
|
24
|
+
attr_accessor :reportsLocation
|
25
|
+
attr_accessor :runnumber
|
26
|
+
attr_accessor :apikey
|
27
|
+
attr_accessor :stepname
|
28
|
+
attr_accessor :environmentId
|
29
|
+
|
30
|
+
|
31
|
+
def initialize(param)
|
32
|
+
@masterurl = ""
|
33
|
+
@cloudproviders = ""
|
34
|
+
@domainName = ""
|
35
|
+
@project = ""
|
36
|
+
@job = ""
|
37
|
+
@workspaceLocation = ""
|
38
|
+
@archiveLocation = ""
|
39
|
+
@stepid = ""
|
40
|
+
@targetServer=""
|
41
|
+
@integrations=""
|
42
|
+
@reportsLocation=""
|
43
|
+
@runnumber=""
|
44
|
+
@apikey=""
|
45
|
+
@stepname=""
|
46
|
+
@environmentId=""
|
47
|
+
load_data(param)
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_data(param)
|
51
|
+
@AppContextParams = param
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_data(keyname)
|
55
|
+
@AppContextParams[keyname]
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
###
|
3
|
+
### (c) CloudMunch Inc.
|
4
|
+
### All Rights Reserved
|
5
|
+
### Un-authorized copying of this file, via any medium is strictly prohibited
|
6
|
+
### Proprietary and confidential
|
7
|
+
###
|
8
|
+
### ganesan@cloudmunch.com
|
9
|
+
###
|
10
|
+
|
11
|
+
$LOAD_PATH << '.'
|
12
|
+
require 'json'
|
13
|
+
require_relative "CloudmunchConstants"
|
14
|
+
|
15
|
+
class AssetHelper
|
16
|
+
include CloudmunchService
|
17
|
+
include Util
|
18
|
+
|
19
|
+
@appContext = nil;
|
20
|
+
@cmDataManager = nil;
|
21
|
+
@logHelper = nil;
|
22
|
+
|
23
|
+
def initialize(appContext)
|
24
|
+
@appContext = appContext
|
25
|
+
@cloudmunchDataService = CloudmunchService.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def getAsset(assetID, filterData)
|
29
|
+
paramHash = {}
|
30
|
+
if !filterData.nil?
|
31
|
+
paramHash["filter"] = filterData.to_json
|
32
|
+
end
|
33
|
+
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
|
34
|
+
assetResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIJey(), paramHash)
|
35
|
+
|
36
|
+
if assetResult == nil then
|
37
|
+
log("ERROR", "Unable to get data from cloudmunch")
|
38
|
+
return nil
|
39
|
+
else
|
40
|
+
assetResult = JSON.parse(assetResult)
|
41
|
+
assetData = assetResult["data"]
|
42
|
+
if assetData.nil? then
|
43
|
+
log("ERROR", "Asset does not exist")
|
44
|
+
return nil
|
45
|
+
else
|
46
|
+
return assetData
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def addAsset(assetName, assetType, assetStatus, assetExternalRef, assetData)
|
52
|
+
if assetName.empty? || assetType.empty? || assetStatus.empty? then
|
53
|
+
log("ERROR", "Asset name ,status and type need to be provided")
|
54
|
+
return false
|
55
|
+
end
|
56
|
+
|
57
|
+
statusArray = [::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL]
|
58
|
+
if !statusArray.include?(assetStatus) then
|
59
|
+
log("ERROR", "Invalid status sent. Allowed values " + ::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL)
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
|
63
|
+
assetData["name"] = assetName
|
64
|
+
assetData["type"] = assetType
|
65
|
+
assetData["status"] = assetStatus
|
66
|
+
assetData["external_reference"] = assetExternalRef
|
67
|
+
|
68
|
+
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/"
|
69
|
+
retResult = @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), assetData)
|
70
|
+
|
71
|
+
if retResult == nil then
|
72
|
+
return nil
|
73
|
+
else
|
74
|
+
retResult = JSON.parse(retResult)
|
75
|
+
retData = retResult["data"]
|
76
|
+
if retData.nil? then
|
77
|
+
return nil
|
78
|
+
else
|
79
|
+
return retData
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
def updateAsset(assetID, assetData)
|
87
|
+
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
|
88
|
+
@cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), assetData)
|
89
|
+
end
|
90
|
+
|
91
|
+
def deleteAsset(assetID)
|
92
|
+
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
|
93
|
+
@cloudmunchDataService.deleteDataForContext(serverUrl, @appContext.getAPIKey())
|
94
|
+
end
|
95
|
+
|
96
|
+
def updateStatus(assetID, status)
|
97
|
+
statusArray = [::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL]
|
98
|
+
if !statusArray.include?(status) then
|
99
|
+
log("ERROR", "Invalid status")
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
|
103
|
+
assetData = {}
|
104
|
+
assetData["status"] = status
|
105
|
+
updateAsset(assetID, assetData)
|
106
|
+
end
|
107
|
+
|
108
|
+
def checkIfAssetExists(assetID)
|
109
|
+
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
|
110
|
+
|
111
|
+
assetResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), "")
|
112
|
+
if assetResult == nil then
|
113
|
+
return nil
|
114
|
+
else
|
115
|
+
assetResult = JSON.parse(assetResult)
|
116
|
+
assetData = assetResult["data"]
|
117
|
+
if assetData.nil? then
|
118
|
+
log("ERROR", "Asset does not exist")
|
119
|
+
return false
|
120
|
+
else
|
121
|
+
return true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
###
|
3
|
+
### (c) CloudMunch Inc.
|
4
|
+
### All Rights Reserved
|
5
|
+
### Un-authorized copying of this file, via any medium is strictly prohibited
|
6
|
+
### Proprietary and confidential
|
7
|
+
###
|
8
|
+
### ganesan@cloudmunch.com
|
9
|
+
###
|
10
|
+
|
11
|
+
$LOAD_PATH << '.'
|
12
|
+
|
13
|
+
class CloudmunchConstants
|
14
|
+
#Assets
|
15
|
+
STATUS_RUNNING = 'running'
|
16
|
+
STATUS_STOPPED = 'stopped'
|
17
|
+
STATUS_NIL = 'NIL'
|
18
|
+
|
19
|
+
#Environments
|
20
|
+
STATUS_RUNNING_WITH_WARNING = 'running_with_warning'
|
21
|
+
STATUS_STOPPED_WITH_ERRORS = 'stopped_with_errors'
|
22
|
+
STATUS_ACTION_IN_PROGRESS = 'action_in_progress'
|
23
|
+
STATUS_CREATION_IN_PROGRESS = 'creation_in_progress'
|
24
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require_relative "Util"
|
8
|
+
|
9
|
+
module CloudmunchService
|
10
|
+
include Util
|
11
|
+
|
12
|
+
##################################################################################
|
13
|
+
###
|
14
|
+
### downloadKeys(filekey, context, contextid)
|
15
|
+
### deleteKeys()
|
16
|
+
### getCloudmunchData(paramHash)
|
17
|
+
### updateCloudmunchData(paramHash, method = "POST")
|
18
|
+
### deleteCloudmunchData(paramHash)
|
19
|
+
### parseResponse(responseJson)
|
20
|
+
### generateServerURL(paramHash, appendQueryParams = nil)
|
21
|
+
###
|
22
|
+
###
|
23
|
+
##################################################################################
|
24
|
+
|
25
|
+
def downloadKeys(filekey, context, contextid)
|
26
|
+
|
27
|
+
paramHash = Hash.new
|
28
|
+
paramHash["context"] = context
|
29
|
+
paramHash["contextID"] = contextid
|
30
|
+
paramHash["file"] = filekey
|
31
|
+
|
32
|
+
keyString = getCloudmunchData(paramHash)
|
33
|
+
|
34
|
+
if !keyString.to_s == ""
|
35
|
+
log("ERROR", "downloaded key content is empty, please re-upload key and try")
|
36
|
+
return nil
|
37
|
+
end
|
38
|
+
|
39
|
+
filename = "keyfile_" + Time.now.strftime('%Y%m%d%H%M%S%L')
|
40
|
+
file = @appContext.get_data("{workspace}")+"/"+filename
|
41
|
+
|
42
|
+
File.open(file, 'w') { |file| file.write(keyString) }
|
43
|
+
system('chmod 400 '+file)
|
44
|
+
|
45
|
+
if @keyArray.nil?
|
46
|
+
@keyArray = []
|
47
|
+
end
|
48
|
+
|
49
|
+
@keyArray.push(file)
|
50
|
+
return file;
|
51
|
+
end
|
52
|
+
|
53
|
+
def deleteKeys()
|
54
|
+
fileName = @appContext.get_data("{workspace}")+"/keyfile_*"
|
55
|
+
File.delete(fileName)
|
56
|
+
end
|
57
|
+
|
58
|
+
def getCloudmunchData(paramHash)
|
59
|
+
serverurl = nil
|
60
|
+
serverurl = generateServerURL(paramHash,true)
|
61
|
+
|
62
|
+
if serverurl.nil?
|
63
|
+
log("DEBUG", "Unable to generate server url")
|
64
|
+
log("ERROR", "Unable to get data from cloudmunch")
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
uri = URI.parse(serverurl)
|
69
|
+
|
70
|
+
log("DEBUG", "URI for get : ")
|
71
|
+
log("DEBUG", uri)
|
72
|
+
|
73
|
+
responseJson = Net::HTTP.get(uri)
|
74
|
+
|
75
|
+
parseResponse(responseJson)
|
76
|
+
end
|
77
|
+
|
78
|
+
def updateCloudmunchData(paramHash, method = "POST")
|
79
|
+
paramData = Hash.new
|
80
|
+
paramData["data"] = paramHash["data"]
|
81
|
+
|
82
|
+
serverurl = nil
|
83
|
+
serverurl = generateServerURL(paramHash)
|
84
|
+
|
85
|
+
if serverurl.nil?
|
86
|
+
log("DEBUG", "Unable to generate server url")
|
87
|
+
log("ERROR", "Unable to "+method+" data on cloudmunch")
|
88
|
+
return nil
|
89
|
+
end
|
90
|
+
|
91
|
+
uri = URI.parse(serverurl)
|
92
|
+
|
93
|
+
log("DEBUG", "URI for "+method+" : ")
|
94
|
+
log("DEBUG", uri)
|
95
|
+
|
96
|
+
if method.casecmp("post") == 0
|
97
|
+
responseJson = Net::HTTP.post_form(uri,"data" => paramData.to_json)
|
98
|
+
elsif method.casecmp("patch") == 0
|
99
|
+
#code for patch
|
100
|
+
elsif method.casecmp("put") == 0
|
101
|
+
#code for put
|
102
|
+
end
|
103
|
+
return parseResponse(responseJson.body)
|
104
|
+
end
|
105
|
+
|
106
|
+
def deleteCloudmunchData(paramHash)
|
107
|
+
paramContext = paramHash["context"]
|
108
|
+
paramContextID = paramHash["contextID"]
|
109
|
+
|
110
|
+
if !paramContext.nil? && !paramContext.empty? && !paramContextID.nil? && !paramContextID.empty?
|
111
|
+
serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+context+"/"+contextID;
|
112
|
+
serverurl=serverurl+"?apikey="+@appContext.get_data("{api_key}")
|
113
|
+
uri = URI.parse(serverurl)
|
114
|
+
Net::HTTP::Delete(uri)
|
115
|
+
return 1
|
116
|
+
else
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def parseResponse(responseJson)
|
122
|
+
begin
|
123
|
+
JSON.parse(responseJson)
|
124
|
+
rescue
|
125
|
+
return responseJson
|
126
|
+
end
|
127
|
+
|
128
|
+
requestDetails = (JSON.load(responseJson))['request']
|
129
|
+
responseData = (JSON.load(responseJson))['data']
|
130
|
+
|
131
|
+
log("DEBUG", "Response : ")
|
132
|
+
log("DEBUG", responseJson)
|
133
|
+
|
134
|
+
if !requestDetails['status'].nil? && requestDetails['status'].casecmp('success') == 0
|
135
|
+
return responseData
|
136
|
+
else
|
137
|
+
if !requestDetails['message'].nil?
|
138
|
+
log("ERROR", requestDetails['message'])
|
139
|
+
end
|
140
|
+
return nil
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
def generateServerURL(paramHash, appendQueryParams = nil)
|
147
|
+
|
148
|
+
serverurl = ""
|
149
|
+
|
150
|
+
if !paramHash["url"].nil?
|
151
|
+
serverurl = @appContext.get_data("{master_url}")+"/"+paramHash["url"]
|
152
|
+
elsif !paramHash["context"].nil?
|
153
|
+
paramContext = paramHash["context"].nil? ? nil : paramHash["context"]
|
154
|
+
paramContextID = paramHash["contextID"].nil? ? nil : paramHash["contextID"]
|
155
|
+
paramSubContext = paramHash["subContext"].nil? ? nil : paramHash["subContext"]
|
156
|
+
paramSubContextID = paramHash["subContextID"].nil? ? nil : paramHash["subContextID"]
|
157
|
+
paramLeafContext = paramHash["leafContext"].nil? ? nil : paramHash["leafContext"]
|
158
|
+
paramLeafContextID = paramHash["leafContextID"].nil? ? nil : paramHash["leafContextID"]
|
159
|
+
|
160
|
+
serverurl=@appContext.get_data("{master_url}")+"/applications/"+@appContext.get_data("{application}")+"/"+paramContext
|
161
|
+
|
162
|
+
if !paramContextID.nil? && !paramContextID.empty?
|
163
|
+
serverurl=serverurl+"/"+paramContextID;
|
164
|
+
if !paramSubContext.nil? && !paramSubContext.empty?
|
165
|
+
serverurl=serverurl+"/"+paramSubContext;
|
166
|
+
if !paramSubContextID.nil? && !paramSubContextID.empty?
|
167
|
+
serverurl=serverurl+"/"+paramSubContextID;
|
168
|
+
if !paramLeafContext.nil? && !paramLeafContext.empty?
|
169
|
+
serverurl=serverurl+"/"+paramLeafContext;
|
170
|
+
if !paramLeafContextID.nil? && !paramLeafContextID.empty?
|
171
|
+
serverurl=serverurl+"/"+paramLeafContextID;
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
else
|
178
|
+
log("DEBUG", "No context provided for get api call");
|
179
|
+
return nil
|
180
|
+
end
|
181
|
+
|
182
|
+
queryString = ""
|
183
|
+
|
184
|
+
if !appendQueryParams.nil?
|
185
|
+
queryString = queryString + "filter=" + paramHash["filter"].to_json + "&" if !paramHash["filter"].nil?
|
186
|
+
queryString = queryString + "file=" + paramHash["file"].to_s + "&" if !paramHash["file"].nil?
|
187
|
+
queryString = queryString + "fields=" + paramHash["fields"].to_s + "&" if !paramHash["fields"].nil?
|
188
|
+
queryString = queryString + "count=" + paramHash["count"].to_s + "&" if !paramHash["count"].nil?
|
189
|
+
queryString = queryString + "offset=" + paramHash["offset"].to_s + "&" if !paramHash["offset"].nil?
|
190
|
+
queryString = queryString + "request_category=" + paramHash["requestCategory"].to_s + "&" if !paramHash["requestCategory"].nil?
|
191
|
+
queryString = queryString + "order_by=" + paramHash["orderBy"].to_s + "&" if !paramHash["orderBy"].nil?
|
192
|
+
queryString = queryString + "group_by=" + paramHash["groupBy"].to_s + "&" if !paramHash["groupBy"].nil?
|
193
|
+
end
|
194
|
+
serverurl = serverurl+"?"+queryString+"apikey="+@appContext.get_data("{api_key}")
|
195
|
+
return serverurl
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.putCustomDataContext(server, endpoint, param)
|
199
|
+
result = self.http_post(server, endpoint, param)
|
200
|
+
|
201
|
+
if result.code.to_s == "200"
|
202
|
+
return true
|
203
|
+
else
|
204
|
+
return false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.getCustomDataContext(server, endpoint, param)
|
209
|
+
return self.http_get(server, endpoint, param)
|
210
|
+
end
|
211
|
+
|
212
|
+
def self.http_get(server,path,params)
|
213
|
+
if params.nil?
|
214
|
+
return Net::HTTP.get(server, path)
|
215
|
+
else
|
216
|
+
queryStr = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
217
|
+
puts ("SDKDEBUG: Calling URL " + server+queryStr)
|
218
|
+
uri = URI(server + "/" + queryStr)
|
219
|
+
return Net::HTTP.get(uri)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.http_post(server,path,params)
|
224
|
+
queryStr = "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
|
225
|
+
puts ("SDKDEBUG: Calling URL " + server+queryStr)
|
226
|
+
if params.nil?
|
227
|
+
return Net::HTTP.post(server, path)
|
228
|
+
else
|
229
|
+
uri = URI(server + path)
|
230
|
+
return Net::HTTP.post_form(uri, params)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# def self.getDataContext(server, endpoint, param)
|
235
|
+
# getCustomDataContext(server, endpoint, param)
|
236
|
+
# end
|
237
|
+
|
238
|
+
# def self.updateDataContext(server, endpoint, param)
|
239
|
+
# putCustomDataContext(server, endpoint, param)
|
240
|
+
# end
|
241
|
+
|
242
|
+
def getDataForContext(server, endpoint, param)
|
243
|
+
getCustomDataContext(server, endpoint, param)
|
244
|
+
end
|
245
|
+
|
246
|
+
def updateDataForContext(server, endpoint, param)
|
247
|
+
putCustomDataContext(server, endpoint, param)
|
248
|
+
end
|
249
|
+
end
|