lib/clc_client.rb in clc_client-0.1.2 vs lib/clc_client.rb in clc_client-0.1.3

- old
+ new

@@ -11,11 +11,11 @@ :memoryGB => 2, :type => "standard", } CLC_API = "https://api.ctl.io" - + def self.setToken(token) $token = token end def self.login(username, password) @@ -45,288 +45,290 @@ response = RestClient.post("https://api.ctl.io/v2/servers/#{accountAlias}", payload.to_json, :content_type => :json, :accept => :json, :authorization => "Bearer #{$token}" ) - puts response JSON.parse(response) - end + end - def self.deleteServer(accountAlias, serverId) - response = RestClient.delete("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.deleteServer(accountAlias, serverId) + response = RestClient.delete("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getServerCredentials(accountAlias, serverId) - response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/credentials", :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getServerCredentials(accountAlias, serverId) + response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/credentials", :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.setServerCpuOrMemory(accountAlias, serverId, payload = {}) - response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", - payload.to_json, - :content_type => :json, - :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.setServerCpuOrMemory(accountAlias, serverId, payload = {}) + response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", + payload.to_json, + :content_type => :json, + :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.setServerCredentials(accountAlias, serverId, payload = {}) - response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.setServerCredentials(accountAlias, serverId, payload = {}) + response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.setServerCustomsFields(accountAlias, serverId, payload = {}) - response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", + def self.setServerCustomsFields(accountAlias, serverId, payload = {}) + response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.setServerDescriptionOrGroup(accountAlias, serverId, payload = {}) - response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.setServerDescriptionOrGroup(accountAlias, serverId, payload = {}) + response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.setServerDisks(accountAlias, serverId, payload = {}) - response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end - - def self.getQueueStatus(accountAlias, serverId) - response = RestClient.get("https://api.ctl.io/v2/operations/#{accountAlias}/status/#{serverId}", + def self.setServerDisks(accountAlias, serverId, payload = {}) + response = RestClient.patch("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", + payload.to_json, + :content_type => :json, :accept => :json, :authorization => "Bearer #{$token}" ) - end + JSON.parse(response) + end - def self.addPublicIpAddress(accountAlias, serverId, payload = {}) - response = RestClient.post("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.getQueueStatus(accountAlias, serverId) + response = RestClient.get("https://api.ctl.io/v2/operations/#{accountAlias}/status/#{serverId}", + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.getPublicIpAddress(accountAlias, serverId, publicIP) - response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses/#{publicIP}", :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.addPublicIpAddress(accountAlias, serverId, payload = {}) + response = RestClient.post("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.deletePublicIpAddress(accountAlias, serverId, publicIP) - response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses/#{publicIP}", :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getPublicIpAddress(accountAlias, serverId, publicIP) + response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses/#{publicIP}", :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.updatePublicIpAddress(accountAlias, serverId, publicIP, payload = {}) - response = RestClient.post("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.deletePublicIpAddress(accountAlias, serverId, publicIP) + response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses/#{publicIP}", :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.archiveServer(accountAlias, serverIds = {}) - response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/archive", - serversIds.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.updatePublicIpAddress(accountAlias, serverId, publicIP, payload = {}) + response = RestClient.post("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}/publicIPAddresses", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.createSnapshot(accountAlias, payload = {}) - response = RestClient.post("https://api.ctl.io/v2/operations/{accountAlias}/servers/createSnapshot", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - end + def self.archiveServer(accountAlias, serverIds = {}) + response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/archive", + serversIds.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.executePackage(accountAlias, payload = {}) - response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/executePackage", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end + def self.createSnapshot(accountAlias, payload = {}) + response = RestClient.post("https://api.ctl.io/v2/operations/{accountAlias}/servers/createSnapshot", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.restoreServer(accountAlias, targetGroupId) - response = RestClient.post("https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/restore", - {:targetGroupId => targetGroupId}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.executePackage(accountAlias, payload = {}) + response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/executePackage", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.setPowerOperation(accountAlias, powerOperation, serverIds = {}) - response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/#{powerOperation}", - {:serverIds => serverIds}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.restoreServer(accountAlias, targetGroupId) + response = RestClient.post("https://api.ctl.io/v2/servers/{accountAlias}/{serverId}/restore", + {:targetGroupId => targetGroupId}.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.setMaintenanceMode(accountAlias, servers = {}) - response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/setMaintenance", - servers.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.setPowerOperation(accountAlias, powerOperation, serverIds = {}) + response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/#{powerOperation}", + {:serverIds => serverIds}.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.archiveGroup(accountAlias, groupId, payload = {}) - response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/archive", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => authorization - ) - JSON.parse(response) - end + def self.setMaintenanceMode(accountAlias, servers = {}) + response = RestClient.post("https://api.ctl.io/v2/operations/#{accountAlias}/servers/setMaintenance", + servers.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.restoreGroup(accountAlias, groupId, targetGroupId) - response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/restore", - {:targetGroupId => targetGroupId}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - end + def self.archiveGroup(accountAlias, groupId, payload = {}) + response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/archive", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => authorization + ) + JSON.parse(response) + end - def self.createGroup(accountAlias, payload) - response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}", - payload.to_json, - :content_type => :json, :accept => :json, + def self.restoreGroup(accountAlias, groupId, targetGroupId) + response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/restore", + {:targetGroupId => targetGroupId}.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end + + def self.createGroup(accountAlias, payload) + response = RestClient.post("https://api.ctl.io/v2/groups/#{accountAlias}", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end + + def self.deleteGroup(accountAlias, groupId) + response = RestClient.delete("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", :authorization => "Bearer #{$token}") - JSON.parse(response) - end + JSON.parse(response) + end - def self.deleteGroup(accountAlias, groupId) - response = RestClient.delete("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getGroup(accountAlias, groupId) + response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getGroup(accountAlias, groupId) - response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getGroupBillingDetails(accountAlias, groupId) + response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/billing", + :authorization => authorization) + JSON.parse(response) + end - def self.getGroupBillingDetails(accountAlias, groupId) - response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/billing", - :authorization => authorization) - JSON.parse(response) - end + def self.getGroupMonitorinfStatistics(accountAlias, groupId) + response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/statistics?start=#{datetime}&sampleInterval=dd:hh:mm:ss", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getGroupMonitorinfStatistics(accountAlias, groupId) - response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}/statistics?start=#{datetime}&sampleInterval=dd:hh:mm:ss", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.setCustomFields(accountAlias, groupId, patchOperation = {}) + response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", + {:patchOperation => patchOperation}.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.setCustomFields(accountAlias, groupId, patchOperation = {}) - response = RestClient.get("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", + def self.setGroupNameOrDescription(accountAlias, groupId, patchOperation = {}) + response = RestClient.patch("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", {:patchOperation => patchOperation}.to_json, :content_type => :json, :accept => :json, :authorization => "Bearer #{$token}") - JSON.parse(response) - end + JSON.parse(response) + end - def self.setGroupNameOrDescription(accountAlias, groupId, patchOperation = {}) - response = RestClient.patch("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", - {:patchOperation => patchOperation}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end - - def self.setGroupParent(accountAlias, groupId, patchOperation = {}) - response = RestClient.patch("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", - {:patchOperation => patchOperation}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end - - def self.getCustomGroups(accountAlias) - response = RestClient.get("https://api.ctl.io/v2/accounts/#{accountAlias}/customFields", - :authorization => "Bearer #{$token}" - ) - JSON.parse(response) - end - - def self.getDataCenter(accountAlias, dataCenter) - response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}/#{dataCenter}?groupLinks=true|false", + def self.setGroupParent(accountAlias, groupId, patchOperation = {}) + response = RestClient.patch("https://api.ctl.io/v2/groups/#{accountAlias}/#{groupId}", + {:patchOperation => patchOperation}.to_json, + :content_type => :json, :accept => :json, :authorization => "Bearer #{$token}") - JSON.parse(response) - end + JSON.parse(response) + end - def self.getDataCentereploymentCapalities(accountAlias, datacenter) - response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}/#{dataCenter}/deploymentCapabilities", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getCustomGroups(accountAlias) + response = RestClient.get("https://api.ctl.io/v2/accounts/#{accountAlias}/customFields", + :authorization => "Bearer #{$token}" + ) + JSON.parse(response) + end - def self.getDataCenterList(accountAlias) - response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getDataCenter(accountAlias, dataCenter) + response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}/#{dataCenter}?groupLinks=true|false", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getCustomFields(accountAlias) - response = RestClient.get("https://api.ctl.io/v2/accounts/#{accountAlias}/customFields", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getDataCentereploymentCapalities(accountAlias, datacenter) + response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}/#{dataCenter}/deploymentCapabilities", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.createAntiAffinityPolicy(accountAlias) - response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getDataCenterList(accountAlias) + response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.deleteAntiAffinityPolicy(accountAlias, policyId, payload = {}) - response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", - payload.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.getCustomFields(accountAlias) + response = RestClient.get("https://api.ctl.io/v2/accounts/#{accountAlias}/customFields", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.updateAntiAffinityPolicy(accountAlias, policyId, name) - response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", - {:name => name}.to_json, - :content_type => :json, :accept => :json, - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.createAntiAffinityPolicy(accountAlias) + response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getAntiAffinityPolicy(accountAlias, policyId) - response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.deleteAntiAffinityPolicy(accountAlias, policyId, payload = {}) + response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", + payload.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end - def self.getAntiAffinityPolicies(accountAlias) - response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}", - :authorization => "Bearer #{$token}") - JSON.parse(response) - end + def self.updateAntiAffinityPolicy(accountAlias, policyId, name) + response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", + {:name => name}.to_json, + :content_type => :json, :accept => :json, + :authorization => "Bearer #{$token}") + JSON.parse(response) + end + def self.getAntiAffinityPolicy(accountAlias, policyId) + response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}/#{policyId}", + :authorization => "Bearer #{$token}") + JSON.parse(response) end + + def self.getAntiAffinityPolicies(accountAlias) + response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{accountAlias}", + :authorization => "Bearer #{$token}") + JSON.parse(response) + end + +end