1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #3455 from pdilung/affinity_groups

[ovirt] Implement affinity groups
This commit is contained in:
Wesley Beary 2015-02-24 15:02:04 -06:00
commit 9a05a06218
14 changed files with 237 additions and 0 deletions

View file

@ -20,6 +20,8 @@ module Fog
collection :volumes collection :volumes
model :quota model :quota
collection :quotas collection :quotas
model :affinity_group
collection :affinity_groups
request_path 'fog/ovirt/requests/compute' request_path 'fog/ovirt/requests/compute'
@ -54,6 +56,13 @@ module Fog
request :get_api_version request :get_api_version
request :list_quotas request :list_quotas
request :get_quota request :get_quota
request :list_affinity_groups
request :get_affinity_group
request :list_affinity_group_vms
request :create_affinity_group
request :destroy_affinity_group
request :add_to_affinity_group
request :remove_from_affinity_group
module Shared module Shared
# converts an OVIRT object into an hash for fog to consume. # converts an OVIRT object into an hash for fog to consume.

View file

@ -0,0 +1,25 @@
module Fog
module Compute
class Ovirt
class AffinityGroup < Fog::Model
identity :id
attribute :name
attribute :positive
attribute :enforcing
def vms
id.nil? ? [] : service.list_affinity_group_vms(id)
end
def destroy
service.destroy_affinity_group(id)
end
def to_s
name
end
end
end
end
end

View file

@ -0,0 +1,20 @@
require 'fog/core/collection'
require 'fog/ovirt/models/compute/affinity_group'
module Fog
module Compute
class Ovirt
class AffinityGroups < Fog::Collection
model Fog::Compute::Ovirt::AffinityGroup
def all(filters = {})
load service.list_affinity_groups(filters)
end
def get(id)
new service.get_affinity_group(id)
end
end
end
end
end

View file

@ -99,6 +99,16 @@ module Fog
service.detach_volume(id, attrs) service.detach_volume(id, attrs)
end end
def add_to_affinity_group(attrs)
wait_for { stopped? } if attrs[:blocking]
service.add_to_affinity_group(id, attrs)
end
def remove_from_affinity_group(attrs)
wait_for { stopped? } if attrs[:blocking]
service.remove_from_affinity_group(id, attrs)
end
def start(options = {}) def start(options = {})
wait_for { !locked? } if options[:blocking] wait_for { !locked? } if options[:blocking]
service.vm_action(:id =>id, :action => :start) service.vm_action(:id =>id, :action => :start)

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Ovirt
class Real
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
end
class Mock
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
true
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Compute
class Ovirt
class Real
def create_affinity_group(attrs)
client.create_affinity_group(attrs)
end
end
class Mock
def create_affinity_group(attrs)
xml = read_xml('affinitygroup.xml')
OVIRT::AffinityGroup::new(self, Nokogiri::XML(xml).root)
end
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Compute
class Ovirt
class Real
def destroy_affinity_group(id)
raise ArgumentError, "instance id is a required parameter" unless id
client.destroy_affinity_group(id)
end
end
class Mock
def destroy_affinity_group(id)
raise ArgumentError, "instance id is a required parameter" unless id
true
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Compute
class Ovirt
class Real
def get_affinity_group(id)
ovirt_attrs client.affinity_group(id)
end
end
class Mock
def get_affinity_group(id)
xml = read_xml('affinitygroup.xml')
ovirt_attrs OVIRT::AffinityGroup::new(self, Nokogiri::XML(xml).root)
end
end
end
end
end

View file

@ -0,0 +1,22 @@
module Fog
module Compute
class Ovirt
class Real
def list_affinity_group_vms(id)
client.affinity_group_vms(id).map {|vm| servers.get(vm.id)}
end
end
class Mock
def list_affinity_group_vms(id)
vms = []
Nokogiri::XML(read_xml('affinitygroup_vms.xml')).xpath('/vms/vm/@id').each do |id|
xml = Nokogiri::XML(read_xml('vms.xml')).xpath("/vms/vm[@id='%s']" % id.value).first
vms << ovirt_attrs(OVIRT::VM::new(self, xml))
end
vms
end
end
end
end
end

View file

@ -0,0 +1,20 @@
module Fog
module Compute
class Ovirt
class Real
def list_affinity_groups(filters = {})
client.affinity_groups(filters).map {|ovirt_obj| ovirt_attrs ovirt_obj}
end
end
class Mock
def list_affinity_groups(filters = {})
xml = read_xml('affinitygroups.xml')
Nokogiri::XML(xml).xpath('/affinity_groups/affinity_group').map do |ag|
ovirt_attrs OVIRT::AffinityGroup::new(self, ag)
end
end
end
end
end
end

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<affinity_group href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/9aaec56b-e24d-4fce-82a1-21a7b642ab0f" id="9aaec56b-e24d-4fce-82a1-21a7b642ab0f">
<name>test1_ag</name>
<link href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/9aaec56b-e24d-4fce-82a1-21a7b642ab0f/vms" rel="vms"/>
<cluster href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa" id="a240aac1-d03a-4c69-923e-a295200539fa"/>
<positive>true</positive>
<enforcing>false</enforcing>
</affinity_group>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vms>
<vm href="/api/vms/5ee86332-7b19-465b-8801-2a12ed0d6c1b" id="5ee86332-7b19-465b-8801-2a12ed0d6c1b">
<name>test-vm1</name>
</vm>
<vm href="/api/vms/349764bb-eba3-4466-abef-f18f4c40c9f1" id="349764bb-eba3-4466-abef-f18f4c40c9f1">
<name>fosdem</name>
</vm>
</vms>

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<affinity_groups>
<affinity_group href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/ff73a83f-10b2-44ae-8c98-a29b13ae0c19" id="ff73a83f-10b2-44ae-8c98-a29b13ae0c19">
<name>test2_ag</name>
<link href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/ff73a83f-10b2-44ae-8c98-a29b13ae0c19/vms" rel="vms"/>
<cluster href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa" id="a240aac1-d03a-4c69-923e-a295200539fa"/>
<positive>true</positive>
<enforcing>true</enforcing>
</affinity_group>
<affinity_group href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/9aaec56b-e24d-4fce-82a1-21a7b642ab0f" id="9aaec56b-e24d-4fce-82a1-21a7b642ab0f">
<name>test1_ag</name>
<link href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa/affinitygroups/9aaec56b-e24d-4fce-82a1-21a7b642ab0f/vms" rel="vms"/>
<cluster href="/api/clusters/a240aac1-d03a-4c69-923e-a295200539fa" id="a240aac1-d03a-4c69-923e-a295200539fa"/>
<positive>true</positive>
<enforcing>false</enforcing>
</affinity_group>
</affinity_groups>

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Ovirt
class Real
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
end
class Mock
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
true
end
end
end
end
end