sakurraform 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4416aa881d34ded8fbd024c7e43b9dd7f0cbfee8
4
- data.tar.gz: c80797a43f85f95c82a0bb0c8c9563a32671c554
3
+ metadata.gz: 2789e5c4f89556a579e74af00b800dcf01b460d9
4
+ data.tar.gz: 66a5d6c506918995fd0ffa11824d3fa90a2b8d1a
5
5
  SHA512:
6
- metadata.gz: d9896cd932be452f615c9009682dbb0b1fc643212e4d2aa28e4f54d2ab66dc2be0f142a679d28742289023a94ef9d39ae6f77e5f3938fef164bb0072e63a59dc
7
- data.tar.gz: 1159a819301a1e0eba877acb40748043d241f56dccf791d58828e3d8034ff9583f124d33f51ca0f91b58abfbf6b662d207b006c0df307b27938114644d3da497
6
+ metadata.gz: 3d53a035d553493257c5a15af8040e1185a7b8b5687c0a5fb3e28bea2420f30beeef1cf22279c995030585122fc72f550d5eb685ef80fa60e83684c2578e30d3
7
+ data.tar.gz: cf28520c2456bd8ef03a4d6b391ae8a835606ed8bb18a4729e04a8644bf83f14a7dca9389d30de09e6dc7837901f8278c2588943d29956774cb3324a666f73be
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG of sakurraform
2
2
 
3
+ ## v0.3.0
4
+
5
+ - Fix: build status crashes if other resources exists.
6
+ - Feature: create plan destroy.
7
+
3
8
  ## v0.2.1
4
9
 
5
10
  - Add Json format for status.
data/README.md CHANGED
@@ -59,6 +59,7 @@ Sakura Base Storage token(optional) ? mytoken
59
59
  $ ./bin/sakurraform plan
60
60
  Commands:
61
61
  sakurraform plan apply # Apply plan
62
+ sakurraform plan destroy # Destroy All Resources
62
63
  sakurraform plan generate # Generate template
63
64
  sakurraform plan help [COMMAND] # Describe subcommands or one specific subcommand
64
65
  ```
@@ -135,6 +136,52 @@ $ ./bin/sakurraform status
135
136
 
136
137
  ```
137
138
 
