require "clc_client/version" require "rest-client" module ClcClient createServerRequest = { :name => "DFT", :groupId => "a163d30b196f436aac885f2e28ad28b9", :sourceServerId => "UBUNTU-14-64-TEMPLATE", :cpu => 1, :memoryGB => 2, :type => "standard", } CLC_API = "https://api.ctl.io" def self.setToken(token) $token = token end def self.login(username, password) begin response = RestClient.post("https://api.ctl.io/v2/authentication/login", {:username => username, :password => password }.to_json, :content_type => :json, :accept => :json ) rescue => e puts e.response end $token = JSON.parse(response)['bearerToken'] end def self.getServerDetails(accountAlias, serverId) begin response = RestClient.get("https://api.ctl.io/v2/servers/#{accountAlias}/#{serverId}", :authorization => "Bearer #{$token}") rescue => e puts e end JSON.parse(response) end def self.createServer(accountAlias, payload = {}) 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 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.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.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 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/#{acctAlias}/status/#{statusId}", :authorization => "Bearer #{$token}" ) 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.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.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.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.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.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.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.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.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.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.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.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.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 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.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.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", :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.getDataCenterList(accountAlias) response = RestClient.get("https://api.ctl.io/v2/datacenters/#{accountAlias}", :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.createAntiAffinityPolicy(accountAlias) response = RestClient.get("https://api.ctl.io/v2/antiAffinityPolicies/#{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.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