knife-oneandone 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +26 -0
  5. data/.travis.yml +5 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +201 -0
  8. data/README.md +278 -0
  9. data/Rakefile +6 -0
  10. data/knife-oneandone.gemspec +31 -0
  11. data/lib/1and1/helpers.rb +29 -0
  12. data/lib/chef/knife/oneandone_appliance_list.rb +39 -0
  13. data/lib/chef/knife/oneandone_base.rb +32 -0
  14. data/lib/chef/knife/oneandone_datacenter_list.rb +33 -0
  15. data/lib/chef/knife/oneandone_firewall_create.rb +97 -0
  16. data/lib/chef/knife/oneandone_firewall_delete.rb +59 -0
  17. data/lib/chef/knife/oneandone_firewall_list.rb +33 -0
  18. data/lib/chef/knife/oneandone_ip_list.rb +39 -0
  19. data/lib/chef/knife/oneandone_loadbalancer_create.rb +147 -0
  20. data/lib/chef/knife/oneandone_loadbalancer_delete.rb +59 -0
  21. data/lib/chef/knife/oneandone_loadbalancer_list.rb +39 -0
  22. data/lib/chef/knife/oneandone_mp_list.rb +37 -0
  23. data/lib/chef/knife/oneandone_server_create.rb +163 -0
  24. data/lib/chef/knife/oneandone_server_delete.rb +63 -0
  25. data/lib/chef/knife/oneandone_server_hdd_add.rb +60 -0
  26. data/lib/chef/knife/oneandone_server_hdd_delete.rb +55 -0
  27. data/lib/chef/knife/oneandone_server_hdd_list.rb +44 -0
  28. data/lib/chef/knife/oneandone_server_hdd_resize.rb +59 -0
  29. data/lib/chef/knife/oneandone_server_list.rb +35 -0
  30. data/lib/chef/knife/oneandone_server_modify.rb +80 -0
  31. data/lib/chef/knife/oneandone_server_reboot.rb +41 -0
  32. data/lib/chef/knife/oneandone_server_rename.rb +37 -0
  33. data/lib/chef/knife/oneandone_server_size_list.rb +39 -0
  34. data/lib/chef/knife/oneandone_server_start.rb +35 -0
  35. data/lib/chef/knife/oneandone_server_stop.rb +41 -0
  36. data/lib/knife-oneandone/version.rb +5 -0
  37. metadata +191 -0