139
+ #### sakurraform plan destroy
140
+
141
+ Delete all resources of plan and remove state files.
142
+
143
+ ```
144
+ $ sakurraform plan destroy
145
+ Nework resources
146
+ +---------------+----------------------------------------------------+--------------+--------------------+-----------------+
147
+ | name | sakurraform_name | sakura_id | subnets | gateway |
148
+ +---------------+----------------------------------------------------+--------------+--------------------+-----------------+
149
+ | defaultrouter | defaultrouter-34b2ae10-38ed-0133-a63c-38e8563c85ec | 112700768733 | 153.120.161.240/28 | 153.120.161.241 |
150
+ +---------------+----------------------------------------------------+--------------+--------------------+-----------------+
151
+
152
+ Server resources
153
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
154
+ | name | sakurraform_name | sakura_id | ipaddress | status | last_state_changed |
155
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
156
+ | master | master-3e88cfc0-38ed-0133-a63c-38e8563c85ec | 112700768736 | 153.120.161.244 | up | 2015-09-09T15:54:35+09:00 |
157
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
158
+ | minion-1 | minion-1-8e060590-38ed-0133-a63c-38e8563c85ec | 112700768742 | 153.120.161.245 | up | 2015-09-09T15:57:53+09:00 |
159
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
160
+ | minion-2 | minion-2-0420bc90-38ee-0133-a63c-38e8563c85ec | 112700768750 | 153.120.161.246 | up | 2015-09-09T16:01:46+09:00 |
161
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
162
+ | minion-3 | minion-3-8f796470-38ee-0133-a63c-38e8563c85ec | 112700768763 | 153.120.161.247 | up | 2015-09-09T16:05:01+09:00 |
163
+ +----------+-----------------------------------------------+--------------+-----------------+--------+---------------------------+
164
+ This operation removes all resources from Sakura no Cloud.
165
+ Are you sure (Type 'Yes')? Yes
166
+ Send stop to master-3e88cfc0-38ed-0133-a63c-38e8563c85ec
167
+ Waiting master-3e88cfc0-38ed-0133-a63c-38e8563c85ec until down ... (in 15 sec)
168
+ .
169
+ Deleting master-3e88cfc0-38ed-0133-a63c-38e8563c85ec and Disks...
170
+ Send stop to minion-1-8e060590-38ed-0133-a63c-38e8563c85ec
171
+ Waiting minion-1-8e060590-38ed-0133-a63c-38e8563c85ec until down ... (in 15 sec)
172
+ .
173
+ Deleting minion-1-8e060590-38ed-0133-a63c-38e8563c85ec and Disks...
174
+ Send stop to minion-2-0420bc90-38ee-0133-a63c-38e8563c85ec
175
+ Waiting minion-2-0420bc90-38ee-0133-a63c-38e8563c85ec until down ... (in 15 sec)
176
+ .
177
+ Deleting minion-2-0420bc90-38ee-0133-a63c-38e8563c85ec and Disks...
178
+ Send stop to minion-3-8f796470-38ee-0133-a63c-38e8563c85ec
179
+ Waiting minion-3-8f796470-38ee-0133-a63c-38e8563c85ec until down ... (in 15 sec)
180
+ .
181
+ Deleting minion-3-8f796470-38ee-0133-a63c-38e8563c85ec and Disks...
182
+ Deleting Router defaultrouter-34b2ae10-38ed-0133-a63c-38e8563c85ec ...
183
+ ```
184
+
138
185
  ### sakurraform map
139
186
 
140
187
  open map page by browser...
@@ -75,5 +75,68 @@ module SakurraForm
75
75
  end
76
76
  end
77
77
  end
78
+
79
+ desc 'destroy', 'Destroy All Resources'
80
+ def destroy
81
+ ## Show resources before destroy.
82
+ SakurraForm::CLI.new.status
83
+ say("This operation removes all resources from Sakura no Cloud.")
84
+ answer = ask("Are you sure (Type 'Yes')? ")
85
+ exit unless answer == "Yes"
86
+
87
+ ## Destroy Servers
88
+ col_servers = SakurraForm::Collection.new('server')
89
+ col_servers.collection_resources(true)
90
+ compute = Fog::Compute[:sakuracloud]
91
+
92
+ col_servers.resources.each do |sv|
93
+ if sv.remote_state
94
+ # puts sv.remote_state
95
+ say("Send stop to #{sv.resource_id}")
96
+ server = compute.servers.get(sv.remote_state[:id])
97
+ server.stop(true)
98
+ server.reload
99
+
100
+ say("Waiting #{sv.resource_id} until down ... (in 15 sec)")
101
+ 3.times do
102
+ break if server.instance["Status"] == "down"
103
+ sleep 5
104
+ say(".")
105
+ server.reload
106
+ end
107
+
108
+ say("Deleting #{sv.resource_id} and Disks...")
109
+ server.delete(
110
+ true,
111
+ server.disks.map {|d| d["ID"]}
112
+ )
113
+ else
114
+ say("Server #{sv.name} not found.")
115
+ end
116
+ sv.flush_cached_state("server")
117
+ end
118
+
119
+ ## Destroy Network
120
+ col_networks = SakurraForm::Collection.new('network')
121
+ col_networks.collection_resources(true)
122
+ network = Fog::Network[:sakuracloud]
123
+
124
+ col_networks.resources.each do |net|
125
+ if net.remote_state
126
+ # puts net.remote_state
127
+ if net.remote_state[:internet].any?
128
+ say("Deleting Router #{net.resource_id} ...")
129
+ network.delete_router(net.remote_state[:internet]["ID"])
130
+ else
131
+ say("Deleting Switch #{net.resource_id} ...")
132
+ network.delete_switch(net.remote_state[:id])
133
+ end
134
+
135
+ else
136
+ say("Router/Switch #{net.name} not found.")
137
+ end
138
+ net.flush_cached_state("network")
139
+ end
140
+ end
78
141
  end
