knife-vcloud 0.2.3 → 1.0.0

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +44 -1
  3. data/README.md +356 -91
  4. data/lib/chef/knife/{vc_catalog_item_show.rb → catalog/vc_catalog_item_show.rb} +13 -13
  5. data/lib/chef/knife/{vc_catalog_show.rb → catalog/vc_catalog_show.rb} +9 -12
  6. data/lib/chef/knife/common/vc_bootstrap_common.rb +208 -0
  7. data/lib/chef/knife/common/vc_catalog_common.rb +58 -0
  8. data/lib/chef/knife/common/vc_common.rb +165 -0
  9. data/lib/chef/knife/common/vc_network_common.rb +34 -0
  10. data/lib/chef/knife/common/vc_vapp_common.rb +49 -0
  11. data/lib/chef/knife/common/vc_vdc_common.rb +43 -0
  12. data/lib/chef/knife/common/vc_vm_common.rb +80 -0
  13. data/lib/chef/knife/network/vc_network_show.rb +45 -0
  14. data/lib/chef/knife/{vc_org_list.rb → org/vc_org_list.rb} +3 -5
  15. data/lib/chef/knife/{vc_org_show.rb → org/vc_org_show.rb} +10 -11
  16. data/lib/chef/knife/ovf/vc_ovf_upload.rb +71 -0
  17. data/lib/chef/knife/vapp/vc_vapp_bootstrap.rb +51 -0
  18. data/lib/chef/knife/vapp/vc_vapp_clone.rb +80 -0
  19. data/lib/chef/knife/{vc_vapp_create.rb → vapp/vc_vapp_create.rb} +10 -9
  20. data/lib/chef/knife/{vc_vapp_delete.rb → vapp/vc_vapp_delete.rb} +12 -10
  21. data/lib/chef/knife/vapp/vc_vapp_network_external.rb +101 -0
  22. data/lib/chef/knife/vapp/vc_vapp_network_internal.rb +151 -0
  23. data/lib/chef/knife/vapp/vc_vapp_reboot.rb +45 -0
  24. data/lib/chef/knife/vapp/vc_vapp_reset.rb +44 -0
  25. data/lib/chef/knife/vapp/vc_vapp_show.rb +90 -0
  26. data/lib/chef/knife/vapp/vc_vapp_snapshot.rb +58 -0
  27. data/lib/chef/knife/{vc_vapp_start.rb → vapp/vc_vapp_start.rb} +7 -7
  28. data/lib/chef/knife/{vc_vapp_stop.rb → vapp/vc_vapp_stop.rb} +7 -7
  29. data/lib/chef/knife/vapp/vc_vapp_suspend.rb +44 -0
  30. data/lib/chef/knife/vc_commands.rb +70 -0
  31. data/lib/chef/knife/vc_login.rb +2 -2
  32. data/lib/chef/knife/{vc_vdc_show.rb → vdc/vc_vdc_show.rb} +13 -14
  33. data/lib/chef/knife/vm/vc_vm_bootstrap.rb +48 -0
  34. data/lib/chef/knife/vm/vc_vm_config_guest.rb +110 -0
  35. data/lib/chef/knife/{vc_vm_config_network.rb → vm/vc_vm_config_network.rb} +17 -11
  36. data/lib/chef/knife/vm/vc_vm_reboot.rb +44 -0
  37. data/lib/chef/knife/vm/vc_vm_reset.rb +44 -0
  38. data/lib/chef/knife/vm/vc_vm_set_disks.rb +78 -0
  39. data/lib/chef/knife/vm/vc_vm_set_info.rb +79 -0
  40. data/lib/chef/knife/{vc_vm_show.rb → vm/vc_vm_show.rb} +35 -18
  41. data/lib/chef/knife/vm/vc_vm_start.rb +44 -0
  42. data/lib/chef/knife/vm/vc_vm_stop.rb +44 -0
  43. data/lib/chef/knife/vm/vc_vm_suspend.rb +44 -0
  44. data/lib/knife-vcloud/version.rb +3 -0
  45. metadata +69 -38
  46. data/lib/chef/knife/vc_common.rb +0 -103
  47. data/lib/chef/knife/vc_vapp_config_network.rb +0 -63
  48. data/lib/chef/knife/vc_vapp_show.rb +0 -59
  49. data/lib/chef/knife/vc_vm_config_guest.rb +0 -67
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ module VcNetworkCommon
22
+ def get_network(network_arg)
23
+ network = nil
24
+ org_name = locate_org_option
25
+
26
+ org = connection.get_organization_by_name org_name
27
+ network = connection.get_network_by_name org, network_arg
28
+
29
+ raise ArgumentError, "Network #{network_arg} not found" unless network
30
+ network
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ module VcVappCommon
22
+
23
+ def self.included(includer)
24
+ includer.class_eval do
25
+ option :vcloud_vdc,
26
+ :long => "--vdc VDC_NAME",
27
+ :description => "VDC to whom vApp belongs",
28
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_vdc] = key }
29
+ end
30
+ end
31
+
32
+ def get_vapp(vapp_arg)
33
+ vapp = nil
34
+ vdc_name = locate_config_value(:vcloud_vdc)
35
+
36
+ unless vdc_name
37
+ notice_msg("--vdc not specified, assuming VAPP is an ID")
38
+ vapp = connection.get_vapp vapp_arg
39
+ else
40
+ org_name = locate_org_option
41
+ org = connection.get_organization_by_name org_name
42
+ vapp = connection.get_vapp_by_name org, vdc_name, vapp_arg
43
+ end
44
+ raise ArgumentError, "VApp #{vapp_arg} not found" unless vapp
45
+ vapp
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ module VcVDCCommon
22
+ def self.included(includer)
23
+ includer.class_eval do
24
+ option :vcloud_org,
25
+ :long => "--org ORG_NAME",
26
+ :description => "Organization to whom VDC belongs",
27
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_org] = key }
28
+ end
29
+ end
30
+
31
+ def get_vdc(vdc_arg)
32
+ vdc = nil
33
+ org_name = locate_org_option
34
+
35
+ org = connection.get_organization_by_name org_name
36
+ vdc = connection.get_vdc_by_name org, vdc_arg
37
+
38
+ raise ArgumentError, "VDC #{vdc_arg} not found" unless vdc
39
+ vdc
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,80 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ module VcVmCommon
22
+
23
+ def self.included(includer)
24
+ includer.class_eval do
25
+ option :vcloud_vdc,
26
+ :long => "--vdc VDC_NAME",
27
+ :description => "VDC to whom VM's vApp belongs",
28
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_vdc] = key }
29
+
30
+ option :vcloud_vapp,
31
+ :long => "--vapp VAPP_NAME",
32
+ :description => "vApp to whom VM belongs",
33
+ :proc => Proc.new { |key| Chef::Config[:knife][:vcloud_vapp] = key }
34
+ end
35
+ end
36
+
37
+ def get_vm(vm_arg)
38
+ vm = nil
39
+ vapp_name = locate_config_value(:vcloud_vapp)
40
+ org_name = locate_org_option
41
+ vdc_name = locate_config_value(:vcloud_vdc)
42
+
43
+ unless vdc_name && vapp_name
44
+ notice_msg("--vapp and --vdc not specified, assuming VM is an ID")
45
+ vm = connection.get_vm vm_arg
46
+ else
47
+ org = connection.get_organization_by_name org_name
48
+ vm = connection.get_vm_by_name org, vdc_name, vapp_name, vm_arg
49
+ end
50
+ raise ArgumentError, "VM #{vm_arg} not found" unless vm
51
+ vm
52
+ end
53
+
54
+ # Accept only characters and hyphens
55
+ #
56
+ # Underscores are converted to hyphens
57
+ def sanitize_guest_name(name)
58
+ name.gsub(/_/, '-').gsub(/[^[0-9]|^[a-z]|^[A-Z]|^-]/, '')
59
+ end
60
+
61
+ # Verify a VM and stop it if it's running
62
+ #
63
+ # Return :nothing if nothing was made
64
+ # :errored for errors
65
+ # :stopped if was stopped
66
+ def stop_if_running(connection, vm)
67
+ if vm[:status] == 'running'
68
+ if ui.confirm("Guest customizations must be applied to a stopped VM, " \
69
+ "but it's running. Can I #{ui.color('STOP', :red)} it")
70
+ ui.msg "Stopping VM..."
71
+ task_id, response = connection.poweroff_vm vm[:id]
72
+ return :errored unless wait_task(connection, task_id)
73
+ end
74
+ return :stopped
75
+ end
76
+ return :nothing
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ class VcNetworkShow < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcNetworkCommon
24
+
25
+ banner "knife vc network show [network] (options)"
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ network_arg = @name_args.shift
31
+ connection.login
32
+ network = get_network(network_arg)
33
+ connection.logout
34
+
35
+ out_msg('ID', network[:id])
36
+ out_msg('Name', network[:name])
37
+ out_msg('Description', network[:description])
38
+ out_msg('Gateway', network[:gateway])
39
+ out_msg('Netmask', network[:netmask])
40
+ out_msg('Fence mode', network[:fence_mode])
41
+ out_msg('IP Range', "#{network[:start_address]} - #{network[:end_address]}")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
- # Copyright:: Copyright (c) 2012
3
+ # Copyright:: Copyright (c) 2012-2013
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,6 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife/vc_common'
20
-
21
19
  class Chef
