Class: AssetHelper
- Inherits:
-
Object
show all
- Includes:
- CloudmunchService, Util
- Defined in:
- AssetHelper.rb
Instance Method Summary
(collapse)
Methods included from Util
getJSONArgs, log, logClose, logInit, logIt, openJSONFile
#deleteCloudmunchData, #deleteKeys, #downloadKeys, #generateServerURL, #getCloudmunchData, getCustomDataContext, #getDataForContext, http_get, http_post, #parseResponse, putCustomDataContext, #updateCloudmunchData, #updateDataForContext
Constructor Details
- (AssetHelper) initialize(appContext)
Returns a new instance of AssetHelper
23
24
25
26
|
# File 'AssetHelper.rb', line 23
def initialize(appContext)
@appContext = appContext
@cloudmunchDataService = CloudmunchService.new
end
|
Instance Method Details
- (Object) addAsset(assetName, assetType, assetStatus, assetExternalRef, assetData)
51
52
53
54
55
56
57
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
|
# File 'AssetHelper.rb', line 51
def addAsset(assetName, assetType, assetStatus, assetExternalRef, assetData)
if assetName.empty? || assetType.empty? || assetStatus.empty? then
log("ERROR", "Asset name ,status and type need to be provided")
return false
end
statusArray = [::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL]
if !statusArray.include?(assetStatus) then
log("ERROR", "Invalid status sent. Allowed values " + ::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL)
return false
end
assetData["name"] = assetName
assetData["type"] = assetType
assetData["status"] = assetStatus
assetData["external_reference"] = assetExternalRef
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/"
retResult = @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), assetData)
if retResult == nil then
return nil
else
retResult = JSON.parse(retResult)
retData = retResult["data"]
if retData.nil? then
return nil
else
return retData
end
end
end
|
- (Object) checkIfAssetExists(assetID)
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'AssetHelper.rb', line 108
def checkIfAssetExists(assetID)
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
assetResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), "")
if assetResult == nil then
return nil
else
assetResult = JSON.parse(assetResult)
assetData = assetResult["data"]
if assetData.nil? then
log("ERROR", "Asset does not exist")
return false
else
return true
end
end
end
|
- (Object) deleteAsset(assetID)
91
92
93
94
|
# File 'AssetHelper.rb', line 91
def deleteAsset(assetID)
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
@cloudmunchDataService.deleteDataForContext(serverUrl, @appContext.getAPIKey())
end
|
- (Object) getAsset(assetID, filterData)
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'AssetHelper.rb', line 28
def getAsset(assetID, filterData)
paramHash = {}
if !filterData.nil?
paramHash["filter"] = filterData.to_json
end
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
assetResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIJey(), paramHash)
if assetResult == nil then
log("ERROR", "Unable to get data from cloudmunch")
return nil
else
assetResult = JSON.parse(assetResult)
assetData = assetResult["data"]
if assetData.nil? then
log("ERROR", "Asset does not exist")
return nil
else
return assetData
end
end
end
|
- (Object) updateAsset(assetID, assetData)
86
87
88
89
|
# File 'AssetHelper.rb', line 86
def updateAsset(assetID, assetData)
serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + assetID
@cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), assetData)
end
|
- (Object) updateStatus(assetID, status)
96
97
98
99
100
101
102
103
104
105
106
|
# File 'AssetHelper.rb', line 96
def updateStatus(assetID, status)
statusArray = [::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL]
if !statusArray.include?(status) then
log("ERROR", "Invalid status")
return false
end
assetData = {}
assetData["status"] = status
updateAsset(assetID, assetData)
end
|