Class: Kitsune::Kit::Operations::EnsureServer
- Inherits:
-
Object
- Object
- Kitsune::Kit::Operations::EnsureServer
- Defined in:
- lib/kitsune/kit/operations/ensure_server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #apply(change) ⇒ Object
-
#initialize(config:, provider:, state_store:, maximum_timeout: nil) ⇒ EnsureServer
constructor
A new instance of EnsureServer.
- #plan ⇒ Object
- #resource ⇒ Object
- #state_key ⇒ Object
Constructor Details
#initialize(config:, provider:, state_store:, maximum_timeout: nil) ⇒ EnsureServer
Returns a new instance of EnsureServer.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 12 def initialize(config:, provider:, state_store:, maximum_timeout: nil) if maximum_timeout && maximum_timeout <= 0 raise Errors::ConfigurationError, "timeout must be greater than zero" end @config = config @provider = provider @state_store = state_store @ready_timeout = maximum_timeout || 180 end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 10 def config @config end |
Instance Method Details
#apply(change) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 40 def apply(change) return current_server(change) unless change.changed? if change.action == "update" raise Errors::UnsafeOperationError.new( "server replacement is required for #{config.server.name}", hint: "Destroy the managed server explicitly, then run apply again.", context: change.details ) end created = @provider.find_server(name: config.server.name, tags: config.server.) || @provider.create_server(spec: desired_spec) record_created(created) ready = @provider.wait_until_ready(id: created.id, timeout: @ready_timeout) record_ready(ready) ready rescue Errors::Error raise rescue StandardError => e raise Errors::ProviderError.new( "server operation failed for #{config.server.name}", context: { cause: e.class.name }, retryable: true ) end |
#plan ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 23 def plan @provider.validate_server_spec!(spec: desired_spec) existing = @provider.find_server(name: config.server.name, tags: config.server.) return create_change unless existing differences = differences_for(existing) return unchanged_change(existing) if differences.empty? Change.new( resource: "server.#{config.server.name}", action: "update", summary: "Server exists with immutable configuration differences", details: { id: existing.id, differences: differences, replacement_required: true }, destructive: true ) end |
#resource ⇒ Object
66 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 66 def resource = "server.#{config.server.name}" |
#state_key ⇒ Object
67 |
# File 'lib/kitsune/kit/operations/ensure_server.rb', line 67 def state_key = "server" |