knife-scaleway 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerDestroy < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server destroy (options)'
21
+
22
+ option :server,
23
+ short: '-S ID',
24
+ long: '--server ID',
25
+ description: 'The server id'
26
+
27
+ option :all,
28
+ short: '-a',
29
+ long: '--all',
30
+ description: '!WARNING! UNRECOVERABLE Destroy all servers.'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ servers_ids = []
38
+
39
+ if locate_config_value(:server)
40
+ servers_ids = [locate_config_value(:server)]
41
+ elsif locate_config_value(:all)
42
+ ui.error('Warning all servers will be lost unless you exit with ctrl-c now!')
43
+
44
+ 15.times do |x|
45
+ print x
46
+ print 13.chr
47
+ sleep 1
48
+ end
49
+
50
+ servers_ids = client.servers.all.map(&:id)
51
+ else
52
+ ui.error 'You need to specify either a --server id or --all'
53
+ exit 1
54
+ end
55
+
56
+ if servers_ids.empty?
57
+ ui.error('Could not find any server(s)')
58
+ exit 1
59
+ end
60
+
61
+ servers_ids.each do |id|
62
+ ui.info "Delete server with id: #{id}"
63
+ result = client.servers.delete(id: id)
64
+ ui.info 'OK' if result == true || ui.error(JSON.parse(result)['message'])
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,54 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerList < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server list (options)'
21
+
22
+ def run
23
+ $stdout.sync = true
24
+
25
+ validate!
26
+
27
+ server_list = [
28
+ ui.color('ID', :bold),
29
+ ui.color('Name', :bold),
30
+ ui.color('Size', :bold),
31
+ ui.color('Region', :bold),
32
+ ui.color('IPv4', :bold),
33
+ ui.color('Image', :bold),
34
+ ui.color('Status', :bold)
35
+ ]
36
+ servers = Scaleway::Server.all
37
+
38
+ servers.each do |server|
39
+ ip = server.public_ip ? server.public_ip.address.to_s : ''.to_s
40
+
41
+ server_list << server.id.to_s
42
+ server_list << server.name.to_s
43
+ server_list << '?' # server.size_slug.to_s
44
+ server_list << 'fr-1' # server.region.name.to_s
45
+ server_list << ip
46
+ server_list << server.image.name.to_s
47
+ server_list << server.state.to_s
48
+ end
49
+
50
+ puts ui.list(server_list, :uneven_columns_across, 7)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,69 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerPower < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server power (options)'
21
+
22
+ option :action,
23
+ short: '-a ACTION',
24
+ long: '--action ACTION',
25
+ description: 'Power Action On/Off'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--server-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:action)
38
+ ui.error('Action cannot be empty. => -a <action>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ case locate_config_value(:action)
48
+ when /(on)/i
49
+ poweron = true
50
+ result = Scaleway::Server.action(locate_config_value(:id), 'poweron')
51
+ when /(off)/i
52
+ poweroff = true
53
+ result = Scaleway::Server.action(locate_config_value(:id), 'poweroff')
54
+ else
55
+ ui.error 'Bad Action: Use on/off.'
56
+ exit 1
57
+ end
58
+
59
+ unless result.task.description
60
+ #ui.error JSON.parse(result)['message']
61
+ exit 1
62
+ end
63
+
64
+ wait_for_status(result, status: 'running') if poweron
65
+ wait_for_status(result, status: 'stopped') if poweroff
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,48 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerPowercycle < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server powercycle (options)'
21
+
22
+ option :id,
23
+ short: '-I ID',
24
+ long: '--server-id ID',
25
+ description: 'Droplet ID'
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ validate!
31
+
32
+ unless locate_config_value(:id)
33
+ ui.error('ID cannot be empty. => -I <id>')
34
+ exit 1
35
+ end
36
+
37
+ result = client.server_actions.power_cycle(server_id: locate_config_value(:id))
38
+
39
+ unless result.class == DropletKit::Action
40
+ ui.error JSON.parse(result)['message']
41
+ exit 1
42
+ end
43
+
44
+ wait_for_status(result, status: 'active')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerReboot < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server reboot (options)'
21
+
22
+ option :id,
23
+ short: '-I ID',
24
+ long: '--server-id ID',
25
+ description: 'Droplet ID'
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ validate!
31
+
32
+ unless locate_config_value(:id)
33
+ ui.error('ID cannot be empty. => -I <id>')
34
+ exit 1
35
+ end
36
+
37
+ result = client.server_actions.reboot(server_id: locate_config_value(:id))
38
+
39
+ unless result.class == DropletKit::Action
40
+ ui.error JSON.parse(result)['message']
41
+ exit 1
42
+ end
43
+
44
+ wait_for_status(result)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,61 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerRebuild < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server rebuild (options)'
21
+
22
+ option :image,
23
+ short: '-i IMAGE',
24
+ long: '--image-id IMAGE',
25
+ description: 'Image ID'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--server-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:image)
38
+ ui.error('Image ID cannot be empty. => -i <image-id>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ result = client.server_actions.rebuild(
48
+ server_id: locate_config_value(:id),
49
+ image: locate_config_value(:image)
50
+ )
51
+
52
+ unless result.class == DropletKit::Action
53
+ ui.error JSON.parse(result)['message']
54
+ exit 1
55
+ end
56
+
57
+ wait_for_status(result, status: 'active')
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,58 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerRename < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server rename (options)'
21
+
22
+ option :name,
23
+ short: '-N NAME',
24
+ long: '--server-name NAME',
25
+ description: 'Name of server'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--server-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:name)
38
+ ui.error('Name cannot be empty. => -N <name>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ result = client.server_actions.rename(server_id: locate_config_value(:id), name: locate_config_value(:name))
48
+
49
+ unless result.class == DropletKit::Action
50
+ ui.error JSON.parse(result)['message']
51
+ exit 1
52
+ end
53
+
54
+ wait_for_status(result)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+ #
13
+ require 'chef/knife/scaleway_base'
14
+
15
+ class Chef
16
+ class Knife
17
+ class ScalewayServerResize < Knife
18
+ include Knife::ScalewayBase
19
+
20
+ banner 'knife scaleway server resize (options)'
21
+
22
+ option :size,
23
+ short: '-s SIZE',
24
+ long: '--size SIZE',
25
+ description: 'Power Action On/Off'
26
+
27
+ option :id,
28
+ short: '-I ID',
29
+ long: '--server-id ID',
30
+ description: 'Droplet ID'
31
+
32
+ def run
33
+ $stdout.sync = true
34
+
35
+ validate!
36
+
37
+ unless locate_config_value(:size)
38
+ ui.error('Size cannot be empty. => -s <size>')
39
+ exit 1
40
+ end
41
+
42
+ unless locate_config_value(:id)
43
+ ui.error('ID cannot be empty. => -I <id>')
44
+ exit 1
45
+ end
46
+
47
+ result = client.server_actions.resize(server_id: locate_config_value(:id), size: locate_config_value(:size))
48
+
49
+ unless result.class == DropletKit::Action
50
+ ui.error JSON.parse(result)['message']
51
+ exit 1
52
+ end
53
+
54
+ wait_for_status(result)
55
+ end
56
+ end
57
+ end
58
+ end