22
20
  class Knife
23
21
  class VcOrgList < Chef::Knife
@@ -34,14 +32,14 @@ class Chef
34
32
  ]
35
33
 
36
34
  connection.login
37
- org_list = connection.list_organizations
35
+ org_list = connection.get_organizations
38
36
  connection.logout
39
37
 
40
38
  org_list.each do |k, v|
41
39
  list << (k || '')
42
40
  list << (v || '')
43
41
  end
44
- puts ui.list(list, :columns_across, 2)
42
+ ui.msg ui.list(list, :columns_across, 2)
45
43
  end
46
44
  end
47
45
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
- # Copyright:: Copyright (c) 2012
3
+ # Copyright:: Copyright (c) 2012-2013
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,19 +16,17 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife/vc_common'
20
-
21
19
  class Chef
22
20
  class Knife
23
21
  class VcOrgShow < Chef::Knife
24
22
  include Knife::VcCommon
25
23
 
26
- banner "knife vc org show [ORG_ID] (options)"
24
+ banner "knife vc org show (options)"
27
25
 
28
26
  def run
29
27
  $stdout.sync = true
30
28
 
31
- org_id = @name_args.first
29
+ org = locate_org_option
32
30
 
33
31
  connection.login
34
32
 
@@ -37,13 +35,14 @@ class Chef
37
35
  ui.color('ID', :bold)
38
36
  ]
39
37
 
40
- catalogs, vdcs, networks, tasklists = connection.show_organization org_id
38
+ organization = connection.get_organization_by_name org
39
+
41
40
  connection.logout
42
41
 
43
42
  list = ["#{ui.color('CATALOGS', :cyan)}", '']
44
43
  list << header
45
44
  list.flatten!
46
- catalogs.each do |k, v|
45
+ sort_by_key(organization[:catalogs]).each do |k, v|
47
46
  list << (k || '')
48
47
  list << (v || '')
49
48
  end
@@ -51,7 +50,7 @@ class Chef
51
50
  list << ['', '', "#{ui.color('VDCs', :cyan)}", '']
52
51
  list << header
53
52
  list.flatten!
54
- vdcs.each do |k, v|
53
+ sort_by_key(organization[:vdcs]).each do |k, v|
55
54
  list << (k || '')
56
55
  list << (v || '')
57
56
  end
@@ -59,7 +58,7 @@ class Chef
59
58
  list << ['', '', "#{ui.color('NETWORKS', :cyan)}", '']
60
59
  list << header
61
60
  list.flatten!
62
- networks.each do |k, v|
61
+ sort_by_key(organization[:networks]).each do |k, v|
63
62
  list << (k || '')
64
63
  list << (v || '')
65
64
  end
@@ -67,12 +66,12 @@ class Chef
67
66
  list << ['', '', "#{ui.color('TASKLISTS', :cyan)}", '']
68
67
  list << header
69
68
  list.flatten!
70
- tasklists.each do |k, v|
69
+ sort_by_key(organization[:tasklists]).each do |k, v|
71
70
  list << (k || '<unnamed list>')
72
71
  list << (v || '')
73
72
  end
74
73
 
75
- puts ui.list(list, :columns_across, 2)
74
+ ui.msg ui.list(list, :columns_across, 2)
76
75
  end
77
76
  end
78
77
  end
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ class VcOvfUpload < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVDCCommon
24
+ include Knife::VcCatalogCommon
25
+
26
+ banner "knife vc ovf upload VDC CATALOG VAPP_NAME VAPP_DESCRIPTION OVF_FILENAME (options)"
27
+
28
+ option :ovf_show_progress_bar,
29
+ :long => "--[no-]progressbar",
30
+ :description => "Show a progress bar for uploads",
31
+ :proc => Proc.new { |key| Chef::Config[:knife][:ovf_show_progress_bar] = key },
32
+ :boolean => true,
33
+ :default => true
34
+
35
+ option :ovf_send_manifest,
36
+ :long => "--[no-]send-manifest",
37
+ :description => "Send a manifest",
38
+ :boolean => true,
39
+ :default => false
40
+
41
+ def run
42
+ $stdout.sync = true
43
+
44
+ vdc_arg = @name_args.shift
45
+ catalog_arg = @name_args.shift
46
+ vapp_name = @name_args.shift
47
+ vapp_description = @name_args.shift
48
+ ovf_filename = @name_args.shift
49
+
50
+ show_progress_bar = locate_config_value(:ovf_show_progress_bar)
51
+ send_manifest = locate_config_value(:ovf_send_manifest)
52
+
53
+ connection.login
54
+
55
+ vdc = get_vdc(vdc_arg)
56
+ catalog = get_catalog(catalog_arg)
57
+
58
+ ui.msg "Uploading OVF..."
59
+
60
+ result = connection.upload_ovf(vdc[:id], vapp_name,
61
+ vapp_description, ovf_filename, catalog[:id],
62
+ { :send_manifest => send_manifest,
63
+ :progressbar_enable => show_progress_bar})
64
+
65
+ ui.msg "OVF uploaded. vAppTemplate created with ID: #{ui.color(result[:id], :cyan)}"
66
+
67
+ connection.logout
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2013
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
+ class Chef
20
+ class Knife
21
+ class VcVappBootstrap < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVappCommon
24
+ include Knife::VcBootstrapCommon
25
+
26
+ banner "knife vc vapp bootstrap [VAPP] (options)"
27
+
28
+ def run
29
+ $stdout.sync = true
30
+ @test_connection_timeout = 5
31
+
32
+ vapp_arg = @name_args.shift
33
+
34
+ connection.login
35
+
36
+ vapp = get_vapp(vapp_arg)
37
+
38
+ if locate_config_value(:bootstrap_windows)
39
+ ui.msg "Windows bootstrapping is not available, yet."
40
+ else
41
+ vapp[:vms_hash].each do |vm_name, details|
42
+ addresses = details[:addresses].reject(&:nil?)
43
+ bootstrap_vm(vm_name, details[:id], addresses)
44
+ end
45
+ end
46
+
47
+ connection.logout
48
+ end
49
+ end
50
+ end
51
+ end