Class: Vmit::Network

Inherits:
RefcountedResource show all
Defined in:
lib/vmit/network.rb

Direct Known Subclasses

BridgedNetwork

Instance Attribute Summary

Attributes inherited from RefcountedResource

#lockfile_dir, #lockfile_path, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RefcountedResource

#auto, #initialize, make_temp

Constructor Details

This class inherits a constructor from Vmit::RefcountedResource

Class Method Details

.create(config) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/vmit/network.rb', line 39

def self.create(config)
  case config
    when Hash then from_config(config)
    when String then from_alias(config)
    else raise "Can't build network from #{config}"
  end
end

.defaultObject



63
64
65
# File 'lib/vmit/network.rb', line 63

def self.default
  BridgedNetwork.new(BridgedNetwork::DEFAULT_NETWORK)
end

.from_alias(name) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vmit/network.rb', line 47

def self.from_alias(name)
  File.open(File.join(ENV['HOME'], '.vmit', 'networks.yml')) do |f|
    # transform keys into Symbols
    networks = YAML::load(f)
    if networks.has_key?(name)
      return from_config(networks[name].symbolize_keys)
    else
      raise "Unknown network #{name}"
    end
  end
end

.from_config(config) ⇒ Object



59
60
61
# File 'lib/vmit/network.rb', line 59

def self.from_config(config)
  BridgedNetwork.new(config[:address])
end

Instance Method Details

#resource_classObject



35
36
37
# File 'lib/vmit/network.rb', line 35

def resource_class
  'network'
end