knife-vcloud 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
  Changes
2
+ ==
3
+ 2012-12-27 (0.2.1)
4
+ --
5
+
6
+ FIXES:
7
+ * Change namespace to fix import error under 1.9.x (system-wide)
8
+
2
9
  ==
3
10
  2012-12-24 (0.2.0)
4
11
  --
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- knife-vcloud
1
+ knife-vcloud [![Dependency Status](https://gemnasium.com/astratto/knife-vcloud.png)](https://gemnasium.com/astratto/knife-vcloud)
2
2
  ===========
3
3
 
4
4
  DESCRIPTION
@@ -16,73 +16,40 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
19
+ require 'chef/knife/vc_common'
20
20
 
21
- module KnifeVCloud
22
- class VcCatalogItemShow < Chef::Knife
23
- include KnifeVCloud::Common
21
+ class Chef
22
+ class Knife
23
+ class VcCatalogItemShow < Chef::Knife
24
+ include Knife::VcCommon
24
25
 
25
- deps do
26
- require 'vcloud-rest/connection'
27
- require 'chef/api_client'
28
- end
29
-
30
- banner "knife vc catalog item show [CATALOG_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 }
26
+ banner "knife vc catalog item show [CATALOG_ID] (options)"
43
27
 
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 }
28
+ def run
29
+ $stdout.sync = true
49
30
 
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 }
31
+ item_id = @name_args.first
55
32
 
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 }
33
+ connection.login
61
34
 
62
- def run
63
- $stdout.sync = true
35
+ header = [
36
+ ui.color('Name', :bold),
37
+ ui.color('Template ID', :bold)
38
+ ]
64
39
 
65
- item_id = @name_args.first
40
+ description, items = connection.show_catalog_item item_id
41
+ connection.logout
66
42
 
67
- connection.login
43
+ puts "#{ui.color('Description:', :cyan)} #{description}"
44
+ list = header
45
+ list.flatten!
46
+ items.each do |k, v|
47
+ list << (k || '')
48
+ list << (v || '')
49
+ end
68
50
 
69
- header = [
70
- ui.color('Name', :bold),
71
- ui.color('Template ID', :bold)
72
- ]
73
-
74
- description, items = connection.show_catalog_item item_id
75
- connection.logout
76
-
77
- puts "#{ui.color('Description:', :cyan)} #{description}"
78
- list = header
79
- list.flatten!
80
- items.each do |k, v|
81
- list << (k || '')
82
- list << (v || '')
51
+ puts ui.list(list, :columns_across, 2)
83
52
  end
84
-
85
- puts ui.list(list, :columns_across, 2)
86
53
  end
87
54
  end
88
55
  end
@@ -16,73 +16,40 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
19
+ require 'chef/knife/vc_common'
20
20
 
21
- module KnifeVCloud
22
- class VcCatalogShow < Chef::Knife
23
- include KnifeVCloud::Common
21
+ class Chef
22
+ class Knife
23
+ class VcCatalogShow < Chef::Knife
24
+ include Knife::VcCommon
24
25
 
25
- deps do
26
- require 'vcloud-rest/connection'
27
- require 'chef/api_client'
28
- end
29
-
30
- banner "knife vc catalog show [CATALOG_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 }
26
+ banner "knife vc catalog show [CATALOG_ID] (options)"
43
27
 
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 }
28
+ def run
29
+ $stdout.sync = true
49
30
 
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 }
31
+ catalog_id = @name_args.first
55
32
 
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 }
33
+ connection.login
61
34
 
62
- def run
63
- $stdout.sync = true
35
+ header = [
36
+ ui.color('Name', :bold),
37
+ ui.color('ID', :bold)
38
+ ]
64
39
 
65
- catalog_id = @name_args.first
40
+ description, items = connection.show_catalog catalog_id
41
+ connection.logout
66
42
 
67
- connection.login
43
+ puts "#{ui.color('Description:', :cyan)} #{description}"
44
+ list = header
45
+ list.flatten!
46
+ items.each do |k, v|
47
+ list << (k || '')
48
+ list << (v || '')
49
+ end
68
50
 
69
- header = [
70
- ui.color('Name', :bold),
71
- ui.color('ID', :bold)
72
- ]
73
-
74
- description, items = connection.show_catalog catalog_id
75
- connection.logout
76
-
77
- puts "#{ui.color('Description:', :cyan)} #{description}"
78
- list = header
79
- list.flatten!
80
- items.each do |k, v|
81
- list << (k || '')
82
- list << (v || '')
51
+ puts ui.list(list, :columns_across, 2)
83
52
  end
