Class: Arver::Host

Inherits:
Object
  • Object
show all
Includes:
NodeWithScriptHooks, PartitionHierarchyNode
Defined in:
lib/arver/host.rb

Instance Attribute Summary collapse

Attributes included from NodeWithScriptHooks

#post_close, #post_open, #pre_close, #pre_open

Attributes included from PartitionHierarchyNode

#name, #parent

Instance Method Summary collapse

Methods included from NodeWithScriptHooks

#script_hooks_from_hash, #script_hooks_to_yaml

Methods included from PartitionHierarchyNode

#==, #add_child, #child, #children, #each_node, #each_partition, #find, #has_child?, #has_parent?, #path, #target?, #to_ascii

Constructor Details

#initialize(name, hostgroup) ⇒ Host

Returns a new instance of Host.



10
11
12
13
# File 'lib/arver/host.rb', line 10

def initialize( name, hostgroup )
  self.name = name
  self.parent = hostgroup
end

Instance Attribute Details

#addressObject



23
24
25
26
# File 'lib/arver/host.rb', line 23

def address
  return @address unless @address.nil?
  self.name
end

#portObject

Returns the value of attribute port.



4
5
6
# File 'lib/arver/host.rb', line 4

def port
  @port
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/arver/host.rb', line 4

def username
  @username
end

Instance Method Details

#add_partition(partition) ⇒ Object



15
16
17
# File 'lib/arver/host.rb', line 15

def add_partition(partition)
  add_child(partition)
end

#from_hash(hash) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/arver/host.rb', line 53

def from_hash( hash )
  script_hooks_from_hash( hash )
  hash.each do | name, data |
    if( name == "port" )
      self.port = data
      next
    end
    if( name == "address" )
      self.address = data
      next
    end
    if( name == "username" )
      self.username= data
      next
    end
    #no matching keyword -> its a partition:
    p = Arver::Partition.new( name, self )
    p.from_hash( data )
  end
end

#partition(name) ⇒ Object



19
20
21
# File 'lib/arver/host.rb', line 19

def partition(name)
  child(name)
end

#run_action(action) ⇒ Object



74
75
76
77
78
# File 'lib/arver/host.rb', line 74

def run_action( action )
  action.pre_host( self )
  super
  action.post_host( self )
end

#to_yamlObject



44
45
46
47
48
49
50
51
# File 'lib/arver/host.rb', line 44

def to_yaml
  yaml = ""
  yaml += "'address': '"+@address+"'\n" unless @address.nil?
  yaml += "'port': '"+@port+"'\n" unless @port.nil?
  yaml += "'username': '"+@username+"'\n" unless @username.nil?
  yaml += script_hooks_to_yaml
  yaml += super
end