Class: DopCommon::Node

Inherits:
Object
  • Object
show all
Includes:
HashParser, Config, Utils, Validator
Defined in:
lib/dop_common/node.rb,
lib/dop_common/node/config.rb

Defined Under Namespace

Modules: Config

Constant Summary collapse

DEFAULT_DIGITS =
2
VALID_FLAVOR_TYPES =
{
  :tiny     => {
    :cores    => 1,
    :memory   => 536870912,
    :storage  => 1073741824
  },
  :small    => {
    :cores    => 1,
    :memory   => 2147483648,
    :storage  => 10737418240
  },
  :medium   => {
    :cores    => 2,
    :memory   => 4294967296,
    :storage  => 10737418240
  },
  :large    => {
    :cores    => 4,
    :memory   => 8589934592,
    :storage  => 10737418240
  },
  :xlarge   => {
    :cores    => 8,
    :memory   => 17179869184,
    :storage  => 10737418240
  }
}
DEFAULT_OPENSTACK_FLAVOR =
'm1.medium'
DEFAULT_CORES =
VALID_FLAVOR_TYPES[:medium][:cores]
DEFAULT_MEMORY =
VALID_FLAVOR_TYPES[:medium][:memory]
DEFAULT_STORAGE =
VALID_FLAVOR_TYPES[:medium][:storage]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#config, #config_includes?, #fact, #has_config?, #has_fact?, #has_name?, #has_role?, #role

Methods included from Utils

sanitize_env

Methods included from HashParser

deep_symbolize_keys, hash_of_pattern_lists_valid?, is_valid_regexp?, key_aliases, load_content, load_content_valid?, parse_hash_of_pattern_lists, parse_pattern_list, pattern_list_valid?, represents_regexp?, symbolize_keys

Methods included from Validator

#log_validation_method, #set_not_valid, #try_validate_obj, #valid?

Constructor Details

#initialize(name, hash, parent = {}) ⇒ Node

Returns a new instance of Node.



52
53
54
55
56
57
58
59
# File 'lib/dop_common/node.rb', line 52

def initialize(name, hash, parent={})
  @name = name
  @hash = symbolize_keys(hash)
  @parsed_infrastructures = parent[:parsed_infrastructures]
  @parsed_credentials     = parent[:parsed_credentials]
  @parsed_hooks           = parent[:parsed_hooks]
  @parsed_configuration   = parent[:parsed_configuration]
end

Instance Attribute Details

#nameObject Also known as: nodename

Returns the value of attribute name.



13
14
15
# File 'lib/dop_common/node.rb', line 13

def name
  @name
end

Instance Method Details

#coresObject



157
158
159
# File 'lib/dop_common/node.rb', line 157

def cores
  @cores ||= cores_valid? ? create_cores : nil
end

#credentialsObject



181
182
183
# File 'lib/dop_common/node.rb', line 181

def credentials
  @credentials ||= credentials_valid? ? create_credentials : []
end

#data_disksObject



189
190
191
# File 'lib/dop_common/node.rb', line 189

def data_disks
  @data_disks ||= data_disks_valid? ? create_data_disks : []
end

#digitsObject



90
91
92
93
# File 'lib/dop_common/node.rb', line 90

def digits
  @digits ||= digits_valid? ?
    @hash[:digits] : DEFAULT_DIGITS
end

#dnsObject



185
186
187
# File 'lib/dop_common/node.rb', line 185

def dns
  @dns ||= dns_valid? ? create_dns : nil
end

#domainnameObject



122
123
124
# File 'lib/dop_common/node.rb', line 122

def domainname
  @domainname ||= fqdn.split('.', 2).last
end

#flavorObject



153
154
155
# File 'lib/dop_common/node.rb', line 153

def flavor
  @flavor ||= flavor_valid? ? create_flavor : nil
end

#fqdnObject



114
115
116
# File 'lib/dop_common/node.rb', line 114

def fqdn
  @fqdn ||= fqdn_valid? ? create_fqdn : nil
end

#full_clone?Boolean Also known as: full_clone

Returns:

  • (Boolean)


139
140
141
# File 'lib/dop_common/node.rb', line 139

def full_clone?
  @full_clone ||= full_clone_valid? ? @hash[:full_clone] : true
end

#hooksObject



193
194
195
# File 'lib/dop_common/node.rb', line 193

def hooks
  @parsed_hooks
end

#hostnameObject



