knife-cloudstack-fog 0.3.3 → 0.3.4
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.
- data/lib/chef/knife/cloudstack_base.rb +101 -101
- data/lib/chef/knife/cloudstack_diskoffering_list.rb +57 -57
- data/lib/chef/knife/cloudstack_keypair_create.rb +102 -102
- data/lib/chef/knife/cloudstack_keypair_delete.rb +49 -49
- data/lib/chef/knife/cloudstack_keypair_list.rb +53 -53
- data/lib/chef/knife/cloudstack_network_create.rb +147 -147
- data/lib/chef/knife/cloudstack_network_delete.rb +53 -53
- data/lib/chef/knife/cloudstack_network_list.rb +67 -67
- data/lib/chef/knife/cloudstack_networkoffering_list.rb +74 -74
- data/lib/chef/knife/cloudstack_publicip_create.rb +90 -90
- data/lib/chef/knife/cloudstack_publicip_list.rb +57 -57
- data/lib/chef/knife/cloudstack_securitygroup_list.rb +124 -124
- data/lib/chef/knife/cloudstack_server_create.rb +320 -320
- data/lib/chef/knife/cloudstack_server_delete.rb +53 -53
- data/lib/chef/knife/cloudstack_server_destroy.rb +53 -53
- data/lib/chef/knife/cloudstack_server_list.rb +135 -135
- data/lib/chef/knife/cloudstack_server_start.rb +69 -69
- data/lib/chef/knife/cloudstack_server_stop.rb +72 -72
- data/lib/chef/knife/cloudstack_serviceoffering_list.rb +61 -61
- data/lib/chef/knife/cloudstack_template_list.rb +127 -127
- data/lib/chef/knife/cloudstack_volumes_list.rb +78 -78
- data/lib/chef/knife/cloudstack_zone_list.rb +63 -63
- data/lib/knife-cloudstack-fog/version.rb +1 -1
- metadata +2 -2
@@ -1,101 +1,101 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'chef/knife'
|
20
|
-
|
21
|
-
class Chef
|
22
|
-
class Knife
|
23
|
-
module CloudstackBase
|
24
|
-
|
25
|
-
# :nodoc:
|
26
|
-
# Would prefer to do this in a rational way, but can't be done b/c of
|
27
|
-
# Mixlib::CLI's design :(
|
28
|
-
def self.included(includer)
|
29
|
-
includer.class_eval do
|
30
|
-
|
31
|
-
deps do
|
32
|
-
require 'fog'
|
33
|
-
require 'readline'
|
34
|
-
require 'chef/json_compat'
|
35
|
-
end
|
36
|
-
|
37
|
-
option :cloudstack_access_key_id,
|
38
|
-
:short => "-A ID",
|
39
|
-
:long => "--cloudstack-access-key-id KEY",
|
40
|
-
:description => "Your Cloudstack Access Key ID",
|
41
|
-
:proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey }
|
42
|
-
|
43
|
-
option :cloudstack_secret_access_key,
|
44
|
-
:short => "-K SECRET",
|
45
|
-
:long => "--cloudstack-secret-access-key SECRET",
|
46
|
-
:description => "Your Cloudstack API Secret Access Key",
|
47
|
-
:proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey }
|
48
|
-
|
49
|
-
option :cloudstack_api_endpoint,
|
50
|
-
:long => "--cloudstack-api-endpoint ENDPOINT",
|
51
|
-
:description => "Your Cloudstack API endpoint",
|
52
|
-
:proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def connection
|
57
|
-
@connection ||= begin
|
58
|
-
cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint])
|
59
|
-
connection = Fog::Compute.new(
|
60
|
-
:provider => :cloudstack,
|
61
|
-
:cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id],
|
62
|
-
:cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key],
|
63
|
-
:cloudstack_host => cloudstack_uri.host,
|
64
|
-
:cloudstack_port => cloudstack_uri.port,
|
65
|
-
:cloudstack_path => cloudstack_uri.path,
|
66
|
-
:cloudstack_scheme => cloudstack_uri.scheme
|
67
|
-
)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def locate_config_value(key)
|
72
|
-
key = key.to_sym
|
73
|
-
Chef::Config[:knife][key] || config[key]
|
74
|
-
end
|
75
|
-
|
76
|
-
def msg_pair(label, value, color=:cyan)
|
77
|
-
if value && !value.to_s.empty?
|
78
|
-
puts "#{ui.color(label, color)}: #{value}"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint])
|
83
|
-
errors = []
|
84
|
-
|
85
|
-
keys.each do |k|
|
86
|
-
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
|
87
|
-
if Chef::Config[:knife][k].nil?
|
88
|
-
errors << "You did not provided a valid '#{pretty_key}' value."
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
if errors.each{|e| ui.error(e)}.any?
|
93
|
-
exit 1
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
|
1
|
+
#
|
2
|
+
# Author:: Chirag Jog (<chirag@clogeny.com>), Jeff Moody (<jmoody@datapipe.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Clogeny Technologies, Copyright (c) 2012 Datapipe
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
module CloudstackBase
|
24
|
+
|
25
|
+
# :nodoc:
|
26
|
+
# Would prefer to do this in a rational way, but can't be done b/c of
|
27
|
+
# Mixlib::CLI's design :(
|
28
|
+
def self.included(includer)
|
29
|
+
includer.class_eval do
|
30
|
+
|
31
|
+
deps do
|
32
|
+
require 'fog'
|
33
|
+
require 'readline'
|
34
|
+
require 'chef/json_compat'
|
35
|
+
end
|
36
|
+
|
37
|
+
option :cloudstack_access_key_id,
|
38
|
+
:short => "-A ID",
|
39
|
+
:long => "--cloudstack-access-key-id KEY",
|
40
|
+
:description => "Your Cloudstack Access Key ID",
|
41
|
+
:proc => Proc.new { |pkey| Chef::Config[:knife][:cloudstack_access_key_id] = pkey }
|
42
|
+
|
43
|
+
option :cloudstack_secret_access_key,
|
44
|
+
:short => "-K SECRET",
|
45
|
+
:long => "--cloudstack-secret-access-key SECRET",
|
46
|
+
:description => "Your Cloudstack API Secret Access Key",
|
47
|
+
:proc => Proc.new { |skey| Chef::Config[:knife][:cloudstack_secret_access_key] = skey }
|
48
|
+
|
49
|
+
option :cloudstack_api_endpoint,
|
50
|
+
:long => "--cloudstack-api-endpoint ENDPOINT",
|
51
|
+
:description => "Your Cloudstack API endpoint",
|
52
|
+
:proc => Proc.new { |endpoint| Chef::Config[:knife][:cloudstack_api_endpoint] = endpoint }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def connection
|
57
|
+
@connection ||= begin
|
58
|
+
cloudstack_uri = URI.parse(Chef::Config[:knife][:cloudstack_api_endpoint])
|
59
|
+
connection = Fog::Compute.new(
|
60
|
+
:provider => :cloudstack,
|
61
|
+
:cloudstack_api_key => Chef::Config[:knife][:cloudstack_access_key_id],
|
62
|
+
:cloudstack_secret_access_key => Chef::Config[:knife][:cloudstack_secret_access_key],
|
63
|
+
:cloudstack_host => cloudstack_uri.host,
|
64
|
+
:cloudstack_port => cloudstack_uri.port,
|
65
|
+
:cloudstack_path => cloudstack_uri.path,
|
66
|
+
:cloudstack_scheme => cloudstack_uri.scheme
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def locate_config_value(key)
|
72
|
+
key = key.to_sym
|
73
|
+
Chef::Config[:knife][key] || config[key]
|
74
|
+
end
|
75
|
+
|
76
|
+
def msg_pair(label, value, color=:cyan)
|
77
|
+
if value && !value.to_s.empty?
|
78
|
+
puts "#{ui.color(label, color)}: #{value}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def validate!(keys=[:cloudstack_access_key_id, :cloudstack_secret_access_key, :cloudstack_api_endpoint])
|
83
|
+
errors = []
|
84
|
+
|
85
|
+
keys.each do |k|
|
86
|
+
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)|(aws)/i) ? w.upcase : w.capitalize }
|
87
|
+
if Chef::Config[:knife][k].nil?
|
88
|
+
errors << "You did not provided a valid '#{pretty_key}' value."
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
if errors.each{|e| ui.error(e)}.any?
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
|
@@ -1,57 +1,57 @@
|
|
1
|
-
# Author:: Jeff Moody (<jmoody@datapipe.com>)
|
2
|
-
# Copyright:: Copyright (c) 2012 Datapipe
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
require 'chef/knife/cloudstack_base'
|
20
|
-
|
21
|
-
class Chef
|
22
|
-
class Knife
|
23
|
-
class CloudstackDiskofferingList < Knife
|
24
|
-
|
25
|
-
include Knife::CloudstackBase
|
26
|
-
|
27
|
-
banner "knife cloudstack diskoffering list"
|
28
|
-
|
29
|
-
def run
|
30
|
-
$stdout.sync = true
|
31
|
-
|
32
|
-
validate!
|
33
|
-
|
34
|
-
diskoffering_list = [
|
35
|
-
ui.color('ID', :bold),
|
36
|
-
ui.color('Name', :bold),
|
37
|
-
ui.color('Description', :bold),
|
38
|
-
ui.color('Disk Size (in GB)', :bold)
|
39
|
-
]
|
40
|
-
response = connection.list_disk_offerings['listdiskofferingsresponse']
|
41
|
-
if diskofferings = response['diskoffering']
|
42
|
-
diskofferings.each do |diskoffering|
|
43
|
-
diskoffering_list << diskoffering['id'].to_s
|
44
|
-
diskoffering_list << diskoffering['name'].to_s
|
45
|
-
diskoffering_list << diskoffering['displaytext'].to_s
|
46
|
-
disk_size = diskoffering['disksize']
|
47
|
-
diskoffering_list << disk_size.to_s
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
puts ui.list(diskoffering_list, :columns_across, 4)
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
1
|
+
# Author:: Jeff Moody (<jmoody@datapipe.com>)
|
2
|
+
# Copyright:: Copyright (c) 2012 Datapipe
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
require 'chef/knife/cloudstack_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class CloudstackDiskofferingList < Knife
|
24
|
+
|
25
|
+
include Knife::CloudstackBase
|
26
|
+
|
27
|
+
banner "knife cloudstack diskoffering list"
|
28
|
+
|
29
|
+
def run
|
30
|
+
$stdout.sync = true
|
31
|
+
|
32
|
+
validate!
|
33
|
+
|
34
|
+
diskoffering_list = [
|
35
|
+
ui.color('ID', :bold),
|
36
|
+
ui.color('Name', :bold),
|
37
|
+
ui.color('Description', :bold),
|
38
|
+
ui.color('Disk Size (in GB)', :bold)
|
39
|
+
]
|
40
|
+
response = connection.list_disk_offerings['listdiskofferingsresponse']
|
41
|
+
if diskofferings = response['diskoffering']
|
42
|
+
diskofferings.each do |diskoffering|
|
43
|
+
diskoffering_list << diskoffering['id'].to_s
|
44
|
+
diskoffering_list << diskoffering['name'].to_s
|
45
|
+
diskoffering_list << diskoffering['displaytext'].to_s
|
46
|
+
disk_size = diskoffering['disksize']
|
47
|
+
diskoffering_list << disk_size.to_s
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
puts ui.list(diskoffering_list, :columns_across, 4)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,102 +1,102 @@
|
|
1
|
-
# Author:: Takashi Kanai (<anikundesu@gmail.com>)
|
2
|
-
# Copyright:: Copyright (c) 2012 IDC Frontier Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
require 'chef/knife/cloudstack_base'
|
20
|
-
|
21
|
-
class Chef
|
22
|
-
class Knife
|
23
|
-
class CloudstackKeypairCreate < Knife
|
24
|
-
|
25
|
-
include Knife::CloudstackBase
|
26
|
-
|
27
|
-
banner "knife cloudstack keypair create -k NAME (options)"
|
28
|
-
|
29
|
-
option :name,
|
30
|
-
:short => "-k KEYPAIR",
|
31
|
-
:long => "--keypair KEYPAIR",
|
32
|
-
:description => "The name of the Key Pair to create."
|
33
|
-
|
34
|
-
option :publickey,
|
35
|
-
:short => "-p publickey",
|
36
|
-
:long => "--public-key publickey",
|
37
|
-
:description => "The public key to register."
|
38
|
-
|
39
|
-
option :outfile,
|
40
|
-
:short => "-o FILENAME",
|
41
|
-
:long => "--out-file FILENAME",
|
42
|
-
:description => "The output filename of created private key."
|
43
|
-
|
44
|
-
def run
|
45
|
-
$stdout.sync = true
|
46
|
-
|
47
|
-
validate!
|
48
|
-
|
49
|
-
options = {}
|
50
|
-
if locate_config_value(:publickey) != nil
|
51
|
-
options['publickey'] = locate_config_value(:publickey)
|
52
|
-
mode = 'register'
|
53
|
-
if locate_config_value(:name) != nil
|
54
|
-
options['name'] = locate_config_value(:name)
|
55
|
-
end
|
56
|
-
else
|
57
|
-
mode = 'create'
|
58
|
-
if locate_config_value(:name) != nil
|
59
|
-
keypair_name = locate_config_value(:name)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
case mode
|
64
|
-
when 'register'
|
65
|
-
response = connection.register_ssh_key_pair(options)
|
66
|
-
sshkeypair = response['registersshkeypairresponse']['keypair']
|
67
|
-
|
68
|
-
sshkeypair_list = [
|
69
|
-
ui.color('Name', :bold),
|
70
|
-
ui.color('Fingerprint', :bold),
|
71
|
-
ui.color('Private Key', :bold)
|
72
|
-
]
|
73
|
-
|
74
|
-
sshkeypair_list << sshkeypair['name'].to_s
|
75
|
-
sshkeypair_list << sshkeypair['fingerprint'].to_s
|
76
|
-
sshkeypair_list << sshkeypair['privatekey'].to_s
|
77
|
-
puts ui.list(sshkeypair_list, :columns_across, 3)
|
78
|
-
when 'create'
|
79
|
-
response = connection.create_ssh_key_pair(keypair_name,options)
|
80
|
-
sshkeypair = response['createsshkeypairresponse']['keypair']
|
81
|
-
|
82
|
-
if locate_config_value(:outfile) != nil
|
83
|
-
output = locate_config_value(:outfile)
|
84
|
-
File.open(output,'w'){|f|
|
85
|
-
f.print sshkeypair['privatekey'].to_s
|
86
|
-
}
|
87
|
-
else
|
88
|
-
sshkeypair_list = [
|
89
|
-
ui.color('Private Key', :bold)
|
90
|
-
]
|
91
|
-
sshkeypair_list << sshkeypair['privatekey'].to_s
|
92
|
-
puts ui.list(sshkeypair_list, :columns_across, 3)
|
93
|
-
end
|
94
|
-
else
|
95
|
-
puts 'Error. Missing Keypair Name (-k) option.'
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
1
|
+
# Author:: Takashi Kanai (<anikundesu@gmail.com>)
|
2
|
+
# Copyright:: Copyright (c) 2012 IDC Frontier Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
require 'chef/knife/cloudstack_base'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class CloudstackKeypairCreate < Knife
|
24
|
+
|
25
|
+
include Knife::CloudstackBase
|
26
|
+
|
27
|
+
banner "knife cloudstack keypair create -k NAME (options)"
|
28
|
+
|
29
|
+
option :name,
|
30
|
+
:short => "-k KEYPAIR",
|
31
|
+
:long => "--keypair KEYPAIR",
|
32
|
+
:description => "The name of the Key Pair to create."
|
33
|
+
|
34
|
+
option :publickey,
|
35
|
+
:short => "-p publickey",
|
36
|
+
:long => "--public-key publickey",
|
37
|
+
:description => "The public key to register."
|
38
|
+
|
39
|
+
option :outfile,
|
40
|
+
:short => "-o FILENAME",
|
41
|
+
:long => "--out-file FILENAME",
|
42
|
+
:description => "The output filename of created private key."
|
43
|
+
|
44
|
+
def run
|
45
|
+
$stdout.sync = true
|
46
|
+
|
47
|
+
validate!
|
48
|
+
|
49
|
+
options = {}
|
50
|
+
if locate_config_value(:publickey) != nil
|
51
|
+
options['publickey'] = locate_config_value(:publickey)
|
52
|
+
mode = 'register'
|
53
|
+
if locate_config_value(:name) != nil
|
54
|
+
options['name'] = locate_config_value(:name)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
mode = 'create'
|
58
|
+
if locate_config_value(:name) != nil
|
59
|
+
keypair_name = locate_config_value(:name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
case mode
|
64
|
+
when 'register'
|
65
|
+
response = connection.register_ssh_key_pair(options)
|
66
|
+
sshkeypair = response['registersshkeypairresponse']['keypair']
|
67
|
+
|
68
|
+
sshkeypair_list = [
|
69
|
+
ui.color('Name', :bold),
|
70
|
+
ui.color('Fingerprint', :bold),
|
71
|
+
ui.color('Private Key', :bold)
|
72
|
+
]
|
73
|
+
|
74
|
+
sshkeypair_list << sshkeypair['name'].to_s
|
75
|
+
sshkeypair_list << sshkeypair['fingerprint'].to_s
|
76
|
+
sshkeypair_list << sshkeypair['privatekey'].to_s
|
77
|
+
puts ui.list(sshkeypair_list, :columns_across, 3)
|
78
|
+
when 'create'
|
79
|
+
response = connection.create_ssh_key_pair(keypair_name,options)
|
80
|
+
sshkeypair = response['createsshkeypairresponse']['keypair']
|
81
|
+
|
82
|
+
if locate_config_value(:outfile) != nil
|
83
|
+
output = locate_config_value(:outfile)
|
84
|
+
File.open(output,'w'){|f|
|
85
|
+
f.print sshkeypair['privatekey'].to_s
|
86
|
+
}
|
87
|
+
else
|
88
|
+
sshkeypair_list = [
|
89
|
+
ui.color('Private Key', :bold)
|
90
|
+
]
|
91
|
+
sshkeypair_list << sshkeypair['privatekey'].to_s
|
92
|
+
puts ui.list(sshkeypair_list, :columns_across, 3)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts 'Error. Missing Keypair Name (-k) option.'
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|