84
-
85
- puts ui.list(list, :columns_across, 2)
86
53
  end
87
54
  end
88
55
  end
@@ -0,0 +1,103 @@
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
+ class Chef
22
+ class Knife
23
+ # Module for operations common among commands
24
+ module VcCommon
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 'vcloud-rest/connection'
33
+ require 'chef/api_client'
34
+ end
35
+
36
+ option :vcloud_url,
37
+ :short => "-H URL",
38
+ :long => "--vcloud-url URL",
39
+ :description => "The vCloud endpoint URL",
40
+ :proc => Proc.new { |url| Chef::Config[:knife][:vcloud_url] = url }
41
+
42
+ option :vcloud_user,
43
+ :short => "-U USER",
44
+ :long => "--vcloud-user USER",
45
+ :description => "Your vCloud User",
46
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_user] = key }
47
+
48
+ option :vcloud_password,
49
+ :short => "-P SECRET",
50
+ :long => "--vcloud-password SECRET",
51
+ :description => "Your vCloud secret key",
52
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_password] = key }
53
+
54
+ option :vcloud_org,
55
+ :short => "-O ORGANIZATION",
56
+ :long => "--vcloud-organization ORGANIZATION",
57
+ :description => "Your vCloud Organization",
58
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
59
+
60
+ option :vcloud_api_version,
61
+ :short => "-A API_VERSION",
62
+ :long => "--vcloud-api-version API_VERSION",
63
+ :description => "vCloud API version (1.5 and 5.1 supported)",
64
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_api_version] = key }
65
+ end
66
+ end
67
+
68
+ def connection
69
+ unless @connection
70
+ @connection = VCloudClient::Connection.new(
71
+ locate_config_value(:vcloud_url),
72
+ locate_config_value(:vcloud_user),
73
+ locate_config_value(:vcloud_password),
74
+ locate_config_value(:vcloud_org),
75
+ locate_config_value(:vcloud_api_version)
76
+ )
77
+ end
78
+ @connection
79
+ end
80
+
81
+ def out_msg(label, value)
82
+ if value && !value.empty?
83
+ puts "#{ui.color(label, :cyan)}: #{value}"
84
+ end
85
+ end
86
+
87
+ def locate_config_value(key)
88
+ key = key.to_sym
89
+ Chef::Config[:knife][key] || config[key]
90
+ end
91
+
92
+ def wait_task(connection, task_id)
93
+ status, errormsg, start_time, end_time = connection.wait_task_completion task_id
94
+ puts "Done!"
95
+ out_msg("Summary", "Status: #{ui.color(status, :cyan)} - started at #{start_time} and ended at #{end_time}")
96
+
97
+ if errormsg
98
+ puts ui.color("ATTENTION: #{errormsg}", :red)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -16,56 +16,23 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
19
+ require 'chef/knife/vc_common'
20
20
 
21
- module KnifeVCloud
22
- class VcLogin < Chef::Knife
23
- include KnifeVCloud::Common
21
+ class Chef
22
+ class Knife
23
+ class VcLogin < Chef::Knife
24
+ include Knife::VcCommon
24
25
 
25
- deps do
26
- require 'vcloud-rest/connection'
27
- require 'chef/api_client'
28
- end
29
-
30
- banner "knife vc login (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 }
26
+ banner "knife vc login (options)"
61
27
 
62
- def run
63
- $stdout.sync = true
28
+ def run
29
+ $stdout.sync = true
64
30
 
65
- connection.login
66
- out_msg("Authenticated successfully, code", connection.auth_key)
31
+ connection.login
32
+ out_msg("Authenticated successfully, code", connection.auth_key)
67
33
 
68
- connection.logout
34
+ connection.logout
35
+ end
69
36
  end
70
37
  end
71
- end
38
+ end
@@ -16,66 +16,33 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
19
+ require 'chef/knife/vc_common'
20
20
 
21
- module KnifeVCloud
22
- class VcOrgList < Chef::Knife
23
- include KnifeVCloud::Common
21
+ class Chef
22
+ class Knife
23
+ class VcOrgList < Chef::Knife
24
+ include Knife::VcCommon
24
25
 
25
- deps do
26
- require 'vcloud-rest/connection'
27
- require 'chef/api_client'
28
- end
29
-
30
- banner "knife vc org list (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 }
26
+ banner "knife vc org list (options)"
61
27
 
