class Chef::Provisioning::FogDriver::Providers::XenServer
Public Class Methods
compute_options_for(provider, id, config)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 25 def self.compute_options_for(provider, id, config) new_compute_options = {} new_compute_options[:provider] = provider new_config = { driver_options: { compute_options: new_compute_options } } new_defaults = { driver_options: { compute_options: {} }, machine_options: { bootstrap_options: { affinity: id } } } result = Cheffish::MergedConfig.new(new_config, config, new_defaults) new_compute_options[:xenserver_url] = id if id && id != "" credential = Fog.credentials new_compute_options[:xenserver_username] ||= credential[:xenserver_username] new_compute_options[:xenserver_password] ||= credential[:xenserver_password] new_compute_options[:xenserver_url] ||= credential[:xenserver_url] new_compute_options[:xenserver_timeout] ||= 300 new_compute_options[:xenserver_redirect_to_master] ||= true id = result[:driver_options][:compute_options][:xenserver_url] [result, id] end
Public Instance Methods
bootstrap_options_for(machine_spec, machine_options)
click to toggle source
Calls superclass method
Chef::Provisioning::FogDriver::Driver#bootstrap_options_for
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 13 def bootstrap_options_for(machine_spec, machine_options) bootstrap_options = super bootstrap_options[:tags] = bootstrap_options[:tags].map { |k, v| "#{k}: #{v}" } bootstrap_options end
converge_floating_ips(action_handler, machine_spec, machine_options, server)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 150 def converge_floating_ips(action_handler, machine_spec, machine_options, server) # XenServer does not have floating IPs end
create_many_servers(num_servers, bootstrap_options, parallelizer) { |server| ... }
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 70 def create_many_servers(num_servers, bootstrap_options, parallelizer) parallelizer.parallelize(1.upto(num_servers)) do |_i| compute.default_template = bootstrap_options[:template] if bootstrap_options[:template] raise "No server can be created without a template, please set a template name as bootstrap_options" unless compute.default_template server = compute.default_template.clone bootstrap_options[:name] if bootstrap_options[:affinity] host = compute.hosts.all.select { |h| h.address == bootstrap_options[:affinity] }.first unless host raise "Host with ID #{bootstrap_options[:affinity]} not found." end server.affinity = host.reference end unless bootstrap_options[:memory].nil? mem = (bootstrap_options[:memory].to_i * 1024 * 1024).to_s server.set_attribute "memory_limits", mem, mem, mem, mem end unless bootstrap_options[:cpus].nil? cpus = (bootstrap_options[:cpus]).to_s server.set_attribute "VCPUs_max", cpus server.set_attribute "VCPUs_at_startup", cpus end # network configuration through xenstore attrs = {} unless bootstrap_options[:network].nil? network = bootstrap_options[:network] net_names = network[:vifs] if net_names server.vifs.each(&:destroy) compute.networks.select { |net| Array(net_names).include? net.name }.each do |net| compute.vifs.create vm: server, network: net, device: "0" end end attrs["vm-data/ip"] = network[:vm_ip] if network[:vm_ip] attrs["vm-data/gw"] = network[:vm_gateway] if network[:vm_gateway] attrs["vm-data/nm"] = network[:vm_netmask] if network[:vm_netmask] attrs["vm-data/ns"] = network[:vm_dns] if network[:vm_dns] attrs["vm-data/dm"] = network[:vm_domain] if network[:vm_domain] server.set_attribute "xenstore_data", attrs unless attrs.empty? end userdevice = 1 (bootstrap_options[:additional_disks] || {}).each do |name, data| sr_name = data[:sr] storage_repository = compute.storage_repositories.find { |sr| sr.name == sr_name } raise "You must specify sr name to add additional disks" unless storage_repository raise "You must specify size to add additional disk" unless data[:size] gb = 1_073_741_824 size = data[:size].to_i * gb vdi_params = { name: name } vdi_params[:storage_repository] = storage_repository vdi_params[:description] == data[:description] if data[:description] vdi_params[:virtual_size] = size.to_s vdi = compute.vdis.create vdi_params compute.vbds.create vm: server, vdi: vdi, userdevice: userdevice.to_s, bootable: false userdevice += 1 end server.provision yield server if block_given? server end.to_a end
creator()
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 9 def creator compute_options[:xenserver_username] end
server_for(machine_spec)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 49 def server_for(machine_spec) if machine_spec.reference compute.servers.get(compute.get_by_uuid(machine_spec.reference["server_id"], "VM")) end end
servers_for(specs_and_options)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 55 def servers_for(specs_and_options) result = {} specs_and_options.each do |machine_spec, _machine_options| if machine_spec.reference if machine_spec.reference["driver_url"] != driver_url raise "Switching a machine's driver from #{machine_spec.reference['driver_url']} to #{driver_url} for is not currently supported! Use machine :destroy and then re-create the machine on the new driver." end result[machine_spec] = compute.servers.get(compute.get_by_uuid(machine_spec.reference["server_id"], "VM")) else result[machine_spec] = nil end end result end
ssh_options_for(_machine_spec, machine_options, _server)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 19 def ssh_options_for(_machine_spec, machine_options, _server) { auth_methods: ["password"], timeout: (machine_options[:ssh_timeout] || 600), password: machine_options[:ssh_password] }.merge(machine_options[:ssh_options] || {}) end
start_server(action_handler, machine_spec, server)
click to toggle source
# File lib/chef/provisioning/fog_driver/providers/xenserver.rb, line 140 def start_server(action_handler, machine_spec, server) if server.state == "Halted" action_handler.perform_action "start machine #{machine_spec.name} (#{server.id} on #{driver_url})" do server.start machine_spec.reference["started_at"] = Time.now.to_i end machine_spec.save(action_handler) end end