File: stack.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (128 lines) | stat: -rw-r--r-- 4,188 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
require 'fog/openstack/models/model'

module Fog
  module OpenStack
    class Orchestration
      class Stack < Fog::OpenStack::Model
        identity :id

        %w(capabilities description disable_rollback links notification_topics outputs parameters
           stack_name stack_status stack_status_reason template_description timeout_mins parent
           creation_time updated_time stack_user_project_id stack_owner files).each do |a|
          attribute a.to_sym
        end

        def save(options = {})
          if persisted?
            stack_default_options = default_options
            if (options.key?(:template_url))
              stack_default_options.delete(:template)
            end
            service.update_stack(self, stack_default_options.merge(options)).body['stack']
          else
            service.stacks.create(default_options.merge(options))
          end
        end

        # Deprecated
        def create
          Fog::Logger.deprecation("#create is deprecated, use #save(options) instead [light_black](#{caller.first})[/]")
          requires :stack_name
          service.stacks.create(default_options)
        end

        # Deprecated
        def update
          Fog::Logger.deprecation("#update is deprecated, use #save(options) instead [light_black](#{caller.first})[/]")
          requires :stack_name
          service.update_stack(self, default_options).body['stack']
        end

        def patch(options = {})
          requires :stack_name
          service.patch_stack(self, options).body['stack']
        end

        def delete
          service.delete_stack(self)
        end
        alias destroy delete

        def details
          @details ||= service.stacks.get(stack_name, id)
        end

        def resources(options = {})
          @resources ||= service.resources.all({:stack => self}.merge(options))
        end

        def events(options = {})
          @events ||= service.events.all(self, options)
        end

        def template
          @template ||= service.templates.get(self)
        end

        def abandon
          service.abandon_stack(self)
        end

        def cancel_update
          service.cancel_update(self)
        end

        # Deprecated
        def template_url
          Fog::Logger.deprecation("#template_url is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]")
          @template_url
        end

        # Deprecated
        def template_url=(url)
          Fog::Logger.deprecation("#template_url= is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]")
          @template_url = url
        end

        # Deprecated
        def template=(content)
          Fog::Logger.deprecation("#template=(content) is deprecated, use it in options for #save(options) instead [light_black](#{caller.first})[/]")
          @template = content
        end

        # Deprecated
        def timeout_in_minutes
          Fog::Logger.deprecation("#timeout_in_minutes is deprecated, set timeout_mins in options for save(options) instead [light_black](#{caller.first})[/]")
          timeout_mins
        end

        # Deprecated
        def timeout_in_minutes=(minutes)
          Fog::Logger.deprecation("#timeout_in_minutes=(minutes) is deprecated, set timeout_mins in options for save(options) instead [light_black](#{caller.first})[/]")
          timeout_mins = minutes
        end

        # build options to create or update stack
        def default_options
          template_content =
            if template && template.kind_of?(Fog::OpenStack::Orchestration::Template)
              template.content
            else
              template
            end

          options = {
            :stack_name       => stack_name,
            :disable_rollback => disable_rollback,
            :timeout_mins     => timeout_mins
          }
          options[:template] = template_content if template_content
          options[:template_url] = @template_url if @template_url
          options[:files] = @files if @files
          options
        end
        private :default_options
      end
    end
  end
end