Class: Fog::Compute::Ovirt::Real

Inherits:
Object
  • Object
show all
Extended by:
Shared
Includes:
Shared
Defined in:
lib/fog/ovirt/compute.rb,
lib/fog/ovirt/requests/compute/create_vm.rb,
lib/fog/ovirt/requests/compute/get_quota.rb,
lib/fog/ovirt/requests/compute/update_vm.rb,
lib/fog/ovirt/requests/compute/vm_action.rb,
lib/fog/ovirt/requests/compute/vm_ticket.rb,
lib/fog/ovirt/requests/compute/add_volume.rb,
lib/fog/ovirt/requests/compute/destroy_vm.rb,
lib/fog/ovirt/requests/compute/datacenters.rb,
lib/fog/ovirt/requests/compute/get_cluster.rb,
lib/fog/ovirt/requests/compute/list_quotas.rb,
lib/fog/ovirt/requests/compute/get_template.rb,
lib/fog/ovirt/requests/compute/list_volumes.rb,
lib/fog/ovirt/requests/compute/add_interface.rb,
lib/fog/ovirt/requests/compute/attach_volume.rb,
lib/fog/ovirt/requests/compute/detach_volume.rb,
lib/fog/ovirt/requests/compute/list_clusters.rb,
lib/fog/ovirt/requests/compute/list_networks.rb,
lib/fog/ovirt/requests/compute/update_volume.rb,
lib/fog/ovirt/requests/compute/destroy_volume.rb,
lib/fog/ovirt/requests/compute/list_templates.rb,
lib/fog/ovirt/requests/compute/get_api_version.rb,
lib/fog/ovirt/requests/compute/list_vm_volumes.rb,
lib/fog/ovirt/requests/compute/storage_domains.rb,
lib/fog/ovirt/requests/compute/update_interface.rb,
lib/fog/ovirt/requests/compute/destroy_interface.rb,
lib/fog/ovirt/requests/compute/get_affinity_group.rb,
lib/fog/ovirt/requests/compute/list_vm_interfaces.rb,
lib/fog/ovirt/requests/compute/get_virtual_machine.rb,
lib/fog/ovirt/requests/compute/list_affinity_groups.rb,
lib/fog/ovirt/requests/compute/add_to_affinity_group.rb,
lib/fog/ovirt/requests/compute/create_affinity_group.rb,
lib/fog/ovirt/requests/compute/list_template_volumes.rb,
lib/fog/ovirt/requests/compute/list_virtual_machines.rb,
lib/fog/ovirt/requests/compute/destroy_affinity_group.rb,
lib/fog/ovirt/requests/compute/list_affinity_group_vms.rb,
lib/fog/ovirt/requests/compute/vm_start_with_cloudinit.rb,
lib/fog/ovirt/requests/compute/list_template_interfaces.rb,
lib/fog/ovirt/requests/compute/remove_from_affinity_group.rb

Constant Summary collapse

DISK_SIZE_TO_GB =
1073741824

Instance Method Summary collapse

Methods included from Shared

check_arguments, ovirt_attrs

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/fog/ovirt/compute.rb', line 118

def initialize(options={})
  require 'rbovirt'
  username   = options[:ovirt_username]
  password   = options[:ovirt_password]
  server     = options[:ovirt_server]
  port       = options[:ovirt_port]       || 8080
  api_path   = options[:ovirt_api_path]   || '/api'
  url        = options[:ovirt_url]        || "#{@scheme}://#{server}:#{port}#{api_path}"

  connection_opts = {}
  connection_opts[:datacenter_id] = options[:ovirt_datacenter]
  connection_opts[:ca_cert_store] = options[:ovirt_ca_cert_store]
  connection_opts[:ca_cert_file]  = options[:ovirt_ca_cert_file]
  connection_opts[:ca_no_verify]  = options[:ovirt_ca_no_verify]
  connection_opts[:filtered_api]  = options[:ovirt_filtered_api]

  @client = OVIRT::Client.new(username, password, url, connection_opts)
end

Instance Method Details

#add_interface(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/fog/ovirt/requests/compute/add_interface.rb', line 5

def add_interface(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id

  client.add_interface(id, options)
end

#add_to_affinity_group(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/fog/ovirt/requests/compute/add_to_affinity_group.rb', line 5

def add_to_affinity_group(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "affinity group id is a required parameter for add-to-affinity-group" unless options.key? :id
  client.add_vm_to_affinity_group(options[:id], id)
end

#add_volume(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/add_volume.rb', line 6

def add_volume(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id
  options[:size]=options[:size_gb].to_i*DISK_SIZE_TO_GB if options[:size_gb]
  client.add_volume(id, options)
end

#api_versionObject



137
138
139
# File 'lib/fog/ovirt/compute.rb', line 137

def api_version
  client.api_version
end

#attach_volume(id, options) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/attach_volume.rb', line 5

def attach_volume(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "volume id is a required parameter for attach-volume" unless options.key? :id

  client.attach_volume(id, options[:id])
end

#create_affinity_group(attrs) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/create_affinity_group.rb', line 5

def create_affinity_group(attrs)
  client.create_affinity_group(attrs)
end

#create_vm(attrs) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/create_vm.rb', line 5

def create_vm(attrs)
  client.create_vm(attrs)
end

#datacenters(filter = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/datacenters.rb', line 5

def datacenters filter={}
  client.datacenters(filter).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#destroy_affinity_group(id) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/fog/ovirt/requests/compute/destroy_affinity_group.rb', line 5

def destroy_affinity_group(id)
  raise ArgumentError, "instance id is a required parameter" unless id
  client.destroy_affinity_group(id)
end

#destroy_interface(id, options) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/destroy_interface.rb', line 5

def destroy_interface(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.key? :id

  client.destroy_interface(id, options[:id])
end

#destroy_vm(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/fog/ovirt/requests/compute/destroy_vm.rb', line 5

def destroy_vm(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  client.destroy_vm(options[:id])
end

#destroy_volume(id, options) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/destroy_volume.rb', line 5

def destroy_volume(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.key? :id

  client.destroy_volume(id, options[:id])
end

#detach_volume(id, options) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/detach_volume.rb', line 5

def detach_volume(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "volume id is a required parameter for detach-volume" unless options.key? :id

  client.detach_volume(id, options[:id])
end

#get_affinity_group(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/get_affinity_group.rb', line 5

def get_affinity_group(id)
  ovirt_attrs client.affinity_group(id)
end

#get_cluster(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/get_cluster.rb', line 5

def get_cluster(id)
  ovirt_attrs client.cluster(id)
end

#get_quota(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/get_quota.rb', line 5

def get_quota(id)
  ovirt_attrs client.quota(id)
end

#get_template(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/get_template.rb', line 5

def get_template(id)
  ovirt_attrs client.template(id)
end

#get_virtual_machine(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/get_virtual_machine.rb', line 5

def get_virtual_machine(id)
  ovirt_attrs client.vm(id)
end

#list_affinity_group_vms(id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_affinity_group_vms.rb', line 5

def list_affinity_group_vms(id)
  client.affinity_group_vms(id).map {|vm| servers.get(vm.id)}
end

#list_affinity_groups(filters = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_affinity_groups.rb', line 5

def list_affinity_groups(filters = {})
  client.affinity_groups(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_clusters(filters = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_clusters.rb', line 5

def list_clusters(filters = {})
  client.clusters(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_networks(cluster_id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_networks.rb', line 5

def list_networks(cluster_id)
  client.networks(:cluster_id => cluster_id)
end

#list_quotas(filters = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_quotas.rb', line 5

def list_quotas(filters = {})
  client.quotas(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_template_interfaces(vm_id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_template_interfaces.rb', line 5

def list_template_interfaces(vm_id)
  client.template_interfaces(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_template_volumes(template_id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_template_volumes.rb', line 5

def list_template_volumes(template_id)
  client.template_volumes(template_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_templates(filters = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_templates.rb', line 5

def list_templates(filters = {})
  client.templates(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_virtual_machines(filters = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_virtual_machines.rb', line 5

def list_virtual_machines(filters = {})
  client.vms(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_vm_interfaces(vm_id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_vm_interfaces.rb', line 5

def list_vm_interfaces(vm_id)
  client.vm_interfaces(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_vm_volumes(vm_id) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_vm_volumes.rb', line 5

def list_vm_volumes(vm_id)
  client.vm_volumes(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#list_volumesObject



5
6
7
# File 'lib/fog/ovirt/requests/compute/list_volumes.rb', line 5

def list_volumes
  client.disks.map {|ovirt_obj| ovirt_attrs ovirt_obj}
end

#remove_from_affinity_group(id, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/fog/ovirt/requests/compute/remove_from_affinity_group.rb', line 5

def remove_from_affinity_group(id, options = {})
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "affinity group id is a required parameter for remove-from-affinity-group" unless options.key? :id
  client.delete_vm_from_affinity_group(options[:id], id)
end

#storage_domains(filter = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/storage_domains.rb', line 5

def storage_domains filter={}
  client.storagedomains(filter)
end

#update_interface(id, options) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/ovirt/requests/compute/update_interface.rb', line 15

def update_interface(id, options)
  check_arguments(id, options)

  interface_id = options[:id]
  options.delete(:id)

  client.update_interface(id, interface_id, options)
end

#update_vm(attrs) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/update_vm.rb', line 5

def update_vm(attrs)
  client.update_vm(attrs)
end

#update_volume(id, options) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/fog/ovirt/requests/compute/update_volume.rb', line 16

def update_volume(id, options)
  check_arguments(id, options)

  disk_id = options[:id]
  options.delete(:id)

  client.update_volume(id, disk_id, options)
  true # If we come here, expect success and return true
end

#vm_action(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/fog/ovirt/requests/compute/vm_action.rb', line 5

def vm_action(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  raise ArgumentError, "action is a required parameter" unless options.key? :action

  client.vm_action options[:id], options[:action]
end

#vm_start_with_cloudinit(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/fog/ovirt/requests/compute/vm_start_with_cloudinit.rb', line 5

def vm_start_with_cloudinit(options = {})
  raise ArgumentError, "instance id is a required parameter" unless options.key? :id
  client.vm_start_with_cloudinit(options[:id], options[:user_data])
end

#vm_ticket(id, options = {}) ⇒ Object



5
6
7
# File 'lib/fog/ovirt/requests/compute/vm_ticket.rb', line 5

def vm_ticket(id, options = {})
  client.set_ticket(id, options)
end