Class: ServerHelper
- Inherits:
-
Object
- Object
- ServerHelper
- Includes:
- CloudmunchService, Util
- Defined in:
- lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb,
lib/cloudmunch_Ruby_sdk_v3/ServerHelper.rb
Instance Method Summary collapse
-
#addServer(server, serverStatus, docker) ⇒ Object
### ### This method can be used to add or register a server to cloudmunch data .
-
#checkConnect(dns, sshport) ⇒ Object
### ### Checks if server is up and running ### ### @param string dns : dns of target server ### @param number sshport : ssh port (22) to be used to check for connection ### @return string Success : displays an appropriate message ### Failure : exits with a failure status with an appropriate message ###.
- #checkConnectionToServer(servername) ⇒ Object
-
#checkServerExists(serverName) ⇒ Object
### ### This method checks if server exists or is registered in cloudmunch data.
-
#deleteServer(serverID) ⇒ Object
### ### This method is to delete server from cloudmunch.
- #getConnectionToServer(servername) ⇒ Object
-
#getServerName(serverName) ⇒ Object
### ### This method retreives the details of server from cloudmunch.
-
#getSSHConnectionHelper ⇒ Object
### ### This method returns SSHConnection helper ### @return CloudMunchsshConnection ###.
-
#initialize(appContext) ⇒ ServerHelper
constructor
A new instance of ServerHelper.
-
#updateServer(server, serverID) ⇒ Object
### ### This method is used to update server data.
Methods included from Util
getJSONArgs, log, logClose, logInit, logIt, openJSONFile
Methods included from CloudmunchService
#deleteCloudmunchData, #deleteKeys, #downloadKeys, #generateServerURL, #getCloudmunchData, #getCloudmunchDataBKUP, getCustomDataContext, #getDataForContext, #getIntegrationWithID, #getResource, http_get, http_post, #parseResponse, putCustomDataContext, #updateCloudmunchData, #updateDataForContext
Constructor Details
#initialize(appContext) ⇒ ServerHelper
Returns a new instance of ServerHelper.
23 24 25 26 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 23 def initialize(appContext) @appContext = appContext @cloudmunchDataService = CloudmunchService.new end |
Instance Method Details
#addServer(server, serverStatus, docker) ⇒ Object
### ### This method can be used to add or register a server to cloudmunch data . ### @param CloudMunchServer server ### @param string docker ###
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 101 def addServer(server, serverStatus, docker) if serverStatus.empty? then log("ERROR", "Server status need to be provided") return false end statusArray = [::STATUS_RUNNING, ::STATUS_STOPPED, ::STATUS_NIL] if !statusArray.include?(serverStatus) then log("ERROR", "Invalid status") return false end paramHash = {} paramHash["description"] = server.description paramHash["dnsName"] = server.dns paramHash["domainName"] = server.domainName paramHash["emailID"] = server.emailID paramHash["CI"] = server.CI ? "y" : "n" paramHash["deploymentStatus"] = server.deploymentStatus paramHash["instanceId"] = server.instanceId paramHash["amiID"] = server.imageID paramHash["username"] = server.username paramHash["build"] = server.build paramHash["appName"] = server.appName paramHash["deployTempLoc"] = server.deployTempLoc paramHash["buildLoc"] = server.buildLocation paramHash["privateKeyLoc"] = server.privateKeyLoc paramHash["publicKeyLoc"] = server.publicKeyLoc paramHash["loginUser"] = server.loginUser paramHash["serverType"] = server.serverType paramHash["type"] = "server" paramHash["status"] = server.status paramHash["starttime"] = server.startTime paramHash["provider"] = server.provider paramHash["region"] = server.region paramHash["cmserver"] = server.cmserver paramHash["name"] = server.serverName paramHash["instancesize"] = server.instanceSize paramHash["password"] = server.password paramHash["sshport"] = server.sshport paramHash["tier"] = server.tier if server.instance_of?(ElasticBeanStalkServer) then paramHash["applicationName"] = server.applicationName paramHash["templateName"] = server.templateName paramHash["environmentName"] = server.environmentName paramHash["bucketName"] = server.bucketName end paramHash["status"] = serverStatus if docker then dataInnerHash = {} dataInnerHash["buildNo"] = server.build dataServerNode = {} dataServerNode[server.appName] = dataInnerHash paramHash["projects"] = dataServerNode end serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), paramHash) end |
#checkConnect(dns, sshport) ⇒ Object
### ### Checks if server is up and running ### ### @param string dns : dns of target server ### @param number sshport : ssh port (22) to be used to check for connection ### @return string Success : displays an appropriate message ### Failure : exits with a failure status with an appropriate message ###
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 244 def checkConnect(dns, sshport) connectionTimeout = Time.now connectionTimeout = connectionTimeout + (10 * 10) connection = false while ((connection == false) && ( Time.now < connectionTimeout )) do if dns.nil? || dns.empty? then log("ERROR", "Invalid dns" + dns) return false end log("INFO", "Checking connectivity to: " + dns) connection = ssh2_connect(dns, sshport) if connection == false then sleep(10) end end if connection == false then log("ERROR", "Failed to connect to " + dns ) return false else return true end end |
#checkConnectionToServer(servername) ⇒ Object
270 271 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 270 def checkConnectionToServer(servername) end |
#checkServerExists(serverName) ⇒ Object
### ### This method checks if server exists or is registered in cloudmunch data. ### @param $servername Name of server. ### @return boolean ###
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 218 def checkServerExists(serverName) serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + serverName serverResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(), "") if serverResult == nil then return nil else serverResult = JSON.parse(serverResult) serverData = serverResult["data"] if serverData.nil? then log("ERROR", "Server does not exist") return false else return true end end end |
#deleteServer(serverID) ⇒ Object
### ### This method is to delete server from cloudmunch. ### @param $serverName Name of server. ###
208 209 210 211 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 208 def deleteServer(serverID) serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + serverID return @cloudmunchDataService.deleteDataForContext(serverUrl, @appContext.getAPIKey() ) end |
#getConnectionToServer(servername) ⇒ Object
273 274 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 273 def getConnectionToServer(servername) end |
#getServerName(serverName) ⇒ Object
### ### This method retreives the details of server from cloudmunch. ### @param string $servername Name of the server as registered in cloudmunch. ### @return CloudMunchServer ###
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 33 def getServerName(serverName) server = nil serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + serverName log("DEBUG", "serverurl from serverhelper:" + serverUrl) deployResult = @cloudmunchDataService.getDataForContext(serverUrl, @appContext.getAPIKey(),nil) if deployResult == nil then return false else deployResult = JSON.parse(deployResult) deployData = deployResult["data"] if deployData.nil? then log("ERROR", "Server does not exist") return nil else if (deployResult[serverName].include?("assetname")) && (deployResult[serverName]["assetname"] == "ElasticBeanStalk") then server = ElasticBeanStalkServer.new else server = Server.new server.servername = deployData["id"] server.description = deployData["description"] server.dns = deployData["dnsName"] server.domainName = deployData["domainName"] server.CI = deployData["CI"] server.deploymentStatus = deployData["deploymentStatus"] server.instanceId = deployData["instanceId"] server.imageID = deployData["amiID"] server.launcheduser = deployData["username"] server.build = deployData["build"] server.appName = deployData["appName"] server.deployTempLoc = deployData["deployTempLoc"] server.buildLocation = deployData["buildLoc"] server.privateKeyLoc = deployData["privateKeyLoc"] server.publicKeyLoc = deployData["publicKeyLoc"] server.loginUser = deployData["loginUser"] server.serverType = deployData["serverType"] server.assetType = deployData["assettype"] server.status = deployData["status"] server.startTime = deployData["starttime"] server.provider = deployData["provider"] server.region = deployData["region"] server.cmserver = deployData["cmserver"] server.assetName = deployData["assetname"] server.instanceSize = deployData["instancesize"] server.password = deployData["password"] server.sshport = deployData["sshport"] server.tier = deployData["tier"] if server.instance_of?(ElasticBeanStalkServer) then server.environmentName = deployData["environmentName"] server.bucketName = deployData["bucketName"] server.applicationName = deployData["applicationName"] server.templateName = deployData["templateName"] end return server end end end end |
#getSSHConnectionHelper ⇒ Object
### ### This method returns SSHConnection helper ### @return CloudMunchsshConnection ###
280 281 282 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 280 def getSSHConnectionHelper() return SSHConnection.new end |
#updateServer(server, serverID) ⇒ Object
### ### This method is used to update server data. ### @param CloudMunchServer server ###
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/cloudmunch_Ruby_sdk_v2/ServerHelper.rb', line 169 def updateServer(server, serverID) paramHash = {} paramHash["description"] = server.description paramHash["dnsName"] = server.dns paramHash["domainName"] = server.domainName paramHash["emailID"] = server.emailID paramHash["CI"] = server.CI ? "y" : "n" paramHash["deploymentStatus"] = server.deploymentStatus paramHash["instanceId"] = server.instanceId paramHash["amiID"] = server.imageID paramHash["username"] = server.username paramHash["build"] = server.build paramHash["appName"] = server.appName paramHash["deployTempLoc"] = server.deployTempLoc paramHash["buildLoc"] = server.buildLocation paramHash["privateKeyLoc"] = server.privateKeyLoc paramHash["publicKeyLoc"] = server.publicKeyLoc paramHash["loginUser"] = server.loginUser paramHash["serverType"] = server.serverType paramHash["type"] = "server" paramHash["status"] = server.status paramHash["starttime"] = server.startTime paramHash["provider"] = server.provider paramHash["region"] = server.region paramHash["cmserver"] = server.cmserver paramHash["name"] = server.serverName paramHash["instancesize"] = server.instanceSize paramHash["password"] = server.password paramHash["sshport"] = server.sshport paramHash["tier"] = server.tier serverUrl = @appContext.getMasterURL() + "/applications/" + @appContext.getProject() + "/assets/" + serverID return @cloudmunchDataService.updateDataForContext(serverUrl, @appContext.getAPIKey(), paramHash) end |