Class: Conoha
- Inherits:
-
Object
- Object
- Conoha
- Defined in:
- lib/conoha.rb,
lib/conoha/config.rb
Defined Under Namespace
Classes: Config
Class Method Summary collapse
- .authenticate! ⇒ Object
- .boot(server_id) ⇒ Object
- .create(os, ram) ⇒ Object
- .create_from_image(image_ref, ram) ⇒ Object
- .create_image(server_id, name) ⇒ Object
- .delete(server_id) ⇒ Object
- .delete_image(image_ref) ⇒ Object
- .images ⇒ Object
- .init! ⇒ Object
- .ip_address_of(server_id) ⇒ Object
- .servers ⇒ Object
- .shutdown(server_id) ⇒ Object
- .status_of(server_id) ⇒ Object
- .vps_list ⇒ Object
Class Method Details
.authenticate! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/conoha.rb', line 10 def self.authenticate! uri = 'https://identity.tyo1.conoha.io/v2.0/tokens' payload = { auth: { passwordCredentials: { username: @@username, password: @@password }, tenantId: @@tenant_id } } res = https_post uri, payload, nil @@authtoken = JSON.parse(res.body)["access"]["token"]["id"] save_config! end |
.boot(server_id) ⇒ Object
72 73 74 75 76 |
# File 'lib/conoha.rb', line 72 def self.boot(server_id) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action" res = https_post uri, {"os-start" => nil}, authtoken res.code == '202' ? 'OK' : 'Error' end |
.create(os, ram) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/conoha.rb', line 36 def self.create(os, ram) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers" payload = { server: { adminPass: randstr, imageRef: image_ref_from_os(os), flavorRef: flavor_ref(ram), key_name: public_key, security_groups: [ {name: 'default'}, {name: 'gncs-ipv4-all'} ] } } res = https_post uri, payload, authtoken JSON.parse(res.body)["server"]["id"] end |
.create_from_image(image_ref, ram) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/conoha.rb', line 102 def self.create_from_image(image_ref, ram) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers" payload = { server: { adminPass: randstr, imageRef: image_ref, flavorRef: flavor_ref(ram), key_name: public_key, security_groups: [ {name: 'default'}, {name: 'gncs-ipv4-all'} ] } } res = https_post uri, payload, authtoken JSON.parse(res.body)["server"]["id"] end |
.create_image(server_id, name) ⇒ Object
90 91 92 93 94 |
# File 'lib/conoha.rb', line 90 def self.create_image(server_id, name) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action" res = https_post uri, {"createImage" => {"name" => name}}, authtoken res.code == '202' ? 'OK' : 'Error' end |
.delete(server_id) ⇒ Object
54 55 56 57 58 |
# File 'lib/conoha.rb', line 54 def self.delete(server_id) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}" res = https_delete uri, authtoken res.code == '204' ? 'OK' : 'Error' end |
.delete_image(image_ref) ⇒ Object
96 97 98 99 100 |
# File 'lib/conoha.rb', line 96 def self.delete_image(image_ref) uri = "https://image-service.tyo1.conoha.io/v2/images/#{image_ref}" res = https_delete uri, authtoken res.code == '204' ? 'OK' : 'Error' end |
.images ⇒ Object
84 85 86 87 88 |
# File 'lib/conoha.rb', line 84 def self.images uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/images" res = https_get uri, authtoken JSON.parse(res.body)["images"].map { |e| [e["name"], e["id"]] } end |
.init! ⇒ Object
6 7 8 |
# File 'lib/conoha.rb', line 6 def self.init! load_config! end |
.ip_address_of(server_id) ⇒ Object
60 61 62 63 64 |
# File 'lib/conoha.rb', line 60 def self.ip_address_of(server_id) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}" res = https_get uri, authtoken JSON.parse(res.body)["server"]["addresses"].values[0].map{ |e| e["addr"] } end |
.servers ⇒ Object
26 27 28 29 30 |
# File 'lib/conoha.rb', line 26 def self.servers uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers" res = https_get uri, authtoken JSON.parse(res.body)["servers"] end |
.shutdown(server_id) ⇒ Object
78 79 80 81 82 |
# File 'lib/conoha.rb', line 78 def self.shutdown(server_id) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action" res = https_post uri, {"os-stop" => nil}, authtoken res.code == '202' ? 'OK' : 'Error' end |
.status_of(server_id) ⇒ Object
66 67 68 69 70 |
# File 'lib/conoha.rb', line 66 def self.status_of(server_id) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}" res = https_get uri, authtoken JSON.parse(res.body)["server"]["status"] end |
.vps_list ⇒ Object
32 33 34 |
# File 'lib/conoha.rb', line 32 def self.vps_list servers.map { |e| e["id"] } end |