Class: Chef::Knife::Cloud::OvirtService

Inherits:
FogService
  • Object
show all
Defined in:
lib/chef/knife/cloud/ovirt_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OvirtService

Returns a new instance of OvirtService.



13
14
15
16
17
18
19
20
21
22
# File 'lib/chef/knife/cloud/ovirt_service.rb', line 13

def initialize(options = {})
  Chef::Log.debug("ovirt_username #{Chef::Config[:knife][:ovirt_username]}")

  super(options.merge(auth_params: {
                        provider: 'ovirt',
                        ovirt_username: Chef::Config[:knife][:ovirt_username],
                        ovirt_password: Chef::Config[:knife][:ovirt_password],
                        ovirt_url: Chef::Config[:knife][:ovirt_url],
                      }))
end

Instance Method Details

#add_api_endpointObject



24
25
26
# File 'lib/chef/knife/cloud/ovirt_service.rb', line 24

def add_api_endpoint
  @auth_params.merge!(ovirt_url: Chef::Config[:knife][:api_endpoint]) unless Chef::Config[:knife][:api_endpoint].nil?
end

#create_server(options = {}) ⇒ Object

originally lifted from knife-cloud/lib/chef/knife/cloud/fog/service.rb



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
# File 'lib/chef/knife/cloud/ovirt_service.rb', line 29

def create_server(options = {})
  begin
    add_custom_attributes(options[:server_def])
    server = connection.servers.create(options[:server_def])

    print "\nWaiting For Server"
    server.wait_for(Integer(options[:server_create_timeout])) do
      print '.'
      !locked?
    end

    # attach/or create any volumes.
    options[:server_volumes].each do |voldef|
      Chef::Log.debug("Volume definition: #{voldef}")
      if voldef.key?(:size) || voldef.key?(:size_gb)
        # create a new volume
        result = connection.add_volume(server.id, voldef)
        name = (result / 'disk/name').first.text
      elsif voldef.key? :id
        server.attach_volume(voldef)
        name = voldef[:id]
      else
        raise CloudExceptions::ServerCreateError, "cannot handle volume definition #{voldef}"
      end

      print "\nAttached #{name} volume"
    end

    print "\nWaiting For Volumes"
    server.wait_for(Integer(options[:server_create_timeout])) do
      print '.'
      !locked?
    end
    Chef::Log.debug("options: #{options}")
    server.start_with_cloudinit(user_data: options[:cloud_init])
  rescue Excon::Error::BadRequest => e
    response = Chef::JSONCompat.from_json(e.response.body)
    message = if response['badRequest']['code'] == 400
                "Bad request (400): #{response['badRequest']['message']}"
              else
                "Unknown server error (#{response['badRequest']['code']}): #{response['badRequest']['message']}"
              end
    ui.fatal(message)
    raise CloudExceptions::ServerCreateError, message
  rescue Fog::Errors::Error => e
    raise CloudExceptions::ServerCreateError, e.message
  end

  print "\n#{ui.color("Waiting for server [wait time = #{options[:server_create_timeout]}]", :magenta)}"

  # wait for it to be ready to do stuff
  server.wait_for(Integer(options[:server_create_timeout])) do
    print '.'
    ready?
  end

  puts("\n")
  server
end