Class: Xen::Vif

Inherits:
Object
  • Object
show all
Defined in:
lib/xen/config_file.rb

Overview

Virtual Network Interface

wiki.xensource.com/xenwiki/XenNetworking

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Vif

Returns a new instance of Vif.

Raises:



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/xen/config_file.rb', line 97

def initialize(*args)
  options = args.extract_options!
  
  # Validations - move them out into a validate function
  raise(ValidationFailed, 'message') if options[:vifname] == 'foos' 
  
  @ip = options[:ip].to_s.gsub /['"]/, ''
  @mac = options[:mac].to_s.gsub /['"]/, ''
  @bridge = options[:bridge].to_s.gsub /['"]/, ''
  @vifname = options[:vifname].to_s.gsub /['"]/, ''
end

Instance Attribute Details

#bridgeObject

Returns the value of attribute bridge.



95
96
97
# File 'lib/xen/config_file.rb', line 95

def bridge
  @bridge
end

#ipObject

Returns the value of attribute ip.



95
96
97
# File 'lib/xen/config_file.rb', line 95

def ip
  @ip
end

#macObject

Returns the value of attribute mac.



95
96
97
# File 'lib/xen/config_file.rb', line 95

def mac
  @mac
end

#vifnameObject

Returns the value of attribute vifname.



95
96
97
# File 'lib/xen/config_file.rb', line 95

def vifname
  @vifname
end

Class Method Details

.from_str(value) ⇒ Object



109
110
111
112
# File 'lib/xen/config_file.rb', line 109

def self.from_str(value)
  options = value.scan(/(\w+)=([^,]+)/).inject({}){ |m, (k, v)| m[k.to_sym] = v; m }
  new(options)
end

Instance Method Details

#to_strObject



114
115
116
117
118
# File 'lib/xen/config_file.rb', line 114

def to_str
  %w(ip mac bridge vifname).collect { |key| 
    "#{key}=#{instance_variable_get('@' + key)}" unless instance_variable_get('@'+key) == ''
  }.compact.join(',')
end