knife-vcloud 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012
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
+ module KnifeVCloud
22
+ class VcVappStop < Chef::Knife
23
+ include KnifeVCloud::Common
24
+
25
+ deps do
26
+ require 'vcloud-rest/connection'
27
+ require 'chef/api_client'
28
+ end
29
+
30
+ banner "knife vc vapp stop [VAPP_ID] (options)"
31
+
32
+ option :vcloud_url,
33
+ :short => "-H URL",
34
+ :long => "--vcloud-url URL",
35
+ :description => "The vCloud endpoint URL",
36
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
37
+
38
+ option :vcloud_user,
39
+ :short => "-U USER",
40
+ :long => "--vcloud-user USER",
41
+ :description => "Your vCloud User",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
43
+
44
+ option :vcloud_password,
45
+ :short => "-P SECRET",
46
+ :long => "--vcloud-password SECRET",
47
+ :description => "Your vCloud secret key",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
49
+
50
+ option :vcloud_org,
51
+ :short => "-O ORGANIZATION",
52
+ :long => "--vcloud-organization ORGANIZATION",
53
+ :description => "Your vCloud Organization",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
55
+
56
+ option :vcloud_api_version,
57
+ :short => "-A API_VERSION",
58
+ :long => "--vcloud-api-version API_VERSION",
59
+ :description => "vCloud API version (1.5 and 5.1 supported)",
60
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
61
+
62
+ def run
63
+ $stdout.sync = true
64
+
65
+ vapp_id = @name_args.first
66
+
67
+ connection.login
68
+
69
+ task_id = connection.poweroff_vapp vapp_id
70
+
71
+ print "vApp shutdown..."
72
+ wait_task(connection, task_id)
73
+
74
+ connection.logout
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,94 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012
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
+ module KnifeVCloud
22
+ class VcVdcShow < Chef::Knife
23
+ include KnifeVCloud::Common
24
+
25
+ deps do
26
+ require 'vcloud-rest/connection'
27
+ require 'chef/api_client'
28
+ end
29
+
30
+ banner "knife vc vdc show [VDC_ID] (options)"
31
+
32
+ option :vcloud_url,
33
+ :short => "-H URL",
34
+ :long => "--vcloud-url URL",
35
+ :description => "The vCloud endpoint URL",
36
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
37
+
38
+ option :vcloud_user,
39
+ :short => "-U USER",
40
+ :long => "--vcloud-user USER",
41
+ :description => "Your vCloud User",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
43
+
44
+ option :vcloud_password,
45
+ :short => "-P SECRET",
46
+ :long => "--vcloud-password SECRET",
47
+ :description => "Your vCloud secret key",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
49
+
50
+ option :vcloud_org,
51
+ :short => "-O ORGANIZATION",
52
+ :long => "--vcloud-organization ORGANIZATION",
53
+ :description => "Your vCloud Organization",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
55
+
56
+ option :vcloud_api_version,
57
+ :short => "-A API_VERSION",
58
+ :long => "--vcloud-api-version API_VERSION",
59
+ :description => "vCloud API version (1.5 and 5.1 supported)",
60
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
61
+
62
+ def run
63
+ $stdout.sync = true
64
+
65
+ vdc_id = @name_args.first
66
+
67
+ connection.login
68
+
69
+ header = [
70
+ ui.color('Name', :bold),
71
+ ui.color('ID', :bold),
72
+ ui.color('Status', :bold),
73
+ ui.color('IP', :bold),
74
+ ]
75
+
76
+ description, vapps, networks = connection.show_vdc vdc_id
77
+
78
+ puts "#{ui.color('Description:', :cyan)} #{description}"
79
+ list = ["#{ui.color('vAPPS', :cyan)}", '', '', '']
80
+ list << header
81
+ list.flatten!
82
+ vapps.each do |k, v|
83
+ name, description, status, ip, vms_hash = connection.show_vapp v
84
+ list << ("#{k} (#{vms_hash.count} VMs)" || '')
85
+ list << (v || '')
86
+ list << (status || '')
87
+ list << (ip || '')
88
+ end
89
+
90
+ puts ui.list(list, :columns_across, 4)
91
+ connection.logout
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012
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
+ module KnifeVCloud
22
+ class VcVmConfigGuest < Chef::Knife
23
+ include KnifeVCloud::Common
24
+
25
+ deps do
26
+ require 'vcloud-rest/connection'
27
+ require 'chef/api_client'
28
+ end
29
+
30
+ banner "knife vc vm config guest [VAPP_ID] [COMPUTER_NAME] (options)"
31
+
32
+ option :vcloud_url,
33
+ :short => "-H URL",
34
+ :long => "--vcloud-url URL",
35
+ :description => "The vCloud endpoint URL",
36
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
37
+
38
+ option :vcloud_user,
39
+ :short => "-U USER",
40
+ :long => "--vcloud-user USER",
41
+ :description => "Your vCloud User",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
43
+
44
+ option :vcloud_password,
45
+ :short => "-P SECRET",
46
+ :long => "--vcloud-password SECRET",
47
+ :description => "Your vCloud secret key",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
49
+
50
+ option :vcloud_org,
51
+ :short => "-O ORGANIZATION",
52
+ :long => "--vcloud-organization ORGANIZATION",
53
+ :description => "Your vCloud Organization",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
55
+
56
+ option :vcloud_api_version,
57
+ :short => "-A API_VERSION",
58
+ :long => "--vcloud-api-version API_VERSION",
59
+ :description => "vCloud API version (1.5 and 5.1 supported)",
60
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
61
+
62
+ def run
63
+ $stdout.sync = true
64
+
65
+ vm_id = @name_args.shift
66
+ computer_name = @name_args.shift
67
+
68
+ connection.login
69
+
70
+ task_id, response = connection.set_vm_guest_customization vm_id, computer_name, {:enabled => true}
71
+
72
+ puts response
73
+
74
+ print "VM network configuration..."
75
+ wait_task(connection, task_id)
76
+
77
+ connection.logout
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012
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
+ module KnifeVCloud
22
+ class VcVmConfigNetwork < Chef::Knife
23
+ include KnifeVCloud::Common
24
+
25
+ deps do
26
+ require 'vcloud-rest/connection'
27
+ require 'chef/api_client'
28
+ end
29
+
30
+ banner "knife vc vm config network [VAPP_ID] [NETWORK_NAME] (options)"
31
+
32
+ option :vcloud_url,
33
+ :short => "-H URL",
34
+ :long => "--vcloud-url URL",
35
+ :description => "The vCloud endpoint URL",
36
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
37
+
38
+ option :vcloud_user,
39
+ :short => "-U USER",
40
+ :long => "--vcloud-user USER",
41
+ :description => "Your vCloud User",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
43
+
44
+ option :vcloud_password,
45
+ :short => "-P SECRET",
46
+ :long => "--vcloud-password SECRET",
47
+ :description => "Your vCloud secret key",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
49
+
50
+ option :vcloud_org,
51
+ :short => "-O ORGANIZATION",
52
+ :long => "--vcloud-organization ORGANIZATION",
53
+ :description => "Your vCloud Organization",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
55
+
56
+ option :vcloud_api_version,
57
+ :short => "-A API_VERSION",
58
+ :long => "--vcloud-api-version API_VERSION",
59
+ :description => "vCloud API version (1.5 and 5.1 supported)",
60
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
61
+
62
+ def run
63
+ $stdout.sync = true
64
+
65
+ vm_id = @name_args.shift
66
+ network_name = @name_args.shift
67
+
68
+ connection.login
69
+
70
+ task_id, response = connection.set_vm_network_config vm_id, network_name, {:ip_allocation_mode => 'POOL'}
71
+
72
+ puts response
73
+
74
+ print "VM network configuration..."
75
+ wait_task(connection, task_id)
76
+
77
+ connection.logout
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,97 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012
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
+ module KnifeVCloud
22
+ class VcVmShow < Chef::Knife
23
+ include KnifeVCloud::Common
24
+
25
+ deps do
26
+ require 'vcloud-rest/connection'
27
+ require 'chef/api_client'
28
+ end
29
+
30
+ banner "knife vc vm show [VM_ID] (options)"
31
+
32
+ option :vcloud_url,
33
+ :short => "-H URL",
34
+ :long => "--vcloud-url URL",
35
+ :description => "The vCloud endpoint URL",
36
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
37
+
38
+ option :vcloud_user,
39
+ :short => "-U USER",
40
+ :long => "--vcloud-user USER",
41
+ :description => "Your vCloud User",
42
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
43
+
44
+ option :vcloud_password,
45
+ :short => "-P SECRET",
46
+ :long => "--vcloud-password SECRET",
47
+ :description => "Your vCloud secret key",
48
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
49
+
50
+ option :vcloud_org,
51
+ :short => "-O ORGANIZATION",
52
+ :long => "--vcloud-organization ORGANIZATION",
53
+ :description => "Your vCloud Organization",
54
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
55
+
56
+ option :vcloud_api_version,
57
+ :short => "-A API_VERSION",
58
+ :long => "--vcloud-api-version API_VERSION",
59
+ :description => "vCloud API version (1.5 and 5.1 supported)",
60
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
61
+
62
+ def pretty_symbol(key)
63
+ key.to_s.gsub('_', ' ').capitalize
64
+ end
65
+
66
+ def run
67
+ $stdout.sync = true
68
+
69
+ vm_id = @name_args.first
70
+
71
+ list = []
72
+
73
+ connection.login
74
+ os_desc, networks, guest_customizations = connection.show_vm vm_id
75
+ connection.logout
76
+
77
+ msg("OS Name", os_desc)
78
+
79
+ networks.each do |network, values|
80
+ list << ui.color('Network', :bold)
81
+ list << (network || '')
82
+ values.each do |k, v|
83
+ list << (pretty_symbol(k) || '')
84
+ list << (v || '')
85
+ end
86
+ end
87
+
88
+ list << ui.color('Customizations', :bold)
89
+ list << ''
90
+ guest_customizations.each do |k, v|
91
+ list << (pretty_symbol(k) || '')
92
+ list << (v || '')
93
+ end
94
+ puts ui.list(list, :columns_across, 2)
95
+ end
96
+ end
97
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-vcloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stefano Tortarolo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: chef
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: knife-windows
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: vcloud-rest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ description: A Knife plugin to create, list and manage vCloud servers
63
+ email:
64
+ - stefano.tortarolo@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - CHANGELOG.md
70
+ - README.md
71
+ - LICENSE
72
+ - lib/chef/knife/common.rb
73
+ - lib/chef/knife/vc_catalog_item_show.rb
74
+ - lib/chef/knife/vc_catalog_show.rb
75
+ - lib/chef/knife/vc_login.rb
76
+ - lib/chef/knife/vc_org_list.rb
77
+ - lib/chef/knife/vc_org_show.rb
78
+ - lib/chef/knife/vc_vapp_config_network.rb
79
+ - lib/chef/knife/vc_vapp_create.rb
80
+ - lib/chef/knife/vc_vapp_delete.rb
81
+ - lib/chef/knife/vc_vapp_show.rb
82
+ - lib/chef/knife/vc_vapp_start.rb
83
+ - lib/chef/knife/vc_vapp_stop.rb
84
+ - lib/chef/knife/vc_vdc_show.rb
85
+ - lib/chef/knife/vc_vm_config_guest.rb
86
+ - lib/chef/knife/vc_vm_config_network.rb
87
+ - lib/chef/knife/vc_vm_show.rb
88
+ homepage: https://github.com/astratto/knife-vcloud
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: A knife plugin for the VMWare vCloud API
112
+ test_files: []
113
+ has_rdoc: