knife-oneandone 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -12
  3. data/.rspec +2 -2
  4. data/.rubocop.yml +29 -26
  5. data/.travis.yml +5 -5
  6. data/Gemfile +4 -4
  7. data/LICENSE +201 -201
  8. data/README.md +358 -278
  9. data/Rakefile +6 -6
  10. data/knife-oneandone.gemspec +30 -31
  11. data/lib/1and1/helpers.rb +29 -29
  12. data/lib/chef/knife/oneandone_appliance_list.rb +39 -39
  13. data/lib/chef/knife/oneandone_base.rb +32 -32
  14. data/lib/chef/knife/oneandone_block_storage_attach.rb +33 -0
  15. data/lib/chef/knife/oneandone_block_storage_create.rb +64 -0
  16. data/lib/chef/knife/oneandone_block_storage_delete.rb +59 -0
  17. data/lib/chef/knife/oneandone_block_storage_detach.rb +28 -0
  18. data/lib/chef/knife/oneandone_block_storage_list.rb +42 -0
  19. data/lib/chef/knife/oneandone_block_storage_rename.rb +38 -0
  20. data/lib/chef/knife/oneandone_datacenter_list.rb +33 -33
  21. data/lib/chef/knife/oneandone_firewall_create.rb +97 -97
  22. data/lib/chef/knife/oneandone_firewall_delete.rb +59 -59
  23. data/lib/chef/knife/oneandone_firewall_list.rb +33 -33
  24. data/lib/chef/knife/oneandone_ip_list.rb +39 -39
  25. data/lib/chef/knife/oneandone_loadbalancer_create.rb +147 -147
  26. data/lib/chef/knife/oneandone_loadbalancer_delete.rb +59 -59
  27. data/lib/chef/knife/oneandone_loadbalancer_list.rb +39 -39
  28. data/lib/chef/knife/oneandone_mp_list.rb +37 -37
  29. data/lib/chef/knife/oneandone_server_baremetal_model_list.rb +31 -0
  30. data/lib/chef/knife/oneandone_server_create.rb +193 -163
  31. data/lib/chef/knife/oneandone_server_delete.rb +63 -63
  32. data/lib/chef/knife/oneandone_server_hdd_add.rb +60 -60
  33. data/lib/chef/knife/oneandone_server_hdd_delete.rb +55 -55
  34. data/lib/chef/knife/oneandone_server_hdd_list.rb +44 -44
  35. data/lib/chef/knife/oneandone_server_hdd_resize.rb +59 -59
  36. data/lib/chef/knife/oneandone_server_list.rb +35 -35
  37. data/lib/chef/knife/oneandone_server_modify.rb +80 -80
  38. data/lib/chef/knife/oneandone_server_reboot.rb +41 -41
  39. data/lib/chef/knife/oneandone_server_rename.rb +37 -37
  40. data/lib/chef/knife/oneandone_server_size_list.rb +39 -39
  41. data/lib/chef/knife/oneandone_server_start.rb +35 -35
  42. data/lib/chef/knife/oneandone_server_stop.rb +41 -41
  43. data/lib/chef/knife/oneandone_ssh_key_create.rb +54 -0
  44. data/lib/chef/knife/oneandone_ssh_key_delete.rb +59 -0
  45. data/lib/chef/knife/oneandone_ssh_key_list.rb +44 -0
  46. data/lib/chef/knife/oneandone_ssh_key_rename.rb +37 -0
  47. data/lib/knife-oneandone/version.rb +5 -5
  48. metadata +24 -13
