Class: Kitchen::Driver::Rackspace

Inherits:
SSHBase
  • Object
show all
Defined in:
lib/kitchen/driver/rackspace.rb

Overview

Rackspace driver for Kitchen.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Rackspace

Returns a new instance of Rackspace.



67
68
69
70
# File 'lib/kitchen/driver/rackspace.rb', line 67

def initialize(config)
  super
  Fog.timeout = config[:wait_for].to_i
end

Instance Method Details

#create(state) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/driver/rackspace.rb', line 72

def create(state)
  server = create_server
  state[:server_id] = server.id
  info("Rackspace instance <#{state[:server_id]}> created.")
  server.wait_for { ready? }
  puts '(server ready)'
  rackconnect_check(server) if config[:rackconnect_wait]
  state[:hostname] = hostname(server)
  tcp_check(state)
rescue Fog::Errors::Error, Excon::Errors::Error => ex
  raise ActionFailed, ex.message
end

#default_imageObject



95
96
97
# File 'lib/kitchen/driver/rackspace.rb', line 95

def default_image
  images[instance.platform.name]
end

#default_nameObject

Generate what should be a unique server name up to 63 total chars Base name: 15 Username: 15 Hostname: 23 Random string: 7 Separators: 3

Total: 63



107
108
109
110
111
112
113
114
# File 'lib/kitchen/driver/rackspace.rb', line 107

def default_name
  [
    instance.name.gsub(/\W/, '')[0..14],
    (Etc.getlogin || 'nologin').gsub(/\W/, '')[0..14],
    Socket.gethostname.gsub(/\W/, '')[0..22],
    Array.new(7) { rand(36).to_s(36) }.join
  ].join('-')
end

#destroy(state) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/kitchen/driver/rackspace.rb', line 85

def destroy(state)
  return if state[:server_id].nil?

  server = compute.servers.get(state[:server_id])
  server.destroy unless server.nil?
  info("Rackspace instance <#{state[:server_id]}> destroyed.")
  state.delete(:server_id)
  state.delete(:hostname)
end