@@ -0,0 +1,44 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerHddList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server hdd list SERVER_ID [SERVER_ID]'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ server_id = ''
14
+
15
+ if name_args.empty?
16
+ ui.error('Server ID must be provided.')
17
+ exit 1
18
+ else
19
+ server_id = name_args[0]
20
+ end
21
+
22
+ init_client
23
+
24
+ server = OneAndOne::Server.new
25
+
26
+ response = server.hdds(server_id: server_id)
27
+ formated_output(response, true)
28
+
29
+ hdds = [
30
+ ui.color('ID', :bold),
31
+ ui.color('Size (GB)', :bold),
32
+ ui.color('Main', :bold)
33
+ ]
34
+ response.each do |disk|
35
+ hdds << disk['id']
36
+ hdds << disk['size'].to_s
37
+ hdds << disk['is_main'].to_s
38
+ end
39
+
40
+ puts ui.list(hdds, :uneven_columns_across, 3)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,59 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerHddResize < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server hdd resize (options)'
9
+
10
+ option :disk_id,
11
+ short: '-D DISK_ID',
12
+ long: '--disk-id DISK_ID',
13
+ description: 'Disk ID'
14
+
15
+ option :disk_size,
16
+ long: '--disk-size DISK_SIZE',
17
+ description: 'Disk size'
18
+
19
+ option :server_id,
20
+ short: '-S SERVER_ID',
21
+ long: '--server-id SERVER_ID',
22
+ description: 'Server ID'
23
+
24
+ option :wait,
25
+ short: '-W',
26
+ long: '--wait',
27
+ description: 'Wait for the operation to complete.'
28
+
29
+ def run
30
+ $stdout.sync = true
31
+
32
+ init_client
33
+
34
+ server = OneAndOne::Server.new
35
+
36
+ begin
37
+ server.get(server_id: config[:server_id])
38
+ rescue StandardError => e
39
+ if e.message.include? 'NOT_FOUND'
40
+ ui.error("Server ID #{config[:server_id]} not found")
41
+ else
42
+ ui.error(e.message)
43
+ end
44
+ exit 1
45
+ end
46
+
47
+ server.modify_hdd(server_id: config[:server_id], hdd_id: config[:disk_id], size: config[:disk_size])
48
+
49
+ if config[:wait]
50
+ puts ui.color('Resizing, wait for the operation to complete...', :cyan).to_s
51
+ server.wait_for
52
+ puts "HDD #{config[:disk_id]} is #{ui.color('resized', :bold)}"
53
+ else
54
+ puts "HDD #{config[:disk_id]} is #{ui.color('resizing', :bold)}"
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,35 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ init_client
14
+
15
+ response = OneAndOne::Server.new.list
16
+ formated_output(response, true)
17
+
18
+ server_list = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold),
21
+ ui.color('State', :bold),
22
+ ui.color('Data Center', :bold)
23
+ ]
24
+ response.each do |server|
25
+ server_list << server['id']
26
+ server_list << server['name']
27
+ server_list << server['status']['state']
28
+ server_list << server['datacenter']['country_code']
29
+ end
30
+
31
+ puts ui.list(server_list, :uneven_columns_across, 4)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,80 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerModify < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server modify SERVER_ID [SERVER_ID] (options)'
9
+
10
+ option :fixed_size_id,
11
+ short: '-S FIXED_SIZE_ID',
12
+ long: '--fixed-size-id FIXED_SIZE_ID',
13
+ description: 'ID of the fixed instance size'
14
+
15
+ option :cpu,
16
+ short: '-P PROCESSORS',
17
+ long: '--cpu PROCESSORS',
18
+ description: 'The number of processors'
19
+
20
+ option :cores,
21
+ short: '-C CORES',
22
+ long: '--cores CORES',
23
+ description: 'The number of cores per processor'
24
+
25
+ option :ram,
26
+ short: '-r RAM',
27
+ long: '--ram RAM',
28
+ description: 'The amount of RAM in GB'
29
+
30
+ option :wait,
31
+ short: '-W',
32
+ long: '--wait',
33
+ description: 'Wait for the operation to complete.'
34
+
35
+ def run
36
+ $stdout.sync = true
37
+
38
+ init_client
39
+
40
+ name_args.each do |server_id|
41
+ server = OneAndOne::Server.new
42
+
43
+ begin
44
+ server.get(server_id: server_id)
45
+ rescue StandardError => e
46
+ if e.message.include? 'NOT_FOUND'
47
+ ui.error("Server ID #{server_id} not found. Skipping.")
48
+ else
49
+ ui.error(e.message)
50
+ end
51
+ next
52
+ end
53
+
54
+ server.modify_hardware(
55
+ fixed_instance_id: config[:fixed_size_id],
56
+ vcore: config[:cpu],
57
+ cores_per_processor: config[:cores],
58
+ ram: config[:ram]
59
+ )
60
+
61
+ if config[:wait]
62
+ puts ui.color('Reconfiguring, wait for the operation to complete...', :cyan).to_s
63
+ server.wait_for
64
+
65
+ puts "\t#{ui.color('ID', :cyan)}: #{server.id}"
66
+ puts "\t#{ui.color('Name', :cyan)}: #{server.specs['name']}"
67
+ puts "\t#{ui.color('Fixed Size ID', :cyan)}: #{server.specs['hardware']['fixed_instance_size_id']}"
68
+ puts "\t#{ui.color('Processors', :cyan)}: #{server.specs['hardware']['vcore']}"
69
+ puts "\t#{ui.color('Cores per Processor', :cyan)}: #{server.specs['hardware']['cores_per_processor']}"
70
+ puts "\t#{ui.color('RAM (GB)', :cyan)}: #{server.specs['hardware']['ram']}\n"
71
+
72
+ puts "Server's hardware is #{ui.color('modified', :bold)}"
73
+ else
74
+ puts "Server's hardware is #{ui.color('being modified', :bold)}"
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,41 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerReboot < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server reboot SERVER_ID [SERVER_ID] (options)'
9
+
10
+ option :force,
11
+ long: '--force',
12
+ description: 'Force hardware restart.'
13
+
14
+ option :wait,
15
+ short: '-W',
16
+ long: '--wait',
17
+ description: 'Wait for the operation to complete.'
18
+
19
+ def run
20
+ $stdout.sync = true
21
+
22
+ init_client
23
+
24
+ method = config[:force] ? 'HARDWARE' : 'SOFTWARE'
25
+
26
+ name_args.each do |server_id|
27
+ server = OneAndOne::Server.new
28
+ response = server.change_status(server_id: server_id, action: 'REBOOT', method: method)
29
+
30
+ if config[:wait]
31
+ puts ui.color('Rebooting, wait for the operation to complete...', :cyan).to_s
32
+ server.wait_for
33
+ puts "Server '#{server.specs['name']}' is #{ui.color('rebooted', :bold)}"
34
+ else
35
+ puts "Server '#{response['name']}' is #{ui.color('rebooting', :bold)}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerRename < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server rename (options)'
9
+
10
+ option :name,
11
+ short: '-n NAME',
12
+ long: '--server-name NAME',
13
+ description: 'Name of the server'
14
+
15
+ option :description,
16
+ long: '--server-desc DESCRIPTION',
17
+ description: 'Description of the server'
18
+
19
+ option :id,
20
+ short: '-I ID',
21
+ long: '--server-id ID',
22
+ description: 'Server ID'
23
+
24
+ def run
25
+ $stdout.sync = true
26
+
27
+ init_client
28
+
29
+ server = OneAndOne::Server.new
30
+ response = server.modify(server_id: config[:id], name: config[:name], description: config[:description])
31
+
32
+ formated_output(response, true)
33
+ puts "Server name and/or description #{ui.color('updated', :bold)}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerSizeList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server size list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ init_client
14
+
15
+ response = OneAndOne::Server.new.list_fixed
16
+ formated_output(response, true)
17
+
18
+ sizes = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold),
21
+ ui.color('RAM (GB)', :bold),
22
+ ui.color('Processor No.', :bold),
23
+ ui.color('Cores per Processor', :bold),
24
+ ui.color('Disk Size (GB)', :bold)
25
+ ]
26
+ response.each do |fs|
27
+ sizes << fs['id']
28
+ sizes << fs['name']
29
+ sizes << fs['hardware']['ram'].to_s
30
+ sizes << fs['hardware']['vcore'].to_s
31
+ sizes << fs['hardware']['cores_per_processor'].to_s
32
+ sizes << fs['hardware']['hdds'][0]['size'].to_s
33
+ end
34
+
35
+ puts ui.list(sizes, :uneven_columns_across, 6)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerStart < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server start SERVER_ID [SERVER_ID] (options)'
9
+
10
+ option :wait,
11
+ short: '-W',
12
+ long: '--wait',
13
+ description: 'Wait for the operation to complete.'
14
+
15
+ def run
16
+ $stdout.sync = true
17
+
18
+ init_client
19
+
20
+ name_args.each do |server_id|
21
+ server = OneAndOne::Server.new
22
+ response = server.change_status(server_id: server_id, action: 'POWER_ON')
23
+
24
+ if config[:wait]
25
+ puts ui.color('Starting, wait for the operation to complete...', :cyan).to_s
26
+ server.wait_for
27
+ puts "Server '#{server.specs['name']}' is #{ui.color('started', :bold)}"
28
+ else
29
+ puts "Server '#{response['name']}' is #{ui.color('starting', :bold)}"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneServerStop < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone server stop SERVER_ID [SERVER_ID] (options)'
9
+
10
+ option :force,
11
+ long: '--force',
12
+ description: 'Force hardware shutdown.'
13
+
14
+ option :wait,
15
+ short: '-W',
16
+ long: '--wait',
17
+ description: 'Wait for the operation to complete.'
18
+
19
+ def run
20
+ $stdout.sync = true
21
+
22
+ init_client
23
+
24
+ method = config[:force] ? 'HARDWARE' : 'SOFTWARE'
25
+
26
+ name_args.each do |server_id|
27
+ server = OneAndOne::Server.new
28
+ response = server.change_status(server_id: server_id, action: 'POWER_OFF', method: method)
29
+
30
+ if config[:wait]
31
+ puts ui.color('Stopping, wait for the operation to complete...', :cyan).to_s
32
+ server.wait_for
33
+ puts "Server '#{server.specs['name']}' is #{ui.color('stopped', :bold)}"
34
+ else
35
+ puts "Server '#{response['name']}' is #{ui.color('stopping', :bold)}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ module Knife
2
+ module Oneandone
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-oneandone
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nurfet Becirevic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: 1and1
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.39'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.39'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.24'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.24'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ description: Official Chef Knife plugin for managing 1&1 Cloud servers
126
+ email:
127
+ - nurfet@stackpointcloud.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.md
139
+ - Rakefile
140
+ - knife-oneandone.gemspec
141
+ - lib/1and1/helpers.rb
142
+ - lib/chef/knife/oneandone_appliance_list.rb
143
+ - lib/chef/knife/oneandone_base.rb
144
+ - lib/chef/knife/oneandone_datacenter_list.rb
145
+ - lib/chef/knife/oneandone_firewall_create.rb
146
+ - lib/chef/knife/oneandone_firewall_delete.rb
147
+ - lib/chef/knife/oneandone_firewall_list.rb
148
+ - lib/chef/knife/oneandone_ip_list.rb
149
+ - lib/chef/knife/oneandone_loadbalancer_create.rb
150
+ - lib/chef/knife/oneandone_loadbalancer_delete.rb
151
+ - lib/chef/knife/oneandone_loadbalancer_list.rb
152
+ - lib/chef/knife/oneandone_mp_list.rb
153
+ - lib/chef/knife/oneandone_server_create.rb
154
+ - lib/chef/knife/oneandone_server_delete.rb
155
+ - lib/chef/knife/oneandone_server_hdd_add.rb
156
+ - lib/chef/knife/oneandone_server_hdd_delete.rb
157
+ - lib/chef/knife/oneandone_server_hdd_list.rb
158
+ - lib/chef/knife/oneandone_server_hdd_resize.rb
159
+ - lib/chef/knife/oneandone_server_list.rb
160
+ - lib/chef/knife/oneandone_server_modify.rb
161
+ - lib/chef/knife/oneandone_server_reboot.rb
162
+ - lib/chef/knife/oneandone_server_rename.rb
163
+ - lib/chef/knife/oneandone_server_size_list.rb
164
+ - lib/chef/knife/oneandone_server_start.rb
165
+ - lib/chef/knife/oneandone_server_stop.rb
166
+ - lib/knife-oneandone/version.rb
167
+ homepage: https://github.com/1and1/oneandone-cloudserver-chef
168
+ licenses:
169
+ - Apache-2.0
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.6.4
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Chef Knife plugin for 1&1 Cloud server
191
+ test_files: []