Class: Kumogata2::Client
- Inherits:
-
Object
- Object
- Kumogata2::Client
- Includes:
- Logger::Helper
- Defined in:
- lib/kumogata2/client.rb
Instance Method Summary collapse
- #convert(path_or_url) ⇒ Object
- #create(path_or_url, stack_name = nil) ⇒ Object
- #delete(stack_name) ⇒ Object
- #deploy(path_or_url, stack_name = nil) ⇒ Object
- #describe(stack_name) ⇒ Object
- #diff(path_or_url1, path_or_url2) ⇒ Object
- #dry_run(path_or_url, stack_name = nil) ⇒ Object
- #export(stack_name) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #list(stack_name = nil) ⇒ Object
- #show_events(stack_name) ⇒ Object
- #show_outputs(stack_name) ⇒ Object
- #show_resources(stack_name) ⇒ Object
- #template_summary(path_or_url) ⇒ Object
- #update(path_or_url, stack_name) ⇒ Object
- #validate(path_or_url) ⇒ Object
Methods included from Logger::Helper
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 |
# File 'lib/kumogata2/client.rb', line 4 def initialize() @options = .kind_of?(Hashie::Mash) ? : Hashie::Mash.new() @client = nil @resource = nil @plugin_by_ext = {} end |
Instance Method Details
#convert(path_or_url) ⇒ Object
83 84 85 86 |
# File 'lib/kumogata2/client.rb', line 83 def convert(path_or_url) template = open_template(path_or_url) convert0(template) end |
#create(path_or_url, stack_name = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kumogata2/client.rb', line 18 def create(path_or_url, stack_name = nil) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) if stack_name template = open_template(path_or_url) update_deletion_policy(template, delete_stack: !stack_name) outputs = create_stack(template, stack_name) unless @options.detach? post_process(path_or_url, outputs) end end |
#delete(stack_name) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/kumogata2/client.rb', line 44 def delete(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) get_resource.stack(stack_name).stack_status if @options.force? or agree("Are you sure you want to delete `#{stack_name}`? ".yellow) delete_stack(stack_name) end end |
#deploy(path_or_url, stack_name = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/kumogata2/client.rb', line 54 def deploy(path_or_url, stack_name = nil) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) if stack_name template = open_template(path_or_url) update_deletion_policy(template, delete_stack: !stack_name) change_set = create_change_set(template, stack_name) execute_change_set(change_set) end |
#describe(stack_name) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/kumogata2/client.rb', line 11 def describe(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) stack = describe_stack(stack_name) JSON.pretty_generate(stack).colorize_as(:json) end |
#diff(path_or_url1, path_or_url2) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/kumogata2/client.rb', line 88 def diff(path_or_url1, path_or_url2) templates = [path_or_url1, path_or_url2].map do |path_or_url| template = nil if path_or_url =~ %r|\Astack://(.*)| stack_name = $1 || '' validate_stack_name(stack_name) template = export_template(stack_name) else template = open_template(path_or_url) end template = Kumogata2::Utils.stringify(template) JSON.pretty_generate(template) end diff_opts = @options.ignore_all_space? ? '-uw' : '-u' opts = {:include_diff_info => true, :diff => diff_opts} diff = Diffy::Diff.new(*templates, opts).to_s diff.sub(/^(\e\[\d+m)?\-\-\-(\s+)(\S+)/m) { "#{$1}---#{$2}#{path_or_url1}"} .sub(/^(\e\[\d+m)?\+\+\+(\s+)(\S+)/m) { "#{$1}+++#{$2}#{path_or_url2}"} end |
#dry_run(path_or_url, stack_name = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/kumogata2/client.rb', line 112 def dry_run(path_or_url, stack_name = nil) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) if stack_name template = open_template(path_or_url) update_deletion_policy(template, delete_stack: !stack_name) changes = show_change_set(template, stack_name) changes = JSON.pretty_generate(changes).colorize_as(:json) if changes changes end |
#export(stack_name) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/kumogata2/client.rb', line 76 def export(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) template = export_template(stack_name) convert0(template) end |
#list(stack_name = nil) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/kumogata2/client.rb', line 69 def list(stack_name = nil) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) if stack_name stacks = describe_stacks(stack_name) JSON.pretty_generate(stacks).colorize_as(:json) end |
#show_events(stack_name) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/kumogata2/client.rb', line 122 def show_events(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) events = describe_events(stack_name) JSON.pretty_generate(events).colorize_as(:json) end |
#show_outputs(stack_name) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/kumogata2/client.rb', line 129 def show_outputs(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) outputs = describe_outputs(stack_name) JSON.pretty_generate(outputs).colorize_as(:json) end |
#show_resources(stack_name) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/kumogata2/client.rb', line 136 def show_resources(stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) resources = describe_resources(stack_name) JSON.pretty_generate(resources).colorize_as(:json) end |
#template_summary(path_or_url) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/kumogata2/client.rb', line 143 def template_summary(path_or_url) params = {} if path_or_url =~ %r|\Astack://(.*)| stack_name = $1 || '' validate_stack_name(stack_name) params[:stack_name] = stack_name else template = open_template(path_or_url) params[:template_body] = JSON.pretty_generate(template) end summary = describe_template_summary(params) JSON.pretty_generate(summary).colorize_as(:json) end |
#update(path_or_url, stack_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kumogata2/client.rb', line 31 def update(path_or_url, stack_name) stack_name = normalize_stack_name(stack_name) validate_stack_name(stack_name) template = open_template(path_or_url) update_deletion_policy(template, update_metadate: true) outputs = update_stack(template, stack_name) unless @options.detach? post_process(path_or_url, outputs) end end |
#validate(path_or_url) ⇒ Object
64 65 66 67 |
# File 'lib/kumogata2/client.rb', line 64 def validate(path_or_url) template = open_template(path_or_url) validate_template(template) end |