Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/fog/libvirt/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class Compute < Fog::Service
request :upload_volume
request :clone_volume
request :list_networks
request :define_network
request :create_network
request :update_network
request :update_network_autostart
request :update_network_section
request :destroy_network
request :dhcp_leases
request :list_interfaces
Expand Down
39 changes: 39 additions & 0 deletions lib/fog/libvirt/models/compute/common/address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "fog/core/model"
require_relative "attribute_model"
require_relative "../util/util"

module Fog
module Libvirt
class Compute
class Address < Fog::Libvirt::Compute::AttributeModel
include Fog::Libvirt::Util

attribute :type

def self.new(attributes = {})
return super if self != Address

klass = types[attributes[:type]&.to_sym]
klass ? klass.new(attributes) : super
end

def self.types
{
:pci => PciAddress,
:drive => DriveAddress
}
end

def self.parse_xml(node)
return nil unless node

xml_attrs(node)
end

def build_xml(xml)
xml.address(attrs_xml(attributes.compact, :switch => true))
end
end
end
end
end
38 changes: 38 additions & 0 deletions lib/fog/libvirt/models/compute/common/attribute_model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "fog/core/model"
require_relative "clonable_model"

module Fog
module Libvirt
class Compute
class AttributeModel < Fog::Model
include ClonableModel

def initialize(attributes = {}) # rubocop:disable Lint/MissingSuper
# don't call super because we want to allow regular :service attribute
merge_attributes(attributes)
end

def self.cast(item)
return item if item.is_a?(self)

new(item)
end

def ==(other)
return super unless other.is_a?(Fog::Model)
return false unless self.class == other.class

other.attributes.compact == attributes.compact
end

def hash
attributes.compact.hash
end

def eql?(other)
self == other
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/fog/libvirt/models/compute/common/clonable_model.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "fog/core/model"

module Fog
module Libvirt
class Compute
module ClonableModel
def clone
copy = super
copy.instance_variable_set(:@attributes, Marshal.load(Marshal.dump(attributes)))
copy
end

def dup
copy = super
copy.instance_variable_set(:@attributes, Marshal.load(Marshal.dump(attributes)))
copy.identity = nil if copy.respond_to?(:identity=)
copy
end
end
end
end
end
25 changes: 25 additions & 0 deletions lib/fog/libvirt/models/compute/common/drive_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "fog/core/model"
require_relative "address"

module Fog
module Libvirt
class Compute
class DriveAddress < Fog::Libvirt::Compute::Address
attribute :controller
attribute :bus
attribute :target
attribute :unit

def initialize(attributes = {})
super(defaults.merge(attributes))
end

private

def defaults
{ :type => "drive" }
end
end
end
end
end
26 changes: 26 additions & 0 deletions lib/fog/libvirt/models/compute/common/pci_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "fog/core/model"
require_relative "address"

module Fog
module Libvirt
class Compute
class PciAddress < Fog::Libvirt::Compute::Address
attribute :domain
attribute :bus
attribute :slot
attribute :function
attribute :multifunction

def initialize(attributes = {})
super(defaults.merge(attributes))
end

private

def defaults
{ :type => "pci", :domain => 0 }
end
end
end
end
end
Loading
Loading