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
- .server_action(server_id, action) ⇒ 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
79 80 81 |
# File 'lib/conoha.rb', line 79 def self.boot(server_id) server_action server_id, "os-start" 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
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/conoha.rb', line 105 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
93 94 95 96 97 |
# File 'lib/conoha.rb', line 93 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
99 100 101 102 103 |
# File 'lib/conoha.rb', line 99 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
87 88 89 90 91 |
# File 'lib/conoha.rb', line 87 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 |
.server_action(server_id, action) ⇒ Object
73 74 75 76 77 |
# File 'lib/conoha.rb', line 73 def self.server_action(server_id, action) uri = "https://compute.tyo1.conoha.io/v2/#{tenant_id}/servers/#{server_id}/action" res = https_post uri, {action => nil}, authtoken res.code == '202' ? 'OK' : 'Error' 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
83 84 85 |
# File 'lib/conoha.rb', line 83 def self.shutdown(server_id) server_action server_id, "os-stop" 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 |