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,48 @@
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 VcVmBootstrap < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+ include Knife::VcBootstrapCommon
25
+
26
+ banner "knife vc vm bootstrap [VM] (options)"
27
+
28
+ def run
29
+ $stdout.sync = true
30
+ @test_connection_timeout = 5
31
+
32
+ vm_arg = @name_args.shift
33
+
34
+ connection.login
35
+
36
+ vm = get_vm(vm_arg)
37
+
38
+ if locate_config_value(:bootstrap_windows)
39
+ ui.msg "Windows bootstrapping is not available, yet."
40
+ else
41
+ bootstrap_vm(vm[:vm_name], vm[:id], vm[:networks].collect{|k, v| v[:ip]})
42
+ end
43
+
44
+ connection.logout
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,110 @@
1
+ #
2
+ # Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
3
+ # Copyright:: Copyright (c) 2012-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 VcVmConfigGuest < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+
25
+ banner "knife vc vm config guest [VM] (options)"
26
+
27
+ option :guest_enabled,
28
+ :long => "--[no-]guest",
29
+ :description => "Toggle Guest Customization (default true)",
30
+ :boolean => true,
31
+ :default => true
32
+
33
+ option :admin_passwd_enabled,
34
+ :long => "--use-[no-]admin-passwd",
35
+ :description => "Toggle Admin Password (default true)",
36
+ :boolean => true,
37
+ :default => true
38
+
39
+ option :admin_passwd,
40
+ :long => "--admin-passwd ADMIN_PASSWD",
41
+ :description => "Set Admin Password"
42
+
43
+ option :customization_script,
44
+ :long => "--script CUSTOMIZATION_SCRIPT",
45
+ :description => "Filename of a customization script to upload"
46
+
47
+ option :force_customization,
48
+ :long => "--[no-]force",
49
+ :description => "Force a Guest Customization of the parent vAPP",
50
+ :boolean => true,
51
+ :default => true
52
+
53
+ option :guest_computer_name,
54
+ :long => "--guest-computer-name COMPUTER_NAME",
55
+ :description => "Set Guest Computer Name"
56
+
57
+ def run
58
+ $stdout.sync = true
59
+
60
+ vm_arg = @name_args.shift
61
+ computer_name = locate_config_value(:guest_computer_name)
62
+ script_filename = locate_config_value(:customization_script)
63
+
64
+ if script_filename
65
+ script = File.read(script_filename)
66
+ raise ArgumentError,
67
+ "A customization script cannot exceed 49000 characters" if script.size > 49_000
68
+ end
69
+
70
+ config = {
71
+ :enabled => locate_config_value(:guest_enabled),
72
+ :admin_passwd_enabled => locate_config_value(:admin_passwd_enabled),
73
+ :admin_passwd => locate_config_value(:admin_passwd),
74
+ :customization_script => script
75
+ }
76
+
77
+ connection.login
78
+
79
+ vm = get_vm(vm_arg)
80
+
81
+ if config[:admin_passwd].nil? && vm[:guest_customizations][:admin_passwd_enabled]
82
+ ui.msg('Inheriting admin password')
83
+ config[:admin_passwd] = vm[:guest_customizations][:admin_passwd]
84
+ end
85
+
86
+ if computer_name.nil?
87
+ computer_name = vm[:guest_customizations][:computer_name]
88
+ end
89
+
90
+ stop_if_running(connection, vm)
91
+
92
+ guest_name = sanitize_guest_name(computer_name)
93
+
94
+ ui.msg "Renaming guest name to #{guest_name}..."
95
+ task_id, response = connection.set_vm_guest_customization vm[:id], guest_name, config
96
+
97
+ ui.msg "VM guest configuration..."
98
+ wait_task(connection, task_id)
99
+
100
+ if locate_config_value(:force_customization)
101
+ ui.msg "Forcing Guest Customization..."
102
+ task_id = connection.force_customization_vm vm[:id]
103
+ wait_task(connection, task_id)
104
+ end
105
+
106
+ connection.logout
107
+ end
108
+ end
109
+ end
110
+ 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,14 +16,13 @@
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 VcVmConfigNetwork < Chef::Knife
24
22
  include Knife::VcCommon
23
+ include Knife::VcVmCommon
25
24
 
26
- banner "knife vc vm config network [VM_ID] [NETWORK_NAME] (options)"
25
+ banner "knife vc vm config network [VM] [NETWORK_NAME] (options)"
27
26
 
28
27
  option :vm_net_primary_index,
29
28
  :long => "--net-primary NETWORK_PRIMARY_IDX",
@@ -51,11 +50,8 @@ class Chef
51
50
  def run
52
51
  $stdout.sync = true
53
52
 
54
- vm_id = @name_args.shift
53
+ vm_arg = @name_args.shift
55
54
  network_name = @name_args.shift
56
-
57
- connection.login
58
-
59
55
  config = {
60
56
  :primary_index => locate_config_value(:vm_net_primary_index),
61
57
  :network_index => locate_config_value(:vm_net_index),
@@ -64,10 +60,20 @@ class Chef
64
60
  :ip_allocation_mode => locate_config_value(:vm_ip_allocation_mode),
65
61
  }
66
62
 
67
- task_id, response = connection.set_vm_network_config vm_id, network_name, config
63
+ connection.login
64
+
65
+ vm = get_vm(vm_arg)
66
+
67
+ stop_if_running(connection, vm)
68
+
69
+ ui.msg "VM network configuration..."
70
+ task_id = connection.set_vm_network_config vm[:id], network_name, config
68
71
 
69
- print "VM network configuration..."
70
- wait_task(connection, task_id)
72
+ if wait_task(connection, task_id)
73
+ ui.msg "Forcing Guest Customization to apply changes..."
74
+ task_id = connection.force_customization_vm vm[:id]
75
+ wait_task(connection, task_id)
76
+ end
71
77
 
72
78
  connection.logout
73
79
  end
@@ -0,0 +1,44 @@
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 VcVmReboot < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+
25
+ banner "knife vc vm reboot [VM] (options)"
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ vm_arg = @name_args.shift
31
+
32
+ connection.login
33
+ vm = get_vm(vm_arg)
34
+
35
+ task_id = connection.reboot_vm vm[:id]
36
+
37
+ ui.msg "VM reboot..."
38
+ wait_task(connection, task_id)
39
+
40
+ connection.logout
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,44 @@
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 VcVmReset < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+
25
+ banner "knife vc vm reset [VM] (options)"
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ vm_arg = @name_args.shift
31
+
32
+ connection.login
33
+ vm = get_vm(vm_arg)
34
+
35
+ task_id = connection.reset_vm vm[:id]
36
+
37
+ ui.msg "VM reset..."
38
+ wait_task(connection, task_id)
39
+
40
+ connection.logout
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,78 @@
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 VcVmSetDisks < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+
25
+ banner "knife vc vm set disks [VM] (options)"
26
+
27
+ option :vm_disk_name,
28
+ :long => "--disk-name DISK_NAME",
29
+ :description => "Name of the disk to be modified (required unless using --add)"
30
+
31
+ option :vm_disk_size,
32
+ :long => "--disk-size DISK_SIZE",
33
+ :description => "Size of the disk (in MB)"
34
+
35
+ option :vm_add_disk,
36
+ :long => "--[no-]add",
37
+ :description => "Whether or not allocate a new disk (default false)",
38
+ :boolean => true,
39
+ :default => false
40
+
41
+ option :vm_delete_disk,
42
+ :long => "--[no-]delete",
43
+ :description => "Whether or not delete a given disk (default false)",
44
+ :boolean => true,
45
+ :default => false
46
+
47
+ def run
48
+ $stdout.sync = true
49
+
50
+ vm_arg = @name_args.shift
51
+
52
+ new_disk = locate_config_value(:vm_add_disk)
53
+ delete_disk = locate_config_value(:vm_delete_disk)
54
+ disk_name = locate_config_value(:vm_disk_name)
55
+ disk_size = locate_config_value(:vm_disk_size)
56
+
57
+ raise ArgumentError, "Disk name is mandatory if using --no-add" if !new_disk && disk_name.nil?
58
+ raise ArgumentError, "Disk size is mandatory if using --add" if new_disk && disk_size.nil?
59
+ raise ArgumentError, "Disk name is mandatory if using --delete" if delete_disk && disk_name.nil?
60
+
61
+ connection.login
62
+ vm = get_vm(vm_arg)
63
+
64
+ if !delete_disk || ui.confirm("Do you really want to #{ui.color('DELETE', :red)} disk #{disk_name}")
65
+ task_id = connection.set_vm_disk_info vm[:id], {
66
+ :add => new_disk,
67
+ :delete => delete_disk,
68
+ :disk_size => disk_size,
69
+ :disk_name => disk_name
70
+ }
71
+ ui.msg "VM setting Disks info..."
72
+ wait_task(connection, task_id)
73
+ end
74
+ connection.logout
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,79 @@
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 VcVmSetInfo < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVmCommon
24
+
25
+ banner "knife vc vm set info [VM] (options)"
26
+
27
+ option :vm_cpus_number,
28
+ :long => "--cpus CPUs_NUMBER",
29
+ :description => "Number of virtual CPUs to be allocated"
30
+
31
+ option :vm_ram,
32
+ :long => "--ram MEMORY_SIZE (in MB)",
33
+ :description => "Memory to be allocated"
34
+
35
+ option :vm_name,
36
+ :long => "--name VM_NAME",
37
+ :description => "Rename the VM"
38
+
39
+ def run
40
+ $stdout.sync = true
41
+
42
+ vm_arg = @name_args.first
43
+ cpus = locate_config_value(:vm_cpus_number)
44
+ ram = locate_config_value(:vm_ram)
45
+ vm_name = locate_config_value(:vm_name)
46
+
47
+ connection.login
48
+
49
+ vm = get_vm(vm_arg)
50
+
51
+ if cpus
52
+ task_id = connection.set_vm_cpus vm[:id], cpus
53
+ ui.msg "VM setting CPUs info..."
54
+ wait_task(connection, task_id)
55
+ end
56
+
57
+ if ram
58
+ task_id = connection.set_vm_ram vm[:id], ram
59
+ ui.msg "VM setting RAM info..."
60
+ wait_task(connection, task_id)
61
+ end
62
+
63
+ if vm_name
64
+ rename_vm(connection, vm, vm_name)
65
+ end
66
+
67
+ connection.logout
68
+ end
69
+
70
+ def rename_vm(connection, vm, vm_name)
71
+ ui.msg "Renaming VM from #{vm[:vm_name]} to #{vm_name}"
72
+ task_id = connection.rename_vm vm[:id], vm_name
73
+ result = wait_task(connection, task_id)
74
+
75
+ return result
76
+ end
77
+ end
78
+ end
79
+ end