Class: Staypuft::Deployment

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
AttributeParamStorage
Defined in:
app/models/staypuft/deployment.rb

Defined Under Namespace

Modules: AmqpProvider, AttributeParamStorage, IpAddressValidator, IpCheck, Networking, NfsUriValidator, Platform, VlanRangeValuesValidator Classes: AbstractParamScope, CephService, CinderService, GlanceService, Jail, NeutronService, NovaService, Passwords

Constant Summary collapse

STEP_INACTIVE =

Form step states

:inactive
STEP_SETTINGS =
:settings
STEP_CONFIGURATION =
:configuration
STEP_COMPLETE =
:complete
STEP_OVERVIEW =
:overview
STEP_NETWORKING =
:networking
NEW_NAME_PREFIX =
'uninitialized_'
EXPORT_PARAMS =

supporting import/export

[:amqp_provider, :networking, :platform]
EXPORT_SERVICES =
[:nova, :neutron, :glance, :cinder, :passwords, :ceph]
SCOPES =
[[:nova, :@nova_service, NovaService],
[:neutron, :@neutron_service, NeutronService],
[:glance, :@glance_service, GlanceService],
[:cinder, :@cinder_service, CinderService],
[:passwords, :@passwords, Passwords],
[:ceph, :@ceph, CephService]]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeParamStorage

param_attr, param_attr_array, param_scope

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ Deployment

Returns a new instance of Deployment.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/staypuft/deployment.rb', line 84

def initialize(attributes = {}, options = {})
  super({ amqp_provider: AmqpProvider::RABBITMQ,
          networking:    Networking::NEUTRON,
          platform:      Platform::RHEL7 }.merge(attributes),
        options)

  self.hostgroup = Hostgroup.new(name: name, parent: Hostgroup.get_base_hostgroup)

  self.nova.set_defaults
  self.neutron.set_defaults
  self.glance.set_defaults
  self.cinder.set_defaults
  self.passwords.set_defaults
  self.ceph.set_defaults
  self.layout = Layout.where(:networking => self.networking).first
end

Class Method Details

.available_locksObject



205
206
207
# File 'app/models/staypuft/deployment.rb', line 205

def self.available_locks
  [:deploy]
end

.find_by_foreman_task(foreman_task) ⇒ Object

Helper method for looking up a Deployment based on a foreman task



104
105
106
107
108
109
110
111
112
113
114
# File 'app/models/staypuft/deployment.rb', line 104

def self.find_by_foreman_task(foreman_task)
  task = ForemanTasks::Lock.where(task_id: foreman_task.id,
                                                 name: :deploy,
                                                 resource_type: 'Staypuft::Deployment').first
  unless task.nil?
    Deployment.find(task.resource_id)
  else
    nil
  end

end

.param_scopeObject



157
158
159
# File 'app/models/staypuft/deployment.rb', line 157

def self.param_scope
  'deployment'
end

Instance Method Details

#build_vips(parameters) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'app/models/staypuft/deployment.rb', line 279

def build_vips(parameters)
  typings = self.subnet_typings
  types = SubnetType.where(:name => parameters.values.uniq).all
  n = 0
  self.deployment_vip_nics.includes(:vip_nic).where("nics.tag not in (?)", parameters.keys).destroy_all
  parameters.each do |parameter, subnet_type|
    type = types.find { |t| t.name == subnet_type }
    raise "unable to find subnet type with name #{subnet_type}" if type.nil?

    subnet = typings.where(:subnet_type_id => type.id).first.subnet
    raise "unable to find subnet assigned to type #{subnet_type} in deployment #{self.name}" if subnet.nil?

    # for identifier, use pre-pended "vip_" rather than appended "_vip" to group interface names
    vip_identifier = "vip_" + parameter.to_s.chomp("_vip")
    deployment_vip_nic = self.deployment_vip_nics.includes(:vip_nic).where(:nics => {:identifier => vip_identifier}).first
    interface = deployment_vip_nic.vip_nic if deployment_vip_nic
    if deployment_vip_nic.nil?
      interface = VipNic.new(:type => 'Staypuft::VipNic', :identifier => vip_identifier)
    end
    interface.subnet = subnet
    interface.managed = false
    mac_str = self.id.to_s(16).rjust(10,'0')
    [8,6,4,2].each {|i| mac_str.insert(i,":") }
    interface.mac = "#{mac_str}:#{n.to_s(16).rjust(2, '0')}"
    interface.tag = parameter
    interface.save!
    if deployment_vip_nic.nil?
      self.deployment_vip_nics.create(:vip_nic=> interface)
    end
    n += 1
  end
end

#ceph_hostgroupObject



260
261
262
263
264
265
# File 'app/models/staypuft/deployment.rb', line 260

def ceph_hostgroup
  Hostgroup.includes(:deployment_role_hostgroup).
    where(DeploymentRoleHostgroup.table_name => { deployment_id: self,
                                                  role_id:       Staypuft::Role.cephosd }).
    first
end

#controller_hostgroupObject



245
246
247
248
249
250
# File 'app/models/staypuft/deployment.rb', line 245

