2012-04-02 07:25:03 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
class Network < Fog::Model
|
|
|
|
# API Reference here:
|
|
|
|
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=network
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
identity :reference
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :uuid
|
2012-12-22 18:21:33 -05:00
|
|
|
attribute :__vifs, :aliases => :VIFs
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :tags
|
|
|
|
attribute :mtu, :aliases => :MTU
|
|
|
|
attribute :bridge
|
|
|
|
attribute :description, :aliases => :name_description
|
|
|
|
attribute :name, :aliases => :name_label
|
|
|
|
attribute :other_config
|
|
|
|
attribute :__pifs, :aliases => :PIFs
|
2012-12-22 18:21:33 -05:00
|
|
|
attribute :allowed_operations
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :current_operations
|
|
|
|
attribute :blobs
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
def refresh
|
2012-12-22 18:21:33 -05:00
|
|
|
data = service.get_record( reference, 'network' )
|
2012-04-02 07:25:03 -04:00
|
|
|
merge_attributes( data )
|
|
|
|
true
|
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
#
|
|
|
|
# Return the list of network related PIFs
|
|
|
|
#
|
|
|
|
def pifs
|
|
|
|
p = []
|
|
|
|
__pifs.each do |pif|
|
2012-12-22 18:21:33 -05:00
|
|
|
p << service.pifs.get(pif)
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
p
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Return the list of network related VIFs
|
|
|
|
#
|
|
|
|
def vifs
|
|
|
|
v = []
|
|
|
|
__vifs.each do |vif|
|
2012-12-22 18:21:33 -05:00
|
|
|
v << service.vifs.get(vif)
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
v
|
|
|
|
end
|
|
|
|
|
2013-03-26 12:33:39 -04:00
|
|
|
# Creates a new network
|
|
|
|
#
|
|
|
|
# service = Fog::Compute[:xenserver]
|
|
|
|
#
|
|
|
|
# # create network 'foonet'
|
|
|
|
# net = service.networks.create :name => 'foonet',
|
|
|
|
# :description => 'test network'
|
|
|
|
#
|
|
|
|
# @returns [Boolean]
|
|
|
|
#
|
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
ref = service.create_network name, attributes
|
|
|
|
data = service.get_record ref, 'network'
|
|
|
|
merge_attributes data
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Destroys a network
|
|
|
|
#
|
|
|
|
# service = Fog::Compute[:xenserver]
|
|
|
|
#
|
|
|
|
# # find network 'foonet' and destroy it
|
|
|
|
# net = service.networks.find { |net| net.name == 'foonet' }
|
|
|
|
# net.destroy
|
|
|
|
#
|
|
|
|
# @returns [Boolean]
|
|
|
|
#
|
|
|
|
def destroy
|
|
|
|
requires :reference
|
|
|
|
service.destroy_network reference
|
|
|
|
true
|
|
|
|
end
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|