Skip to content

Commit

Permalink
Merge 13e29c6 into e63cf6b
Browse files Browse the repository at this point in the history
  • Loading branch information
plribeiro3000 committed Jul 18, 2014
2 parents e63cf6b + 13e29c6 commit 9b1c6d9
Show file tree
Hide file tree
Showing 43 changed files with 268 additions and 157 deletions.
19 changes: 4 additions & 15 deletions lib/fog/compute/xen_server/models/network.rb
Expand Up @@ -15,31 +15,20 @@ class Network < Fog::Model
attribute :bridge
attribute :current_operations
attribute :default_locking_mode
attribute :description, :aliases => :name_description
attribute :description, :aliases => :name_description, :default => ''
attribute :mtu, :aliases => :MTU
attribute :name, :aliases => :name_label
attribute :other_config
attribute :name, :aliases => :name_label, :default => ''
attribute :other_config, :default => {}
attribute :tags
attribute :uuid

has_many :pifs, :pifs, :aliases => :PIFs
has_many :vifs, :vifs, :aliases => :VIFs

# Creates a new network
#
# service = Fog::Compute[:xenserver]
#
# # create network 'foonet'
# net = service.networks.create :name => 'foonet',
# :description => 'test network'
#
# @return [Boolean]
#
def save
requires :name
ref = service.create_network name, attributes
data = service.get_record ref, 'network'
merge_attributes data
merge_attributes service.networks.get(ref).attributes
true
end
end
Expand Down
76 changes: 35 additions & 41 deletions lib/fog/compute/xen_server/models/server.rb
Expand Up @@ -12,48 +12,52 @@ class Server < Fog::Compute::Server

identity :reference

attribute :actions_after_crash
attribute :actions_after_reboot
attribute :actions_after_shutdown
attribute :actions_after_crash, :default => 'Restart'
attribute :actions_after_reboot, :default => 'Restart'
attribute :actions_after_shutdown, :default => 'Destroy'
attribute :allowed_operations
attribute :blobs
attribute :blocked_operations
attribute :bios_strings
attribute :current_operations
attribute :domarch
attribute :domid
attribute :description, :aliases => :name_description
attribute :description, :aliases => :name_description, :default => ''
attribute :generation_id
attribute :ha_always_run
attribute :ha_restart_priority
attribute :hvm_boot_params, :aliases => :HVM_boot_params
attribute :hvm_boot_policy, :aliases => :HVM_boot_policy
attribute :hvm_boot_params, :aliases => :HVM_boot_params, :default => {}
attribute :hvm_boot_policy, :aliases => :HVM_boot_policy, :default => ''
attribute :hvm_shadow_multiplier, :aliases => :HVM_shadow_multiplier
attribute :is_a_snapshot
attribute :is_a_template
attribute :is_a_template, :default => true
attribute :is_control_domain
attribute :is_snapshot_from_vmpp
attribute :last_booted_record
attribute :last_boot_cpu_flags, :aliases => :last_boot_CPU_flags
attribute :memory_dynamic_max
attribute :memory_dynamic_min
attribute :memory_dynamic_max, :default => '536870912'
attribute :memory_dynamic_min, :default => '536870912'
attribute :memory_overhead
attribute :memory_static_max
attribute :memory_static_min
attribute :memory_static_max, :default => '536870912'
attribute :memory_static_min, :default => '536870912'
attribute :memory_target
attribute :name, :aliases => :name_label
attribute :name, :aliases => :name_label, :default => ''
attribute :order
attribute :other_config
attribute :pci_bus, :aliases => :PCI_bus
attribute :platform
attribute :other_config, :default => {}
attribute :pci_bus, :aliases => :PCI_bus, :default => ''
attribute :platform, :default => { 'nx' => 'true',
'acpi' => 'true',
'apic' => 'true',
'pae' => 'true',
'viridian' => 'true' }
attribute :power_state
attribute :pv_args, :aliases => :PV_args
attribute :pv_bootloader, :aliases => :PV_bootloader
attribute :pv_bootloader_args, :aliases => :PV_bootloader_args
attribute :pv_kernel, :aliases => :PV_kernel
attribute :pv_legacy_args, :aliases => :PV_legacy_args
attribute :pv_ramdisk, :aliases => :PV_ramdisk
attribute :recommendations
attribute :pv_args, :aliases => :PV_args, :default => '-- quiet console=hvc0'
attribute :pv_bootloader, :aliases => :PV_bootloader, :default => 'pygrub' # pvgrub, eliloader
attribute :pv_bootloader_args, :aliases => :PV_bootloader_args, :default => ''
attribute :pv_kernel, :aliases => :PV_kernel, :default => ''
attribute :pv_legacy_args, :aliases => :PV_legacy_args, :default => ''
attribute :pv_ramdisk, :aliases => :PV_ramdisk, :default => ''
attribute :recommendations, :default => ''
attribute :shutdown_delay
attribute :snapshot_info
attribute :snapshot_metadata
Expand All @@ -62,11 +66,11 @@ class Server < Fog::Compute::Server
attribute :tags
attribute :template_name
attribute :transportable_snapshot_id
attribute :user_version
attribute :user_version, :default => '0'
attribute :uuid
attribute :vcpus_at_startup, :aliases => :VCPUs_at_startup
attribute :vcpus_max, :aliases => :VCPUs_max
attribute :vcpus_params, :aliases => :VCPUs_params
attribute :vcpus_at_startup, :aliases => :VCPUs_at_startup, :default => '1'
attribute :vcpus_max, :aliases => :VCPUs_max, :default => '1'
attribute :vcpus_params, :aliases => :VCPUs_params, :default => {}
attribute :version
attribute :xenstore_data

