Class: Kitchen::Driver::Sakuracloud
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Sakuracloud
- Defined in:
- lib/kitchen/driver/sakuracloud.rb
Instance Method Summary collapse
- #create(state) ⇒ Object
- #create_server ⇒ Object
- #destroy(state) ⇒ Object
- #destroy_server(id) ⇒ Object
Instance Method Details
#create(state) ⇒ Object
28 29 30 31 32 |
# File 'lib/kitchen/driver/sakuracloud.rb', line 28 def create(state) server = create_server state[:id] = server.id state[:hostname] = server.interfaces.first["IPAddress"] end |
#create_server ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kitchen/driver/sakuracloud.rb', line 38 def create_server raise Kitchen::ActionFailed "" unless config[:sshkey_id] begin server = compute.servers.create( :name => instance.name, :sshkey => config[:sshkey_id], :serverplan => config[:serverplan], :volume => { :diskplan => config[:diskplan], :size_mb => config[:size_mb], :sourcearchive => config[:sourcearchive] }, :boot => true ) rescue Excon::Errors::HTTPStatusError => e logger.error JSON.parse(e.response.body) raise e end server end |
#destroy(state) ⇒ Object
34 35 36 |
# File 'lib/kitchen/driver/sakuracloud.rb', line 34 def destroy(state) destroy_server(state[:id]) if state[:id] end |
#destroy_server(id) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kitchen/driver/sakuracloud.rb', line 59 def destroy_server(id) logger.debug "Trying to delete #{id} ..." begin server = compute.servers.get(id) server.stop(true) server.reload logger.debug("Waiting #{id} until down ... (in 15 sec)") 3.times do break if server.instance["Status"] == "down" sleep 5 server.reload end server.delete(true) rescue Excon::Errors::HTTPStatusError => e logger.error JSON.parse(e.response.body) raise e unless e.response.status == 404 end end |