Class: LeasewebAPI
- Inherits:
-
Object
- Object
- LeasewebAPI
- Includes:
- HTTParty
- Defined in:
- lib/leaseweb-rest-api.rb
Instance Method Summary collapse
- #apiKeyAuth(apikey) ⇒ Object
- #createDNSRecords(domain, host, content, type, priority = nil) ⇒ Object
- #createPAYGInstance(modelId) ⇒ Object
-
#createPrivateNetworks(name = '') ⇒ Object
TODO: check post with name.
- #createPrivateNetworksBareMetals(id, bareMetalId) ⇒ Object
- #delete(url) ⇒ Object
- #deleteDNSRecord(domain, dnsRecordId) ⇒ Object
- #deleteLease(bareMetalId, macAddress) ⇒ Object
- #deletePrivateNetwork(id) ⇒ Object
- #deletePrivateNetworksBareMetals(id, bareMetalId) ⇒ Object
- #destroyPAYGInstance(bareMetalId) ⇒ Object
- #get(url) ⇒ Object
- #get_paginated(url, key, offset = 0, limit = 50) ⇒ Object
- #getBareMetal(bareMetalId) ⇒ Object
-
#getBareMetals ⇒ Object
BareMetals.
- #getControlPanel(operatingSystemId, controlPanelId) ⇒ Object
- #getControlPanels(operatingSystemId) ⇒ Object
- #getDNSRecord(domain, dnsRecordId) ⇒ Object
- #getDNSRecords(domain) ⇒ Object
- #getDomain(domain) ⇒ Object
-
#getDomains ⇒ Object
Domains.
- #getInstallationStatus(bareMetalId) ⇒ Object
- #getIp(ipAddress) ⇒ Object
- #getIP(bareMetalId, ipAddress) ⇒ Object
- #getIpmiCredentials(bareMetalId) ⇒ Object
-
#getIps ⇒ Object
IPs.
- #getIPs(bareMetalId) ⇒ Object
- #getLease(bareMetalId, macAddress) ⇒ Object
- #getLeases(bareMetalId) ⇒ Object
- #getNetworkUsage(bareMetalId) ⇒ Object
- #getNetworkUsageBandWidth(bareMetalId, dateFrom, dateTo, format = 'json') ⇒ Object
- #getNetworkUsageDataTraffic(bareMetalId, dateFrom, dateTo, format = 'json') ⇒ Object
- #getOauthToken(clientId, clientSecret) ⇒ Object
- #getOperatingSystem(operatingSystemId) ⇒ Object
-
#getOperatingSystems ⇒ Object
Operating Systems.
- #getPartitionSchema(operatingSystemId, bareMetalId) ⇒ Object
- #getPasswordToken(username, password, client_id, client_secret) ⇒ Object
- #getPAYGInstance(bareMetalId) ⇒ Object
-
#getPAYGInstances ⇒ Object
Pay as you go.
- #getPAYGModelInstance(modelId) ⇒ Object
- #getPAYGModels ⇒ Object
- #getPowerStatus(bareMetalId) ⇒ Object
- #getPrivateNetwork(id) ⇒ Object
-
#getPrivateNetworks ⇒ Object
Private Networks.
-
#getRescueImages ⇒ Object
Rescue.
- #getRootPassword(bareMetalId, format = 'json') ⇒ Object
- #getSwitchPort(bareMetalId) ⇒ Object
- #installServer(bareMetalId, osId, hdd = []) ⇒ Object
- #post(url, body) ⇒ Object
- #postReboot(bareMetalId) ⇒ Object
- #postResqueMode(bareMetalId, osId) ⇒ Object
- #postSwitchPortClose(bareMetalId) ⇒ Object
- #postSwitchPortOpen(bareMetalId) ⇒ Object
- #put(url, body) ⇒ Object
- #readPrivateKey(privateKey, password) ⇒ Object
- #setLease(bareMetalId, bootFileName) ⇒ Object
- #updateBareMetal(bareMetalId, reference) ⇒ Object
- #updateDNSRecord(domain, dnsRecordId, host, content, type, priority = nil) ⇒ Object
- #updateDomain(domain, ttl) ⇒ Object
- #updateIP(bareMetalId, ipAddress, reverseLookup = '', nullRouted = 0) ⇒ Object
- #updateIp(ipAddress, reverseLookup = '', nullRouted = 0) ⇒ Object
-
#updatePrivateNetwork(id, name = '') ⇒ Object
TODO: Check with Jeroen if it works.
Instance Method Details
#apiKeyAuth(apikey) ⇒ Object
16 17 18 |
# File 'lib/leaseweb-rest-api.rb', line 16 def apiKeyAuth(apikey) @options = { headers: { 'X-Lsw-Auth' => apikey, 'Content-Type' => 'application/json' } } end |
#createDNSRecords(domain, host, content, type, priority = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/leaseweb-rest-api.rb', line 91 def createDNSRecords(domain, host, content, type, priority = nil) opt = @options.merge!(body: { host: host, content: content, type: type }) if !priority.nil? && ((type == 'MX') || (type == 'SRV')) opt[:body][:priority] = priority end self.class.post("/v1/domains/#{domain}/dnsRecords", opt) end |
#createPAYGInstance(modelId) ⇒ Object
319 320 321 322 323 |
# File 'lib/leaseweb-rest-api.rb', line 319 def createPAYGInstance(modelId) opt = @options.merge!(model: modelId) self.class.post('/v1/payAsYouGo/bareMetals/instances', opt) end |
#createPrivateNetworks(name = '') ⇒ Object
TODO: check post with name
245 246 247 248 249 |
# File 'lib/leaseweb-rest-api.rb', line 245 def createPrivateNetworks(name = '') opt = @options.merge!(body: { name: name }) self.class.post('/v1/privateNetworks', opt) end |
#createPrivateNetworksBareMetals(id, bareMetalId) ⇒ Object
266 267 268 269 270 |
# File 'lib/leaseweb-rest-api.rb', line 266 def createPrivateNetworksBareMetals(id, ) opt = @options.merge!(body: { bareMetalId: }) self.class.post("/v1/privateNetworks/#{id}/bareMetals", opt) end |
#delete(url) ⇒ Object
68 69 70 |
# File 'lib/leaseweb-rest-api.rb', line 68 def delete(url) self.class.delete(url, @options) end |
#deleteDNSRecord(domain, dnsRecordId) ⇒ Object
115 116 117 |
# File 'lib/leaseweb-rest-api.rb', line 115 def deleteDNSRecord(domain, dnsRecordId) self.class.delete("/v1/domains/#{domain}/dnsRecords/#{dnsRecordId}", @options) end |
#deleteLease(bareMetalId, macAddress) ⇒ Object
235 236 237 |
# File 'lib/leaseweb-rest-api.rb', line 235 def deleteLease(, macAddress) self.class.delete("/v1/bareMetals/#{}/leases/#{macAddress}", @options) end |
#deletePrivateNetwork(id) ⇒ Object
262 263 264 |
# File 'lib/leaseweb-rest-api.rb', line 262 def deletePrivateNetwork(id) self.class.delete("/v1/privateNetworks/#{id}", @options) end |
#deletePrivateNetworksBareMetals(id, bareMetalId) ⇒ Object
272 273 274 |
# File 'lib/leaseweb-rest-api.rb', line 272 def deletePrivateNetworksBareMetals(id, ) self.class.delete("/v1/privateNetworks/#{id}/bareMetals/#{}", @options) end |
#destroyPAYGInstance(bareMetalId) ⇒ Object
329 330 331 |
# File 'lib/leaseweb-rest-api.rb', line 329 def destroyPAYGInstance() self.class.post("/v1/payAsYouGo/bareMetals/instances/#{}/destroy", @options) end |
#get(url) ⇒ Object
38 39 40 |
# File 'lib/leaseweb-rest-api.rb', line 38 def get(url) self.class.get(url, @options) end |
#get_paginated(url, key, offset = 0, limit = 50) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/leaseweb-rest-api.rb', line 42 def get_paginated(url, key, offset = 0, limit = 50) data = [] loop do response = self.class.get("#{url}&offset=#{offset}&limit=#{limit}", @options) total = response.parsed_response['_metadata']['totalCount'] data += response.parsed_response[key] offset += limit break unless offset < total end data end |
#getBareMetal(bareMetalId) ⇒ Object
129 130 131 |
# File 'lib/leaseweb-rest-api.rb', line 129 def getBareMetal() self.class.get("/v1/bareMetals/#{}", @options) end |
#getBareMetals ⇒ Object
BareMetals
125 126 127 |
# File 'lib/leaseweb-rest-api.rb', line 125 def getBareMetals self.class.get('/v1/bareMetals', @options) end |
#getControlPanel(operatingSystemId, controlPanelId) ⇒ Object
289 290 291 |
# File 'lib/leaseweb-rest-api.rb', line 289 def getControlPanel(, controlPanelId) self.class.get("/v1/operatingSystems/#{}/controlPanels/#{controlPanelId}", @options) end |
#getControlPanels(operatingSystemId) ⇒ Object
285 286 287 |
# File 'lib/leaseweb-rest-api.rb', line 285 def getControlPanels() self.class.get("/v1/operatingSystems/#{}/controlPanels", @options) end |
#getDNSRecord(domain, dnsRecordId) ⇒ Object
101 102 103 |
# File 'lib/leaseweb-rest-api.rb', line 101 def getDNSRecord(domain, dnsRecordId) self.class.get("/v1/domains/#{domain}/dnsRecords/#{dnsRecordId}", @options) end |
#getDNSRecords(domain) ⇒ Object
87 88 89 |
# File 'lib/leaseweb-rest-api.rb', line 87 def getDNSRecords(domain) self.class.get("/v1/domains/#{domain}/dnsRecords", @options) end |
#getDomain(domain) ⇒ Object
77 78 79 |
# File 'lib/leaseweb-rest-api.rb', line 77 def getDomain(domain) self.class.get("/v1/domains/#{domain}", @options) end |
#getDomains ⇒ Object
Domains
73 74 75 |
# File 'lib/leaseweb-rest-api.rb', line 73 def getDomains self.class.get('/v1/domains', @options) end |
#getInstallationStatus(bareMetalId) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/leaseweb-rest-api.rb', line 207 def getInstallationStatus() response = self.class.get("/v1/bareMetals/#{}/installationStatus", @options) if response['installationStatus'].include?('initRootPassword') response['installationStatus']['initRootPassword'] = decrypt(response['installationStatus']['initRootPassword']) end if response['installationStatus'].include?('rescueModeRootPass') response['installationStatus']['rescueModeRootPass'] = decrypt(response['installationStatus']['rescueModeRootPass']) end response end |
#getIp(ipAddress) ⇒ Object
304 305 306 |
# File 'lib/leaseweb-rest-api.rb', line 304 def getIp(ipAddress) self.class.get("/v1/ips/#{ipAddress}", @options) end |
#getIP(bareMetalId, ipAddress) ⇒ Object
159 160 161 |
# File 'lib/leaseweb-rest-api.rb', line 159 def getIP(, ipAddress) self.class.get("/v1/bareMetals/#{}/ips/#{ipAddress}", @options) end |
#getIpmiCredentials(bareMetalId) ⇒ Object
169 170 171 |
# File 'lib/leaseweb-rest-api.rb', line 169 def getIpmiCredentials() self.class.get("/v1/bareMetals/#{}/ipmiCredentials", @options) end |
#getIps ⇒ Object
IPs
300 301 302 |
# File 'lib/leaseweb-rest-api.rb', line 300 def getIps self.class.get('/v1/ips', @options) end |
#getIPs(bareMetalId) ⇒ Object
155 156 157 |
# File 'lib/leaseweb-rest-api.rb', line 155 def getIPs() self.class.get("/v1/bareMetals/#{}/ips", @options) end |
#getLease(bareMetalId, macAddress) ⇒ Object
231 232 233 |
# File 'lib/leaseweb-rest-api.rb', line 231 def getLease(, macAddress) self.class.get("/v1/bareMetals/#{}/leases/#{macAddress}", @options) end |
#getLeases(bareMetalId) ⇒ Object
221 222 223 |
# File 'lib/leaseweb-rest-api.rb', line 221 def getLeases() self.class.get("/v1/bareMetals/#{}/leases", @options) end |
#getNetworkUsage(bareMetalId) ⇒ Object
173 174 175 |
# File 'lib/leaseweb-rest-api.rb', line 173 def getNetworkUsage() self.class.get("/v1/bareMetals/#{}/networkUsage", @options) end |
#getNetworkUsageBandWidth(bareMetalId, dateFrom, dateTo, format = 'json') ⇒ Object
177 178 179 |
# File 'lib/leaseweb-rest-api.rb', line 177 def getNetworkUsageBandWidth(, dateFrom, dateTo, format = 'json') self.class.get("/v1/bareMetals/#{}/networkUsage/bandWidth", formatRequest(dateFrom, dateTo, format)) end |
#getNetworkUsageDataTraffic(bareMetalId, dateFrom, dateTo, format = 'json') ⇒ Object
181 182 183 |
# File 'lib/leaseweb-rest-api.rb', line 181 def getNetworkUsageDataTraffic(, dateFrom, dateTo, format = 'json') self.class.get("/v1/bareMetals/#{}/networkUsage/dataTraffic", formatRequest(dateFrom, dateTo, format)) end |
#getOauthToken(clientId, clientSecret) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/leaseweb-rest-api.rb', line 20 def getOauthToken(clientId, clientSecret) response = self.class.post('https://auth.leaseweb.com/token', basic_auth: { username: clientId, password: clientSecret }, body: { grant_type: 'client_credentials' }) access_token = response.parsed_response['access_token'] @options = { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => 'application/json' } } end |
#getOperatingSystem(operatingSystemId) ⇒ Object
281 282 283 |
# File 'lib/leaseweb-rest-api.rb', line 281 def () self.class.get("/v1/operatingSystems/#{}", @options) end |
#getOperatingSystems ⇒ Object
Operating Systems
277 278 279 |
# File 'lib/leaseweb-rest-api.rb', line 277 def self.class.get('/v1/operatingSystems', @options) end |
#getPartitionSchema(operatingSystemId, bareMetalId) ⇒ Object
293 294 295 296 297 |
# File 'lib/leaseweb-rest-api.rb', line 293 def getPartitionSchema(, ) opt = @options.merge!(query: { serverPackId: }) self.class.get("/v1/operatingSystems/#{}/partitionSchema", opt) end |
#getPasswordToken(username, password, client_id, client_secret) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/leaseweb-rest-api.rb', line 27 def getPasswordToken(username, password, client_id, client_secret) response = self.class.post('https://auth.leaseweb.com/token', basic_auth: { username: client_id, password: client_secret }, body: { grant_type: 'password', username: username, password: password }) access_token = response.parsed_response['access_token'] @options = { headers: { 'Authorization' => "Bearer #{access_token}", 'Content-Type' => 'application/json' } } end |
#getPAYGInstance(bareMetalId) ⇒ Object
325 326 327 |
# File 'lib/leaseweb-rest-api.rb', line 325 def getPAYGInstance() self.class.get("/v1/payAsYouGo/bareMetals/instances/#{}", @options) end |
#getPAYGInstances ⇒ Object
Pay as you go
315 316 317 |
# File 'lib/leaseweb-rest-api.rb', line 315 def getPAYGInstances self.class.get('/v1/payAsYouGo/bareMetals/instances', @options) end |
#getPAYGModelInstance(modelId) ⇒ Object
337 338 339 |
# File 'lib/leaseweb-rest-api.rb', line 337 def getPAYGModelInstance(modelId) self.class.get("/v1/payAsYouGo/bareMetals/models/#{modelId}", @options) end |
#getPAYGModels ⇒ Object
333 334 335 |
# File 'lib/leaseweb-rest-api.rb', line 333 def getPAYGModels self.class.get('/v1/payAsYouGo/bareMetals/models', @options) end |
#getPowerStatus(bareMetalId) ⇒ Object
151 152 153 |
# File 'lib/leaseweb-rest-api.rb', line 151 def getPowerStatus() self.class.get("/v1/bareMetals/#{}/powerStatus", @options) end |
#getPrivateNetwork(id) ⇒ Object
251 252 253 |
# File 'lib/leaseweb-rest-api.rb', line 251 def getPrivateNetwork(id) self.class.get("/v1/privateNetworks/#{id}", @options) end |
#getPrivateNetworks ⇒ Object
Private Networks
240 241 242 |
# File 'lib/leaseweb-rest-api.rb', line 240 def getPrivateNetworks self.class.get('/v1/privateNetworks', @options) end |
#getRescueImages ⇒ Object
Rescue
120 121 122 |
# File 'lib/leaseweb-rest-api.rb', line 120 def getRescueImages self.class.get('/v1/rescueImages', @options) end |
#getRootPassword(bareMetalId, format = 'json') ⇒ Object
201 202 203 204 205 |
# File 'lib/leaseweb-rest-api.rb', line 201 def getRootPassword(, format = 'json') opt = @options.merge!(headers: formatHeader(format)) self.class.get("/v1/bareMetals/#{}/rootPassword", opt) end |
#getSwitchPort(bareMetalId) ⇒ Object
139 140 141 |
# File 'lib/leaseweb-rest-api.rb', line 139 def getSwitchPort() self.class.get("/v1/bareMetals/#{}/switchPort", @options) end |
#installServer(bareMetalId, osId, hdd = []) ⇒ Object
189 190 191 192 193 |
# File 'lib/leaseweb-rest-api.rb', line 189 def installServer(, osId, hdd = []) opt = @options.merge!(body: { osId: osId, hdd: hdd }, query_string_normalizer: ->(h) { HashToURIConversion.new.to_params(h) }) self.class.post("/v1/bareMetals/#{}/install", opt) end |
#post(url, body) ⇒ Object
58 59 60 61 |
# File 'lib/leaseweb-rest-api.rb', line 58 def post(url, body) opt = @options.merge!(body: body) self.class.post(url, opt) end |
#postReboot(bareMetalId) ⇒ Object
185 186 187 |
# File 'lib/leaseweb-rest-api.rb', line 185 def postReboot() self.class.post("/v1/bareMetals/#{}/reboot", @options) end |
#postResqueMode(bareMetalId, osId) ⇒ Object
195 196 197 198 199 |
# File 'lib/leaseweb-rest-api.rb', line 195 def postResqueMode(, osId) opt = @options.merge!(body: { osId: osId }) self.class.post("/v1/bareMetals/#{}/rescueMode", opt) end |
#postSwitchPortClose(bareMetalId) ⇒ Object
147 148 149 |
# File 'lib/leaseweb-rest-api.rb', line 147 def postSwitchPortClose() self.class.post("/v1/bareMetals/#{}/switchPort/close", @options) end |
#postSwitchPortOpen(bareMetalId) ⇒ Object
143 144 145 |
# File 'lib/leaseweb-rest-api.rb', line 143 def postSwitchPortOpen() self.class.post("/v1/bareMetals/#{}/switchPort/open", @options) end |
#put(url, body) ⇒ Object
63 64 65 66 |
# File 'lib/leaseweb-rest-api.rb', line 63 def put(url, body) opt = @options.merge!(body: body) self.class.put(url, opt) end |
#readPrivateKey(privateKey, password) ⇒ Object
34 35 36 |
# File 'lib/leaseweb-rest-api.rb', line 34 def readPrivateKey(privateKey, password) @private_key = OpenSSL::PKey::RSA.new(File.read(privateKey), password) end |
#setLease(bareMetalId, bootFileName) ⇒ Object
225 226 227 228 229 |
# File 'lib/leaseweb-rest-api.rb', line 225 def setLease(, bootFileName) opt = @options.merge!(body: { bootFileName: bootFileName }) self.class.post("/v1/bareMetals/#{}/leases", opt) end |
#updateBareMetal(bareMetalId, reference) ⇒ Object
133 134 135 136 137 |
# File 'lib/leaseweb-rest-api.rb', line 133 def updateBareMetal(, reference) opt = @options.merge!(body: { reference: reference }) self.class.put("/v1/bareMetals/#{}", opt) end |
#updateDNSRecord(domain, dnsRecordId, host, content, type, priority = nil) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/leaseweb-rest-api.rb', line 105 def updateDNSRecord(domain, dnsRecordId, host, content, type, priority = nil) opt = @options.merge!(body: { id: dnsRecordId, host: host, content: content, type: type }) if !priority.nil? && ((type == 'MX') || (type == 'SRV')) opt[:body][:priority] = priority end self.class.put("/v1/domains/#{domain}/dnsRecords/#{dnsRecordId}", opt) end |
#updateDomain(domain, ttl) ⇒ Object
81 82 83 84 85 |
# File 'lib/leaseweb-rest-api.rb', line 81 def updateDomain(domain, ttl) opt = @options.merge!(body: { ttl: ttl }) self.class.put("/v1/domains/#{domain}", opt) end |
#updateIP(bareMetalId, ipAddress, reverseLookup = '', nullRouted = 0) ⇒ Object
163 164 165 166 167 |
# File 'lib/leaseweb-rest-api.rb', line 163 def updateIP(, ipAddress, reverseLookup = '', nullRouted = 0) opt = @options.merge!(body: { reverseLookup: reverseLookup, nullRouted: nullRouted }) self.class.put("/v1/bareMetals/#{}/ips/#{ipAddress}", opt) end |
#updateIp(ipAddress, reverseLookup = '', nullRouted = 0) ⇒ Object
308 309 310 311 312 |
# File 'lib/leaseweb-rest-api.rb', line 308 def updateIp(ipAddress, reverseLookup = '', nullRouted = 0) opt = @options.merge!(body: { reverseLookup: reverseLookup, nullRouted: nullRouted }) self.class.put("/v1/ips/#{ipAddress}", opt) end |
#updatePrivateNetwork(id, name = '') ⇒ Object
TODO: Check with Jeroen if it works
256 257 258 259 260 |
# File 'lib/leaseweb-rest-api.rb', line 256 def updatePrivateNetwork(id, name = '') opt = @options.merge!(body: { name: name }) self.class.put("/v1/privateNetworks/#{id}", opt) end |