Class: Kitchen::Driver::Propeller

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/propeller.rb

Overview

inherit base

Instance Method Summary collapse

Instance Method Details

#create(state) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/kitchen/driver/propeller.rb', line 63

def create(state)
  puts "End Point: #{config[:driver_options][:endpoint]}"
  data = config[:driver_options][:vmName].split(".")
  hn = SecureRandom.hex(4)
  finalVmName = data[0] + '-' + hn + '.' + data[1]
  puts "Building Machine: #{finalVmName}"
  kitchenData = {
    :tenantName => config[:driver_options][:tenantName],
    :request =>
      [{
        :vmName =>  finalVmName,
        :keyPair => config[:driver_options][:keyPair],
        :serverType => config[:driver_options][:serverType]
      }] }
  @state = state
  info("Creating virtual machine for #{instance.name}.")
  uri = URI(config[:driver_options][:endpoint])
  req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'user' =>  config[:driver_options][:user])
  req.body = kitchenData.to_json
  res = Net::HTTP.start(uri.hostname, uri.port, :read_timeout => 300) do |http|
    res = http.request(req)
    vmo = JSON.parse(res.body)
    puts vmo
    sdat = vmo[0]
    @state[:username] = 'centos'
    @state[:id] = sdat['serverId']
    @state[:hostname] = sdat['vmName']
    @state[:ssh_key] = config[:driver_options][:ssh_key]
    @state[:networkName] = config[:driver_options][:networkName]
    info("Propeller instance #{instance.to_str} created ID: #{sdat['serverId']}.")
    info("Waiting for instance #{instance.to_str} to resolv.")
    up?(sdat['vmName'])
  end
end

#destroy(state) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/kitchen/driver/propeller.rb', line 98

def destroy(state)
  @state = state
  #return unless vm_exists

  instance.transport.connection(state).close
  info("Destroying virtual machine for #{instance.name}.")

  puts state[:id]

  uri = URI("#{config[:driver_options][:endpoint]}/#{state[:id]}")
  req = Net::HTTP::Delete.new(uri, 'Content-Type' => 'application/json',
    'user' => config[:driver_options][:user])

  req.body = 'user:[email protected]'

  res = Net::HTTP.start(uri.hostname, uri.port) do |http|
    res = http.request(req)
    puts "response #{res.body}"
  end
  info("The Propeller instance #{instance.to_str} has been removed.")

  state.delete(:id)
end

#up?(host) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kitchen/driver/propeller.rb', line 42

def up?(host)

 spinner = Enumerator.new do |e|
   loop do
     e.yield '|'
     e.yield '/'
     e.yield '-'
     e.yield '\\'
  end
end
  until Net::Ping::External.new(host).ping? do
     if $stdout.tty?
       printf("\r %s", spinner.next)
       sleep 0.1
     else
      printf "."
      sleep 0.1
    end            
  end
end