@@ -1,39 +1,39 @@
1
- require 'chef/knife/oneandone_base'
2
-
3
- class Chef
4
- class Knife
5
- class OneandoneLoadbalancerList < Knife
6
- include Knife::OneandoneBase
7
-
8
- banner 'knife oneandone loadbalancer list'
9
-
10
- def run
11
- $stdout.sync = true
12
-
13
- init_client
14
-
15
- response = OneAndOne::LoadBalancer.new.list
16
- formated_output(response, true)
17
-
18
- load_balancers = [
19
- ui.color('ID', :bold),
20
- ui.color('Name', :bold),
21
- ui.color('IP Address', :bold),
22
- ui.color('Method', :bold),
23
- ui.color('State', :bold),
24
- ui.color('Data Center', :bold)
25
- ]
26
- response.each do |lb|
27
- load_balancers << lb['id']
28
- load_balancers << lb['name']
29
- load_balancers << lb['ip']
30
- load_balancers << lb['method']
31
- load_balancers << lb['state']
32
- load_balancers << lb['datacenter']['country_code']
33
- end
34
-
35
- puts ui.list(load_balancers, :uneven_columns_across, 6)
36
- end
37
- end
38
- end
39
- end
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneLoadbalancerList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone loadbalancer list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ init_client
14
+
15
+ response = OneAndOne::LoadBalancer.new.list
16
+ formated_output(response, true)
17
+
18
+ load_balancers = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold),
21
+ ui.color('IP Address', :bold),
22
+ ui.color('Method', :bold),
23
+ ui.color('State', :bold),
24
+ ui.color('Data Center', :bold)
25
+ ]
26
+ response.each do |lb|
27
+ load_balancers << lb['id']
28
+ load_balancers << lb['name']
29
+ load_balancers << lb['ip']
30
+ load_balancers << lb['method']
31
+ load_balancers << lb['state']
32
+ load_balancers << lb['datacenter']['country_code']
33
+ end
34
+
35
+ puts ui.list(load_balancers, :uneven_columns_across, 6)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,37 +1,37 @@
1
- require 'chef/knife/oneandone_base'
2
-
3
- class Chef
4
- class Knife
5
- class OneandoneMpList < Knife
6
- include Knife::OneandoneBase
7
-
8
- banner 'knife oneandone mp list'
9
-
10
- def run
11
- $stdout.sync = true
12
-
13
- init_client
14
-
15
- response = OneAndOne::MonitoringPolicy.new.list
16
- formated_output(response, true)
17
-
18
- mp_list = [
19
- ui.color('ID', :bold),
20
- ui.color('Name', :bold),
21
- ui.color('Email', :bold),
22
- ui.color('State', :bold),
23
- ui.color('Agent', :bold)
24
- ]
25
- response.each do |mp|
26
- mp_list << mp['id']
27
- mp_list << mp['name']
28
- mp_list << mp['email']
29
- mp_list << mp['state']
30
- mp_list << mp['agent'].to_s
31
- end
32
-
33
- puts ui.list(mp_list, :uneven_columns_across, 5)
34
- end
35
- end
36
- end
37
- end
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneMpList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone mp list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ init_client
14
+
15
+ response = OneAndOne::MonitoringPolicy.new.list
16
+ formated_output(response, true)
17
+
18
+ mp_list = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold),
21
+ ui.color('Email', :bold),
22
+ ui.color('State', :bold),
23
+ ui.color('Agent', :bold)
24
+ ]
25
+ response.each do |mp|
26
+ mp_list << mp['id']
27
+ mp_list << mp['name']
28
+ mp_list << mp['email']
29
+ mp_list << mp['state']
30
+ mp_list << mp['agent'].to_s
31
+ end
32
+
33
+ puts ui.list(mp_list, :uneven_columns_across, 5)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ require 'chef/knife/oneandone_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class OneandoneBaremetalModelList < Knife
6
+ include Knife::OneandoneBase
7
+
8
+ banner 'knife oneandone baremetal model list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+
13
+ init_client
14
+
15
+ response = OneAndOne::Server.new.list_baremetal_models
16
+ formated_output(response, true)
17
+
18
+ baremetal_model_list = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold)
21
+ ]
22
+ response.each do |baremetal_model|
23
+ baremetal_model_list << baremetal_model['id']
24
+ baremetal_model_list << baremetal_model['name']
25
+ end
26
+
27
+ puts ui.list(baremetal_model_list, :uneven_columns_across, 2)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,163 +1,193 @@
1
- require 'chef/knife/oneandone_base'
2
- require '1and1/helpers'
3
-
4
- class Chef
5
- class Knife
6
- class OneandoneServerCreate < Knife
7
- include Knife::OneandoneBase
8
- include Oneandone::Helpers
9
-
10
- banner 'knife oneandone server create (options)'
11
-
12
- option :datacenter_id,
13
- short: '-D DATACENTER_ID',
14
- long: '--datacenter-id DATACENTER_ID',
15
- description: 'ID of the virtual data center',
16
- proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
17
-
18
- option :name,
19
- short: '-n NAME',
20
- long: '--name NAME',
21
- description: 'Name of the server (required)'
22
-
23
- option :description,
24
- long: '--description DESCRIPTION',
25
- description: 'Description of the server'
26
-
27
- option :appliance_id,
28
- short: '-I APPLIANCE_ID',
29
- long: '--appliance-id APPLIANCE_ID',
30
- description: 'ID of the server appliance (required)',
31
- proc: proc { |appliance_id| Chef::Config[:knife][:appliance_id] = appliance_id }
32
-
33
- option :fixed_size_id,
34
- short: '-S FIXED_SIZE_ID',
35
- long: '--fixed-size-id FIXED_SIZE_ID',
36
- description: 'ID of the fixed instance size',
37
- proc: proc { |fixed_size_id| Chef::Config[:knife][:fixed_size_id] = fixed_size_id }
38
-
39
- option :cpu,
40
- short: '-P PROCESSORS',
41
- long: '--cpu PROCESSORS',
42
- description: "The number of processors. Required, if '--fixed-size-id' is not specified."
43
-
44
- option :cores,
45
- short: '-C CORES',
46
- long: '--cores CORES',
47
- description: "The number of cores per processor. Required, if '--fixed-size-id' is not specified."
48
-
49
- option :ram,
50
- short: '-r RAM',
51
- long: '--ram RAM',
52
- description: "The amount of RAM in GB. Required, if '--fixed-size-id' is not specified."
53
-
54
- option :hdd_size,
55
- short: '-H HDD_SIZE',
56
- long: '--hdd-size HDD_SIZE',
57
- description: "The HDD size in GB. Required, if '--fixed-size-id' is not specified."
58
-
59
- option :password,
60
- short: '-p PASSWORD',
61
- long: '--password PASSWORD',
62
- description: "The password of the server's root/administrator user"
63
-
64
- option :rsa_key,
65
- long: '--rsa-key RSA_KEY',
66
- description: 'Specify a valid public SSH Key to be copied into your 1&1 server during creation.',
67
- proc: proc { |rsa_key| Chef::Config[:knife][:rsa_key] = rsa_key }
68
-
69
- option :firewall_id,
70
- long: '--firewall-id FIREWALL_ID',
71
- description: 'ID of a firewall policy to be used for the server',
72
- proc: proc { |firewall_id| Chef::Config[:knife][:firewall_id] = firewall_id }
73
-
74
- option :power_on,
75
- long: '--power-on BOOLEAN_VALUE',
76
- description: 'Power on the server after creating (true by default).',
77
- default: true
78
-
79
- option :ip_id,
80
- long: '--ip-id IP_ID',
81
- description: 'ID of an IP address to be used for the server'
82
-
83
- option :load_balancer_id,
84
- long: '--load-balancer-id LOAD_BALANCER_ID',
85
- description: 'ID of a load balancer to be used for the server',
86
- proc: proc { |load_balancer_id| Chef::Config[:knife][:load_balancer_id] = load_balancer_id }
87
-
88
- option :monitoring_policy_id,
89
- long: '--monitoring-policy-id MONITORING_POLICY_ID',
90
- description: 'ID of a monitoring policy to be used for the server',
91
- proc: proc { |monitoring_policy_id| Chef::Config[:knife][:monitoring_policy_id] = monitoring_policy_id }
92
-
93
- option :wait,
94
- long: '--[no-]wait',
95
- description: 'Wait for the server deployment to complete (true by default).',
96
- boolean: true,
97
- default: true
98
-
99
- def run
100
- $stdout.sync = true
101
-
102
- validate(config[:name], '-n NAME')
103
- validate(config[:appliance_id], '-I APPLIANCE_ID')
104
-
105
- init_client
106
-
107
- size_id = config[:fixed_size_id]
108
- hdds = nil
109
-
110
- if size_id.nil? || size_id.empty?
111
- hdds = [
112
- {
113
- 'size' => config[:hdd_size],
114
- 'is_main' => true
115
- }
116
- ]
117
- end
118
-
119
- server = OneAndOne::Server.new
120
- response = server.create(
121
- name: config[:name],
122
- description: config[:description],
123
- datacenter_id: config[:datacenter_id],
124
- fixed_instance_id: size_id,
125
- appliance_id: config[:appliance_id],
126
- vcore: config[:cpu],
127
- cores_per_processor: config[:cores],
128
- ram: config[:ram],
129
- hdds: hdds,
130
- power_on: config[:power_on],
131
- password: config[:password],
132
- rsa_key: config[:rsa_key],
133
- firewall_id: config[:firewall_id],
134
- ip_id: config[:ip_id],
135
- load_balancer_id: config[:load_balancer_id],
136
- monitoring_policy_id: config[:monitoring_policy_id]
137
- )
138
-
139
- if config[:wait]
140
- puts ui.color('Deploying, wait for the operation to complete...', :cyan).to_s
141
-
142
- # wait for provisioning 30m max
143
- server.wait_for(timeout: 30, interval: 15)
144
-
145
- formated_output(server.get, true)
146
-
147
- first_password = server.first_password.nil? ? config[:password] : server.first_password
148
- first_ip = !server.specs['ips'].empty? ? server.specs['ips'][0]['ip'] : ''
149
-
150
- puts "\t#{ui.color('ID', :cyan)}: #{server.id}"
151
- puts "\t#{ui.color('Name', :cyan)}: #{server.specs['name']}"
152
- puts "\t#{ui.color('First IP', :cyan)}: #{first_ip}"
153
- puts "\t#{ui.color('First Password', :cyan)}: #{first_password}\n"
154
-
155
- puts ui.color('done', :bold).to_s
156
- else
157
- formated_output(response, true)
158
- puts "Server #{response['id']} is #{ui.color('being deployed', :bold)}"
159
- end
160
- end
161
- end
162
- end
163
- end
1
+ require 'chef/knife/oneandone_base'
2
+ require '1and1/helpers'
3
+
4
+ class Chef
5
+ class Knife
6
+ class OneandoneServerCreate < Knife
7
+ include Knife::OneandoneBase
8
+ include Oneandone::Helpers
9
+
10
+ banner 'knife oneandone server create (options)'
11
+
12
+ option :datacenter_id,
13
+ short: '-D DATACENTER_ID',
14
+ long: '--datacenter-id DATACENTER_ID',
15
+ description: 'ID of the virtual data center',
16
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
17
+
18
+ option :name,
19
+ short: '-n NAME',
20
+ long: '--name NAME',
21
+ description: 'Name of the server (required)'
22
+
23
+ option :description,
24
+ long: '--description DESCRIPTION',
25
+ description: 'Description of the server'
26
+
27
+ option :appliance_id,
28
+ short: '-I APPLIANCE_ID',
29
+ long: '--appliance-id APPLIANCE_ID',
30
+ description: 'ID of the server appliance (required)',
31
+ proc: proc { |appliance_id| Chef::Config[:knife][:appliance_id] = appliance_id }
32
+
33
+ option :fixed_size_id,
34
+ short: '-S FIXED_SIZE_ID',
35
+ long: '--fixed-size-id FIXED_SIZE_ID',
36
+ description: 'ID of the fixed instance size',
37
+ proc: proc { |fixed_size_id| Chef::Config[:knife][:fixed_size_id] = fixed_size_id }
38
+
39
+ option :baremetal_model_id,
40
+ short: '-BM BAREMETAL_MODEL_ID',
41
+ long: '--baremetal-model-id BAREMETAL_MODEL_ID',
42
+ description: "ID of the baremetal model. Required, if 'server_type' is 'baremetal'",
43
+ proc: proc { |baremetal_model_id| Chef::Config[:knife][:baremetal_model_id] = baremetal_model_id }
44
+
45
+ option :cpu,
46
+ short: '-P PROCESSORS',
47
+ long: '--cpu PROCESSORS',
48
+ description: "The number of processors. Required, if neither '--fixed-size-id' nor '--baremetal-model-id' are specified."
49
+
50
+ option :cores,
51
+ short: '-C CORES',
52
+ long: '--cores CORES',
53
+ description: "The number of cores per processor. Required, if neither '--fixed-size-id' nor '--baremetal-model-id' are specified."
54
+
55
+ option :ram,
56
+ short: '-r RAM',
57
+ long: '--ram RAM',
58
+ description: "The amount of RAM in GB. Required, if neither '--fixed-size-id' nor '--baremetal-model-id' are specified."
59
+
60
+ option :hdd_size,
61
+ short: '-H HDD_SIZE',
62
+ long: '--hdd-size HDD_SIZE',
63
+ description: "The HDD size in GB. Required, if neither '--fixed-size-id' nor '--baremetal-model-id' are specified."
64
+
65
+ option :password,
66
+ short: '-p PASSWORD',
67
+ long: '--password PASSWORD',
68
+ description: "The password of the server's root/administrator user"
69
+
70
+ option :rsa_key,
71
+ long: '--rsa-key RSA_KEY',
72
+ description: 'Specify a valid public SSH Key to be copied into your 1&1 server during creation.',
73
+ proc: proc { |rsa_key| Chef::Config[:knife][:rsa_key] = rsa_key }
74
+
75
+ option :firewall_id,
76
+ long: '--firewall-id FIREWALL_ID',
77
+ description: 'ID of a firewall policy to be used for the server',
78
+ proc: proc { |firewall_id| Chef::Config[:knife][:firewall_id] = firewall_id }
79
+
80
+ option :power_on,
81
+ long: '--power-on BOOLEAN_VALUE',
82
+ description: 'Power on the server after creating (true by default).',
83
+ default: true
84
+
85
+ option :ip_id,
86
+ long: '--ip-id IP_ID',
87
+ description: 'ID of an IP address to be used for the server'
88
+
89
+ option :load_balancer_id,
90
+ long: '--load-balancer-id LOAD_BALANCER_ID',
91
+ description: 'ID of a load balancer to be used for the server',
92
+ proc: proc { |load_balancer_id| Chef::Config[:knife][:load_balancer_id] = load_balancer_id }
93
+
94
+ option :monitoring_policy_id,
95
+ long: '--monitoring-policy-id MONITORING_POLICY_ID',
96
+ description: 'ID of a monitoring policy to be used for the server',
97
+ proc: proc { |monitoring_policy_id| Chef::Config[:knife][:monitoring_policy_id] = monitoring_policy_id }
98
+
99
+ option :public_key,
100
+ short: '-pk PUBLIC_KEY',
101
+ long: '--public-key PUBLIC_KEY',
102
+ description: 'A comma separated list of SSH Key IDs to be copied to the server'
103
+
104
+ option :server_type,
105
+ short: '-st SERVER_TYPE',
106
+ long: '--server-type SERVER_TYPE',
107
+ description: "Server type 'cloud' or 'baremetal'."
108
+
109
+ option :wait,
110
+ long: '--[no-]wait',
111
+ description: 'Wait for the server deployment to complete (true by default).',
112
+ boolean: true,
113
+ default: true
114
+
115
+ def run
116
+ $stdout.sync = true
117
+
118
+ validate(config[:name], '-n NAME')
119
+ validate(config[:appliance_id], '-I APPLIANCE_ID')
120
+
121
+ init_client
122
+
123
+ size_id = config[:fixed_size_id]
124
+ hdds = nil
125
+
126
+ if size_id.nil? || size_id.empty?
127
+ hdds = [
128
+ {
129
+ 'size' => config[:hdd_size],
130
+ 'is_main' => true
131
+ }
132
+ ]
133
+ end
134
+
135
+ pkeys_config = config[:public_key]
136
+ pkeys = nil
137
+
138
+ if !pkeys_config.nil? && !pkeys_config.empty?
139
+ pkeys_config = pkeys_config.split(',')
140
+ pkeys = []
141
+ pkeys_config.each do |key|
142
+ pkeys << key.strip
143
+ end
144
+ end
145
+
146
+ server = OneAndOne::Server.new
147
+ response = server.create(
148
+ name: config[:name],
149
+ description: config[:description],
150
+ datacenter_id: config[:datacenter_id],
151
+ fixed_instance_id: size_id,
152
+ appliance_id: config[:appliance_id],
153
+ vcore: config[:cpu],
154
+ cores_per_processor: config[:cores],
155
+ ram: config[:ram],
156
+ hdds: hdds,
157
+ power_on: config[:power_on],
158
+ password: config[:password],
159
+ rsa_key: config[:rsa_key],
160
+ firewall_id: config[:firewall_id],
161
+ ip_id: config[:ip_id],
162
+ load_balancer_id: config[:load_balancer_id],
163
+ monitoring_policy_id: config[:monitoring_policy_id],
164
+ public_key: pkeys,
165
+ server_type: config[:server_type],
166
+ baremetal_model_id: config[:baremetal_model_id]
167
+ )
168
+
169
+ if config[:wait]
170
+ puts ui.color('Deploying, wait for the operation to complete...', :cyan).to_s
171
+
172
+ # wait for provisioning 30m max
173
+ server.wait_for(timeout: 30, interval: 15)
174
+
175
+ formated_output(server.get, true)
176
+
177
+ first_password = server.first_password.nil? ? config[:password] : server.first_password
178
+ first_ip = !server.specs['ips'].empty? ? server.specs['ips'][0]['ip'] : ''
179
+
180
+ puts "\t#{ui.color('ID', :cyan)}: #{server.id}"
181
+ puts "\t#{ui.color('Name', :cyan)}: #{server.specs['name']}"
182
+ puts "\t#{ui.color('First IP', :cyan)}: #{first_ip}"
183
+ puts "\t#{ui.color('First Password', :cyan)}: #{first_password}\n"
184
+
185
+ puts ui.color('done', :bold).to_s
186
+ else
187
+ formated_output(response, true)
188
+ puts "Server #{response['id']} is #{ui.color('being deployed', :bold)}"
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end