Class: Miasma::Models::Orchestration::Stack

Inherits:
Types::Model show all
Includes:
Bogo::Memoization
Defined in:
lib/miasma/models/orchestration/stack.rb,
lib/miasma/models/orchestration/plan.rb,
lib/miasma/models/orchestration/event.rb,
lib/miasma/models/orchestration/plans.rb,
lib/miasma/models/orchestration/events.rb,
lib/miasma/models/orchestration/resource.rb,
lib/miasma/models/orchestration/resources.rb

Overview

Abstract server

Defined Under Namespace

Classes: Event, Events, Output, Plan, Plans, Resource, Resources

Constant Summary collapse

VALID_PLAN_STATES =

Stack states which are valid to execute update plan

[
  :create_complete, :update_complete, :update_failed,
  :rollback_complete, :rollback_failed, :unknown,
]

Instance Attribute Summary

Attributes inherited from Types::Model

#api

Instance Method Summary collapse

Methods inherited from Types::Model

#destroy, from_json, #id?, #initialize, #persisted?

Methods included from Utils::ApiMethoding

#api_method_for

Methods inherited from Types::Data

from_json, #from_json, #initialize, #to_json

Constructor Details

This class inherits a constructor from Miasma::Types::Model

Instance Method Details

#eventsEvents

Returns:



139
140
141
142
143
# File 'lib/miasma/models/orchestration/stack.rb', line 139

def events
  memoize(:events) do
    Events.new(self)
  end
end

#load_data(args = {}) ⇒ Object

Overload the loader so we can extract resources, events, and outputs



66
67
68
69
70
71
72
73
74
75
# File 'lib/miasma/models/orchestration/stack.rb', line 66

def load_data(args = {})
  args = args.to_smash
  @resources = (args.delete(:resources) || []).each do |r|
    Resource.new(r)
  end
  @events = (args.delete(:events) || []).each do |e|
    Event.new(e)
  end
  super args
end

#plan_destroyself

Delete the current plan

Returns:

  • (self)


114
115
116
117
118
119
120
121
122
# File 'lib/miasma/models/orchestration/stack.rb', line 114

def plan_destroy
  if dirty?(:plan)
    perform_plan_destroy
  else
    raise Miasma::Error::OrchestrationError::InvalidStackPlan.new(
      "This stack instance does not have a generated plan"
    )
  end
end

#plan_executeself

Execute current execute

Returns:

  • (self)


101
102
103
104
105
106
107
108
109
# File 'lib/miasma/models/orchestration/stack.rb', line 101

def plan_execute
  if dirty?(:plan)
    perform_plan_execute
  else
    raise Miasma::Error::OrchestrationError::InvalidStackPlan.new(
      "This stack instance does not have a generated plan"
    )
  end
end

#plan_generatePlan

Create a new stack plan

Returns:



88
89
90
91
92
93
94
95
96
# File 'lib/miasma/models/orchestration/stack.rb', line 88

def plan_generate
  if plan
    raise Miasma::Error::OrchestrationError::StackPlanExists.new(
      "Plan already exists for this stack"
    )
  else
    perform_plan
  end
end

#plansPlans

Returns:



146
147
148
149
150
# File 'lib/miasma/models/orchestration/stack.rb', line 146

def plans
  memoize(:plans) do
    Plans.new(self)
  end
end

#reloadself

Override to scrub custom caches

Returns:

  • (self)


127
128
129
130
131
132
133
134
135
136
# File 'lib/miasma/models/orchestration/stack.rb', line 127

def reload
  clear_memoizations!
  remove = data.keys.find_all do |k|
    ![:id, :name].include?(k.to_sym)
  end
  remove.each do |k|
    data.delete(k)
  end
  super
end

#resourcesResources

Returns:



153
154
155
156
157
# File 'lib/miasma/models/orchestration/stack.rb', line 153

def resources
  memoize(:resources) do
    Resources.new(self)
  end
end

#saveObject

Always perform save. Remove dirty check provided by default.



161
162
163
# File 'lib/miasma/models/orchestration/stack.rb', line 161

def save
  perform_save
end

#validateTrueClass

Validate the stack template

Returns:

  • (TrueClass)


81
82
83
# File 'lib/miasma/models/orchestration/stack.rb', line 81

def validate
  perform_template_validate
end