79
142
  end
@@ -19,7 +19,7 @@ module SakurraForm
19
19
  output["Networks"] = build_state_network(col_network)
20
20
  else
21
21
  Formatador.display_line('[green]Nework resources[/]')
22
- Formatador.display_table(build_state_network(col_network), [:name, :sakurraform_name, :sakura_id, :subnet, :gateway])
22
+ Formatador.display_table(build_state_network(col_network), [:name, :sakurraform_name, :sakura_id, :subnets, :gateway])
23
23
  say()
24
24
  end
25
25
 
@@ -54,8 +54,8 @@ module SakurraForm
54
54
  table_datum[:name] = resource.name
55
55
  table_datum[:sakurraform_name] = resource.resource_id ? resource.resource_id : 'not created'
56
56
  table_datum[:sakura_id] = resource.remote_state ? resource.remote_state[:id] : 'not created'
57
- table_datum[:subnet] = resource.remote_state ? resource.remote_state[:subnets].first['NetworkAddress'] + '/' + resource.remote_state[:subnets].first['NetworkMaskLen'].to_s : 'not created'
58
- table_datum[:gateway] = resource.remote_state ? resource.remote_state[:subnets].first['DefaultRoute'] : 'not created'
57
+ table_datum[:subnets] = resource.remote_state && resource.remote_state[:subnets] ? resource.remote_state[:subnets].first['NetworkAddress'] + '/' + resource.remote_state[:subnets].first['NetworkMaskLen'].to_s : 'not created'
58
+ table_datum[:gateway] = resource.remote_state && resource.remote_state[:subnets] ? resource.remote_state[:subnets].first['DefaultRoute'] : 'not created'
59
59
 
60
60
  table_data << table_datum
61
61
  end
@@ -70,9 +70,9 @@ module SakurraForm
70
70
  table_datum[:name] = resource.name
71
71
  table_datum[:sakurraform_name] = resource.resource_id ? resource.resource_id : 'not created'
72
72
  table_datum[:sakura_id] = resource.remote_state ? resource.remote_state[:id] : 'not created'
73
- table_datum[:status] = resource.remote_state ? resource.remote_state[:instance]['Status'] : 'not created'
74
- table_datum[:last_state_changed] = resource.remote_state ? resource.remote_state[:instance]['StatusChangedAt'] : 'not created'
75
- table_datum[:ipaddress] = resource.remote_state ? resource.remote_state[:interfaces].first['UserIPAddress'] : 'not created'
73
+ table_datum[:status] = resource.remote_state && resource.remote_state[:instance] ? resource.remote_state[:instance]['Status'] : 'not created'
74
+ table_datum[:last_state_changed] = resource.remote_state && resource.remote_state[:instance] ? resource.remote_state[:instance]['StatusChangedAt'] : 'not created'
75
+ table_datum[:ipaddress] = resource.remote_state && resource.remote_state[:interfaces] ? resource.remote_state[:interfaces].first['UserIPAddress'] : 'not created'
76
76
 
77
77
  table_data << table_datum
78
78
  end
@@ -23,6 +23,12 @@ module SakurraForm
23
23
  def collect_remote_state
24
24
  # Override It
25
25
  end
26
+
27
+ def flush_cached_state(type)
28
+ state_path = "state/#{type}/#{@resource_id}.yml"
29
+ return true unless File.exists?(state_path)
30
+ File.delete(state_path)
31
+ end
26
32
  end
27
33
  end
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module SakurraForm
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sakurraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawanoboly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor