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, LayoutName, Networking, 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, :layout_name, :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.



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

def initialize(attributes = {}, options = {})
  super({ amqp_provider: AmqpProvider::RABBITMQ,
          layout_name:   LayoutName::NON_HA,
          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(:name       => self.layout_name,
                             :networking => self.networking).first
end

Class Method Details

.available_locksObject



214
215
216
# File 'app/models/staypuft/deployment.rb', line 214

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



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

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



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

def self.param_scope
  'deployment'
end

Instance Method Details

#ceph_hostgroupObject



281
282
283
284
285
286
# File 'app/models/staypuft/deployment.rb', line 281

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

#controller_hostgroupObject



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

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



296
297
298
# File 'app/models/staypuft/deployment.rb', line 296

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

#deployed?Boolean

Returns:

  • (Boolean)


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

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



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

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

#form_complete?Boolean

Returns:

  • (Boolean)


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

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

#form_step_is_configuration?Boolean

Returns:

  • (Boolean)


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

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

#form_step_is_past_configuration?Boolean

Returns:

  • (Boolean)


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

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

#ha?Boolean

Returns:

  • (Boolean)


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

def ha?
  self.layout_name == LayoutName::HA
end

#has_custom_repos?Boolean

Returns:

  • (Boolean)


292
293
294
# File 'app/models/staypuft/deployment.rb', line 292

def has_custom_repos?
  self.custom_repos.present?
end

#hide_ceph_notification?Boolean

Returns:

  • (Boolean)


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

def hide_ceph_notification?
  ceph_hostgroup.hosts.empty?
end

#horizon_urlObject



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

def horizon_url
  if ha?
    "http://#{network_query.get_vip(:horizon_public_vip)}"
  else
    network_query.controller_ips(Staypuft::SubnetType::PUBLIC_API).empty? ? nil : "http://#{network_query.controller_ip(Staypuft::SubnetType::PUBLIC_API)}"
  end
end

#in_progress?Boolean

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

Returns:

  • (Boolean)


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

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

#in_progress_hosts(hostgroup) ⇒ Object

Returns a list of hosts that are currently being deployed.



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

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

#network_queryObject



288
289
290
# File 'app/models/staypuft/deployment.rb', line 288

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

#neutron_networking?Boolean

Returns:

  • (Boolean)


254
255
256
# File 'app/models/staypuft/deployment.rb', line 254

def neutron_networking?
  networking == Networking::NEUTRON
end

#non_ha?Boolean

Returns:

  • (Boolean)


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

def non_ha?
  self.layout_name == LayoutName::NON_HA
end

#nova_networking?Boolean

Returns:

  • (Boolean)


250
251
252
# File 'app/models/staypuft/deployment.rb', line 250

def nova_networking?
  networking == Networking::NOVA
end

#progressObject

Helper method for getting the progress of this deployment



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

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

#progress_summaryObject



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

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

#services_hostgroup_mapObject



218
219
220
221
222
223
224
# File 'app/models/staypuft/deployment.rb', line 218

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.



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

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

#unassigned_pxe_default_subnet_typesObject



277
278
279
# File 'app/models/staypuft/deployment.rb', line 277

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

#unassigned_subnet_typesObject



273
274
275
# File 'app/models/staypuft/deployment.rb', line 273

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