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



151
152
153
# File 'lib/dop_common/node.rb', line 151

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

#credentialsObject



175
176
177
# File 'lib/dop_common/node.rb', line 175

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

#data_disksObject



183
184
185
# File 'lib/dop_common/node.rb', line 183

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

#digitsObject



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

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

#dnsObject



179
180
181
# File 'lib/dop_common/node.rb', line 179

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

#domainnameObject



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

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

#flavorObject



147
148
149
# File 'lib/dop_common/node.rb', line 147

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

#fqdnObject



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

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

#full_clone?Boolean Also known as: full_clone

Returns:

  • (Boolean)


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

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

#hooksObject



187
188
189
# File 'lib/dop_common/node.rb', line 187

def hooks
  @parsed_hooks
end

#hostnameObject



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

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

#imageObject



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

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

#inflatable?Boolean

Check if the node describes a series of nodes.

Returns:

  • (Boolean)


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

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

#inflateObject

Create and return all the nodes in the series



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

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



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

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

#infrastructure_propertiesObject



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

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

#interfacesObject



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

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

#memoryObject



155
156
157
# File 'lib/dop_common/node.rb', line 155

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

#organization_nameObject



171
172
173
# File 'lib/dop_common/node.rb', line 171

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

#product_idObject



167
168
169
# File 'lib/dop_common/node.rb', line 167

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

#rangeObject



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

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

#storageObject



159
160
161
# File 'lib/dop_common/node.rb', line 159

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

#timezoneObject



163
164
165
# File 'lib/dop_common/node.rb', line 163

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
# 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('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