118
119
120
# File 'lib/dop_common/node.rb', line 118

def hostname
  @hostname ||= fqdn.split('.').first
end

#imageObject



135
136
137
# File 'lib/dop_common/node.rb', line 135

def image
  @image ||= image_valid? ? @hash[:image] : nil
end

#inflatable?Boolean

Check if the node describes a series of nodes.

Returns:

  • (Boolean)


101
102
103
# File 'lib/dop_common/node.rb', line 101

def inflatable?
  @name.include?('{i}')
end

#inflateObject

Create and return all the nodes in the series



106
107
108
109
110
111
112
# File 'lib/dop_common/node.rb', line 106

def inflate
  range.map do |node_number|
    @node_copy = clone
    @node_copy.name = @name.gsub('{i}', "%0#{digits}d" % node_number)
    @node_copy
  end
end

#infrastructureObject



126
127
128
# File 'lib/dop_common/node.rb', line 126

def infrastructure
  @infrastructure ||= infrastructure_valid? ? create_infrastructure : nil
end

#infrastructure_propertiesObject



130
131
132
133
# File 'lib/dop_common/node.rb', line 130

def infrastructure_properties
  @infrastructure_properties ||= infrastructure_properties_valid? ?
    create_infrastructure_properties : {}
end

#interfacesObject



149
150
151
# File 'lib/dop_common/node.rb', line 149

def interfaces
  @interfaces ||= interfaces_valid? ? create_interfaces : []
end

#memoryObject



161
162
163
# File 'lib/dop_common/node.rb', line 161

def memory
  @memory ||= memory_valid? ? create_memory : nil
end

#organization_nameObject



177
178
179
# File 'lib/dop_common/node.rb', line 177

def organization_name
  @organization_name ||= organization_name_valid? ? @hash[:organization_name] : nil
end

#product_idObject



173
174
175
# File 'lib/dop_common/node.rb', line 173

def product_id
  @product_id ||= product_id_valid? ? @hash[:product_id] : nil
end

#rangeObject



95
96
97
98
# File 'lib/dop_common/node.rb', line 95

def range
  @range ||= range_valid? ?
    Range.new(*@hash[:range].scan(/\d+/)) : nil
end

#storageObject



165
166
167
# File 'lib/dop_common/node.rb', line 165

def storage
  @storage ||= storage_valid? ? create_storage : nil
end

#thin_clone?Boolean Also known as: thin_clone

Returns:

  • (Boolean)


144
145
146
# File 'lib/dop_common/node.rb', line 144

def thin_clone?
  @thin_clone ||= thin_clone_valid? ? @hash[:thin_clone] : nil
end

#timezoneObject



169
170
171
# File 'lib/dop_common/node.rb', line 169

def timezone
  @timezone ||= timezone_valid? ? @hash[:timezone] : nil
end

#validateObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dop_common/node.rb', line 61

def validate
  log_validation_method('digits_valid?')
  log_validation_method('range_valid?')
  log_validation_method('fqdn_valid?')
  log_validation_method('infrastructure_valid?')
  log_validation_method('infrastructure_properties_valid?')
  log_validation_method('image_valid?')
  log_validation_method('full_clone_valid?')
  log_validation_method('thin_clone_valid?')
  log_validation_method('interfaces_valid?')
  log_validation_method('flavor_valid?')
  log_validation_method('cores_valid?')
  log_validation_method('memory_valid?')
  log_validation_method('storage_valid?')
  log_validation_method('timezone_valid?')
  log_validation_method('product_id_valid?')
  log_validation_method('organization_name_valid?')
  log_validation_method('credentials_valid?')
  log_validation_method('dns_valid?')
  log_validation_method('data_disks_valid?')
  try_validate_obj("Node #{@name}: Can't validate the interfaces part because of a previous error"){interfaces}
  try_validate_obj("Node #{@name}: Can't validate the infrastructure_properties part because of a previous error"){infrastructure_properties}
  try_validate_obj("Node #{@name}: Can't validate the dns part because of a previous error"){dns}
  try_validate_obj("Node #{@name}: Can't validate data_disks part because of a previous error"){data_disks}
  # Memory and storage may be to nil.
  try_validate_obj("Node #{@name}: Can't validate the memory part because of a previous error"){memory} unless @hash[:memory].nil?
  try_validate_obj("Node #{@name}: Can't validate storage part because of a previous error"){storage} unless @hash[:storage].nil?
end