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



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

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

#credentialsObject



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

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

#data_disksObject



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

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

#digitsObject



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

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

#dnsObject



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

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

#domainnameObject



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

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

#flavorObject



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

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

#fqdnObject



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

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

#full_clone?Boolean Also known as: full_clone

Returns:

  • (Boolean)


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

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

#hooksObject



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

def hooks
  @parsed_hooks
end

#hostnameObject



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

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

#imageObject



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

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

#inflatable?Boolean

Check if the node describes a series of nodes.

Returns:

  • (Boolean)


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

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

#inflateObject

Create and return all the nodes in the series



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

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



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

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

#infrastructure_propertiesObject



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

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

#interfacesObject



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

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

#memoryObject



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

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

#organization_nameObject



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

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

#product_idObject



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

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

#rangeObject



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

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

#storageObject



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

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

#tagsObject



198
199
200
# File 'lib/dop_common/node.rb', line 198

def tags
  @tags ||= tags_valid? ? create_tags : nil
end

#thin_clone?Boolean Also known as: thin_clone

Returns:

  • (Boolean)


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

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

#timezoneObject



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

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
89
# 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?')
  log_validation_method('tags_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