def controller_hostgroup
  Hostgroup.includes(:deployment_role_hostgroup).
    where(DeploymentRoleHostgroup.table_name => { deployment_id: self,
                                                  role_id:       Staypuft::Role.controller }).
    first
end

#custom_repos_pathsObject



275
276
277
# File 'app/models/staypuft/deployment.rb', line 275

def custom_repos_paths
  self.custom_repos.split("\n")
end

#deployed?Boolean

Returns:

  • (Boolean)


217
218
219
# File 'app/models/staypuft/deployment.rb', line 217

def deployed?
  self.hosts.any?(&:open_stack_deployed?)
end

#deployed_hosts(hostgroup, errors = false) ⇒ Object

Returns all deployed hosts with no errors (default behaviour). Set errors=true to return all deployed hosts that have errors



138
139
140
# File 'app/models/staypuft/deployment.rb', line 138

def deployed_hosts(hostgroup, errors=false)
  in_progress? ? {} : hostgroup.openstack_hosts(errors)
end

#form_complete?Boolean

Returns:

  • (Boolean)


229
230
231
# File 'app/models/staypuft/deployment.rb', line 229

def form_complete?
  self.form_step.to_sym == Deployment::STEP_COMPLETE
end

#form_step_is_configuration?Boolean

Returns:

  • (Boolean)


221
222
223
# File 'app/models/staypuft/deployment.rb', line 221

def form_step_is_configuration?
  self.form_step.to_sym == Deployment::STEP_CONFIGURATION
end

#form_step_is_past_configuration?Boolean

Returns:

  • (Boolean)


225
226
227
# File 'app/models/staypuft/deployment.rb', line 225

def form_step_is_past_configuration?
  self.form_step_is_configuration? || self.form_complete?
end

#has_custom_repos?Boolean

Returns:

  • (Boolean)


271
272
273
# File 'app/models/staypuft/deployment.rb', line 271

def has_custom_repos?
  self.custom_repos.present?
end

#hide_ceph_notification?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'app/models/staypuft/deployment.rb', line 126

def hide_ceph_notification?
  ceph_hostgroup.hosts.empty?
end

#horizon_urlObject



241
242
243
# File 'app/models/staypuft/deployment.rb', line 241

def horizon_url
  "http://#{network_query.get_vip(:horizon_public_vip)}"
end

#in_progress?Boolean

Helper method for checking whether this deployment is in progress or not.

Returns:

  • (Boolean)


122
123
124
# File 'app/models/staypuft/deployment.rb', line 122

def in_progress?
  ForemanTasks::Lock.locked? self, nil
end

#in_progress_hosts(hostgroup) ⇒ Object

Returns a list of hosts that are currently being deployed.



117
118
119
# File 'app/models/staypuft/deployment.rb', line 117

def in_progress_hosts(hostgroup)
  return in_progress? ? hostgroup.openstack_hosts : {}
end

#network_queryObject



267
268
269
# File 'app/models/staypuft/deployment.rb', line 267

def network_query
  @network_query || NetworkQuery.new(self)
end

#neutron_networking?Boolean

Returns:

  • (Boolean)


237
238
239
# File 'app/models/staypuft/deployment.rb', line 237

def neutron_networking?
  networking == Networking::NEUTRON
end

#nova_networking?Boolean

Returns:

  • (Boolean)


233
234
235
# File 'app/models/staypuft/deployment.rb', line 233

def nova_networking?
  networking == Networking::NOVA
end

#progressObject

Helper method for getting the progress of this deployment



147
148
149
150
151
152
153
154
155
# File 'app/models/staypuft/deployment.rb', line 147

def progress
  if self.in_progress?
    (self.task.progress * 100).round(1)
  elsif self.deployed?
    100
  else
    0
  end
end

#progress_summaryObject



142
143
144
# File 'app/models/staypuft/deployment.rb', line 142

def progress_summary
  self.in_progress? ? self.task.humanized[:output] : nil
end

#services_hostgroup_mapObject



209
210
211
212
213
214
215
# File 'app/models/staypuft/deployment.rb', line 209

def services_hostgroup_map
  deployment_role_hostgroups.map do |deployment_role_hostgroup|
    deployment_role_hostgroup.services.reduce({}) do |h, s|
      h.update s => deployment_role_hostgroup.hostgroup
    end
  end.reduce(&:merge)
end

#taskObject

Helper method for getting the in progress foreman task for this deployment.



132
133
134
# File 'app/models/staypuft/deployment.rb', line 132

def task
  in_progress? ? ForemanTasks::Lock.colliding_locks(self, nil).first.task : nil
end

#unassigned_pxe_default_subnet_typesObject



256
257
258
# File 'app/models/staypuft/deployment.rb', line 256

def unassigned_pxe_default_subnet_types
  self.layout.subnet_types.pxe_defaults - self.subnet_types
end

#unassigned_subnet_typesObject



252
253
254
# File 'app/models/staypuft/deployment.rb', line 252

def unassigned_subnet_types
  self.layout.subnet_types - self.subnet_types
end