62
- def run
63
- $stdout.sync = true
28
+ def run
29
+ $stdout.sync = true
64
30
 
65
- list = [
66
- ui.color('Name', :bold),
67
- ui.color('ID', :bold)
68
- ]
31
+ list = [
32
+ ui.color('Name', :bold),
33
+ ui.color('ID', :bold)
34
+ ]
69
35
 
70
- connection.login
71
- org_list = connection.list_organizations
72
- connection.logout
36
+ connection.login
37
+ org_list = connection.list_organizations
38
+ connection.logout
73
39
 
74
- org_list.each do |k, v|
75
- list << (k || '')
76
- list << (v || '')
40
+ org_list.each do |k, v|
41
+ list << (k || '')
42
+ list << (v || '')
43
+ end
44
+ puts ui.list(list, :columns_across, 2)
77
45
  end
78
- puts ui.list(list, :columns_across, 2)
79
46
  end
80
47
  end
81
48
  end
@@ -16,97 +16,64 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife'
20
-
21
- module KnifeVCloud
22
- class VcOrgShow < 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 org show [ORG_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
- org_id = @name_args.first
66
-
67
- connection.login
68
-
69
- header = [
70
- ui.color('Name', :bold),
71
- ui.color('ID', :bold)
72
- ]
73
-
74
- catalogs, vdcs, networks, tasklists = connection.show_organization org_id
75
- connection.logout
76
-
77
- list = ["#{ui.color('CATALOGS', :cyan)}", '']
78
- list << header
79
- list.flatten!
80
- catalogs.each do |k, v|
81
- list << (k || '')
82
- list << (v || '')
83
- end
84
-
85
- list << ['', '', "#{ui.color('VDCs', :cyan)}", '']
86
- list << header
87
- list.flatten!
88
- vdcs.each do |k, v|
89
- list << (k || '')
90
- list << (v || '')
19
+ require 'chef/knife/vc_common'
20
+
21
+ class Chef
22
+ class Knife
23
+ class VcOrgShow < Chef::Knife
24
+ include Knife::VcCommon
25
+
26
+ banner "knife vc org show [ORG_ID] (options)"
27
+
28
+ def run
29
+ $stdout.sync = true
30
+
31
+ org_id = @name_args.first
32
+
33
+ connection.login
34
+
35
+ header = [
36
+ ui.color('Name', :bold),
37
+ ui.color('ID', :bold)
38
+ ]
39
+
40
+ catalogs, vdcs, networks, tasklists = connection.show_organization org_id
41
+ connection.logout
42
+
43
+ list = ["#{ui.color('CATALOGS', :cyan)}", '']
44
+ list << header
45
+ list.flatten!
46
+ catalogs.each do |k, v|
47
+ list << (k || '')
48
+ list << (v || '')
49
+ end
50
+
51
+ list << ['', '', "#{ui.color('VDCs', :cyan)}", '']
52
+ list << header
53
+ list.flatten!
54
+ vdcs.each do |k, v|
55
+ list << (k || '')
56
+ list << (v || '')
57
+ end
58
+
59
+ list << ['', '', "#{ui.color('NETWORKS', :cyan)}", '']
60
+ list << header
61
+ list.flatten!
62
+ networks.each do |k, v|
63
+ list << (k || '')
64
+ list << (v || '')
65
+ end
66
+
67
+ list << ['', '', "#{ui.color('TASKLISTS', :cyan)}", '']
68
+ list << header
69
+ list.flatten!
70
+ tasklists.each do |k, v|
71
+ list << (k || '<unnamed list>')
72
+ list << (v || '')
73
+ end
74
+
75
+ puts ui.list(list, :columns_across, 2)
91
76
  end
92
-
93
- list << ['', '', "#{ui.color('NETWORKS', :cyan)}", '']
94
- list << header
95
- list.flatten!
96
- networks.each do |k, v|
97
- list << (k || '')
98
- list << (v || '')
99
- end
100
-
101
- list << ['', '', "#{ui.color('TASKLISTS', :cyan)}", '']
102
- list << header
103
- list.flatten!
104
- tasklists.each do |k, v|
105
- list << (k || '<unnamed list>')
106
- list << (v || '')
107
- end
108
-
109
- puts ui.list(list, :columns_across, 2)
110
77
  end
111
78
  end
112
- end
79
+ end