Expand Down Expand Up @@ -114,24 +118,14 @@ def halted?

def save(params = {})
requires :name
nets = attributes[:networks] || []
if params[:auto_start].nil?
auto_start = true
else
auto_start = params[:auto_start]
end
nets = params.fetch(:networks, [])
auto_start = params.fetch(:auto_start, true)
if template_name
attr = service.get_record(
service.create_server( name, template_name, nets, :auto_start => auto_start),
'VM'
)
ref = service.create_server(name, template_name, nets, :auto_start => auto_start)
else
attr = service.get_record(
service.create_server_raw(attributes),
'VM'
)
ref = service.create_server_raw(attributes)
end
merge_attributes attr
merge_attributes service.servers.get(ref).attributes
true
end

Expand Down
43 changes: 10 additions & 33 deletions lib/fog/compute/xen_server/models/storage_repository.rb
Expand Up @@ -12,17 +12,17 @@ class StorageRepository < Fog::Model

attribute :allowed_operations
attribute :blobs
attribute :content_type
attribute :content_type, :default => 'user'
attribute :current_operations
attribute :description, :aliases => :name_description
attribute :description, :aliases => :name_description, :default => ''
attribute :introduced_by
attribute :local_cache_enabled
attribute :name, :aliases => :name_label
attribute :other_config
attribute :physical_size
attribute :physical_size, :default => '0'
attribute :physical_utilisation
attribute :shared
attribute :sm_config
attribute :shared, :default => false
attribute :sm_config, :default => {}
attribute :tags
attribute :type
attribute :uuid
Expand All @@ -31,34 +31,11 @@ class StorageRepository < Fog::Model
has_many :pbds, :pbds, :aliases => :PBDs
has_many :vdis, :vdis, :aliases => :VDIs

def save
requires :name
requires :type

# host is not a model attribute (not in XAPI at least),
# but we need it here
host = attributes[:host]
raise ArgumentError.new('host is required for this operation') unless
host

# Not sure if this is always required, so not raising exception if nil
device_config = attributes[:device_config]

# create_sr request provides sane defaults if some attributes are
# missing
attr = service.get_record(
service.create_sr( host.reference,
name,
type,
description || '',
device_config || {},
physical_size || '0',
content_type || 'user',
shared || false,
sm_config || {}),
'SR'
)
merge_attributes attr
def save(host, device_config = {})
requires :name, :type
ref = service.create_sr(host, name, type, description, device_config, physical_size, content_type,
shared || false, sm_config)
merge_attributes service.storage_repositories.get(ref).attributes
true
end
end
Expand Down
23 changes: 12 additions & 11 deletions lib/fog/compute/xen_server/models/vbd.rb
Expand Up @@ -11,23 +11,23 @@ class Vbd < Fog::Model
identity :reference

attribute :allowed_operations
attribute :bootable
attribute :bootable, :default => true
attribute :currently_attached
attribute :current_operations
attribute :device
attribute :empty
attribute :mode
attribute :other_config
attribute :qos_supported_algorithms
attribute :qos_algorithm_params
attribute :qos_algorithm_type
attribute :empty, :default => false
attribute :mode, :default => 'RW'
attribute :other_config, :default => { 'owner' => '' }
attribute :qos_supported_algorithms, :default => []
attribute :qos_algorithm_params, :default => {}
attribute :qos_algorithm_type, :default => ''
attribute :runtime_properties
attribute :status_code
attribute :status_detail
attribute :storage_lock
attribute :type
attribute :type, :default => 'Disk'
attribute :unpluggable
attribute :userdevice
attribute :userdevice, :default => '0'
attribute :uuid

has_one :metrics, :vbds_metrics
Expand All @@ -38,8 +38,9 @@ class Vbd < Fog::Model

def save
requires :vdi, :server
ref = service.create_vbd attributes[:server], attributes[:vdi], attributes
merge_attributes service.vbds.get(ref).attributes
ref = service.create_vbd(server, vdi, attributes)
merge_attributes(service.vbds.get(ref).attributes)
true
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/compute/xen_server/models/vdi.rb
Expand Up @@ -58,8 +58,9 @@ def initialize(attributes = {})

def save
requires :name, :storage_repository
ref = service.create_vdi attributes
ref = service.create_vdi(attributes)
merge_attributes service.vdis.get(ref).attributes
true
end
end
end
Expand Down
19 changes: 9 additions & 10 deletions lib/fog/compute/xen_server/models/vif.rb
Expand Up @@ -17,12 +17,12 @@ class Vif < Fog::Model
attribute :ipv4_allowed
attribute :ipv6_allowed
attribute :locking_mode
attribute :mac, :aliases => :MAC
attribute :mac_autogenerated, :aliases => :MAC_autogenerated
attribute :mtu, :aliases => :MTU
attribute :other_config
attribute :qos_algorithm_params
attribute :qos_algorithm_type
attribute :mac, :aliases => :MAC, :default => ''
attribute :mac_autogenerated, :aliases => :MAC_autogenerated, :default => 'True'
attribute :mtu, :aliases => :MTU, :default => '0'
attribute :other_config, :default => {}
attribute :qos_algorithm_params, :default => {}
attribute :qos_algorithm_type, :default => 'ratelimit'
attribute :qos_supported_algorithms
attribute :runtime_properties
attribute :status_code
Expand All @@ -36,11 +36,10 @@ class Vif < Fog::Model
alias_method :server, :vm

def save
requires :server
raise ArgumentError.new('network is required for this operation') \
unless attributes[:__network]
ref = service.create_vif attributes[:server], attributes[:__network]
requires :server, :network
ref = service.create_vif(server, network)
merge_attributes service.vifs.get(ref).attributes
true
end
end
end
Expand Down
28 changes: 3 additions & 25 deletions lib/fog/compute/xen_server/models/vlan.rb
Expand Up @@ -17,32 +17,10 @@ class Vlan < Fog::Model
has_one :tagged_pif, :pifs, :aliases => :tagged_PIF
has_one :untagged_pif, :pifs, :aliases => :untagged_PIF

# Creates a new VLAN.
#
# service = Fog::Compute[:xenserver]
#
# # create a network 'foo-net'
# net = service.networks.create :name => 'foo-net'
#
# # get the eth0 physical interface where the
# # VLAN subinterface will be added
# pif = service.pifs.find { |p| p.device == 'eth0' and p.physical }
#
# Fog::Compute[:xenserver].vlans.create :tag => 123,
# :network => net,
# :pif => pif
def save
def save(pif, network)
requires :tag
pif = attributes[:pif]
net = attributes[:network]
unless pif and net
raise Fog::Error.new 'save requires :pif and :network attributes'
end
ref = service.create_vlan attributes[:pif].reference,
tag,
attributes[:network].reference
data = service.get_record ref, 'VLAN'
merge_attributes data
ref = service.create_vlan(pif, tag, network)
merge_attributes service.vlans.get(ref).attributes
true
end
end
Expand Down
12 changes: 2 additions & 10 deletions lib/fog/compute/xen_server/requests/create_sr.rb
Expand Up @@ -32,18 +32,10 @@ def create_sr( host_ref,
content_type = 'user',
shared = false,
sm_config = {} )

host_ref = host_ref.reference if host_ref.kind_of? Fog::Compute::XenServer::StorageRepository
@connection.request(
{:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.create'},
host_ref,
device_config || {},
physical_size || '0',
name_label,
name_description || '',
type,
content_type,
shared || false,
sm_config || {}
host_ref, device_config, physical_size, name_label, name_description, type, content_type, shared, sm_config
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/fog/compute/xen_server/requests/create_vlan.rb
Expand Up @@ -7,15 +7,15 @@ class Real
#
# @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=VLAN
#
def create_vlan( pif_ref, vlan_id, network_ref )
def create_vlan(pif_ref, vlan_id, network_ref)
pif_ref = pif_ref.reference if pif_ref.kind_of? Fog::Compute::XenServer::Pif
network_ref = network_ref.reference if network_ref.kind_of? Fog::Compute::XenServer::Network
@connection.request(
{
:parser => Fog::Parsers::XenServer::Base.new,
:method => 'VLAN.create'
},
pif_ref,
vlan_id.to_s,
network_ref
pif_ref, vlan_id.to_s, network_ref
)
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/fog/compute/xen_server/models/blob_spec.rb
Expand Up @@ -33,4 +33,8 @@ def self.read_identity
blob_class.aliases.must_equal({ :name_description => :description,
:name_label => :name })
end

it "shouldn't have default values" do
blob_class.default_values.must_equal({})
end
end

0 comments on commit 9b1c6d9

Please sign in to comment.