knife-vcloud 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,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
+ class VcVappClone < Chef::Knife
22
+ include Knife::VcCommon
23
+
24
+ banner "knife vc vapp clone [VDC] [SOURCE_VAPP] [DEST_NAME] (options)"
25
+
26
+ option :vm_deploy_clone,
27
+ :long => "--[no-]deploy-clone",
28
+ :description => "Deploy vApp after cloning (default true)",
29
+ :proc => Proc.new { |key| Chef::Config[:knife][:vm_deploy_clone] = key },
30
+ :boolean => true,
31
+ :default => true
32
+
33
+ option :vm_poweron_clone,
34
+ :long => "--[no-]poweron-clone",
35
+ :description => "Poweron vApp after cloning (default false)",
36
+ :proc => Proc.new { |key| Chef::Config[:knife][:vm_poweron_clone] = key },
37
+ :boolean => true,
38
+ :default => false
39
+
40
+ option :vm_delete_source,
41
+ :long => "--[no-]delete-source",
42
+ :description => "Delete source vApp",
43
+ :proc => Proc.new { |key| Chef::Config[:knife][:vm_delete_source] = key },
44
+ :boolean => true,
45
+ :default => false
46
+
47
+ option :vdc_name,
48
+ :long => "--vdc VDC_NAME",
49
+ :description => "VDC to whom vApp belongs",
50
+ :proc => Proc.new { |key| Chef::Config[:knife][:default_vdc_name] = key }
51
+
52
+ def run
53
+ $stdout.sync = true
54
+
55
+ vdc_arg = @name_args.shift
56
+ vapp_arg = @name_args.shift
57
+ dest_vapp_name = @name_args.shift
58
+
59
+ org_name = locate_org_option
60
+ deploy_clone = locate_config_value(:vm_deploy_clone).to_s
61
+ poweron_clone = locate_config_value(:vm_poweron_clone).to_s
62
+ delete_source = locate_config_value(:vm_delete_source).to_s
63
+
64
+ connection.login
65
+
66
+ org = connection.get_organization_by_name org_name
67
+ vdc = connection.get_vdc_by_name org, vdc_arg
68
+ vapp = connection.get_vapp_by_name org, vdc[:name], vapp_arg
69
+
70
+ result = connection.clone_vapp vdc[:id], vapp[:id], dest_vapp_name, deploy_clone, poweron_clone, delete_source
71
+
72
+ ui.msg "Cloning vApp..."
73
+ wait_task(connection, result[:task_id])
74
+ ui.msg "vApp cloned with ID: #{ui.color(result[:vapp_id], :cyan)}"
75
+
76
+ connection.logout
77
+ end
78
+ end
79
+ end
80
+ 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,30 +16,31 @@
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 VcVappCreate < Chef::Knife
24
22
  include Knife::VcCommon
23
+ include Knife::VcVDCCommon
25
24
 
26
- banner "knife vc vapp create [VDC_ID] [NAME] [DESCRIPTION] [TEMPLATE_ID] (options)"
25
+ banner "knife vc vapp create [VDC] [NAME] [DESCRIPTION] [TEMPLATE_ID] (options)"
27
26
 
28
27
  def run
29
28
  $stdout.sync = true
30
29
 
31
- vdc_id = @name_args.shift
30
+ vdc_arg = @name_args.shift
32
31
  name = @name_args.shift
33
32
  description = @name_args.shift
34
33
  templateId = @name_args.shift
35
34
 
36
35
  connection.login
37
36
 
38
- vapp_id, task_id = connection.create_vapp_from_template vdc_id, name, description, templateId
37
+ vdc = get_vdc(vdc_arg)
38
+
39
+ result = connection.create_vapp_from_template vdc[:id], name, description, templateId
39
40
 
40
- print "vApp creation..."
41
- wait_task(connection, task_id)
42
- puts "vApp created with ID: #{ui.color(vapp_id, :cyan)}"
41
+ ui.msg "vApp creation..."
42
+ wait_task(connection, result[:task_id])
43
+ ui.msg "vApp created with ID: #{ui.color(result[:vapp_id], :cyan)}"
43
44
 
44
45
  connection.logout
45
46
  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,29 +16,31 @@
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 VcVappDelete < Chef::Knife
24
22
  include Knife::VcCommon
23
+ include Knife::VcVappCommon
25
24
 
26
- banner "knife vc vapp delete [VAPP_ID] (options)"
25
+ banner "knife vc vapp delete [VAPP] (options)"
27
26
 
28
27
  def run
29
28
  $stdout.sync = true
30
29
 
31
- vapp_id = @name_args.first
30
+ vapp_arg = @name_args.shift
31
+
32
+ connection.login
33
+
34
+ vapp = get_vapp(vapp_arg)
32
35
 
33
- if ui.confirm("Do you really want to #{ui.color('DELETE', :red)} vApp #{vapp_id}?")
34
- connection.login
35
- task_id = connection.delete_vapp vapp_id
36
+ if ui.confirm("Do you really want to #{ui.color('DELETE', :red)} vApp #{vapp[:name]} (ID: #{vapp[:id]})")
37
+ task_id = connection.delete_vapp vapp[:id]
36
38
 
37
- print "vApp deletion..."
39
+ ui.msg "vApp deletion..."
38
40
  wait_task(connection, task_id)
39
41
 
40
- connection.logout
41
42
  end
43
+ connection.logout
42
44
  end
43
45
  end
44
46
  end
@@ -0,0 +1,101 @@
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 VcVappNetworkExternal < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVappCommon
24
+ include Knife::VcNetworkCommon
25
+
26
+ banner "knife vc vapp network external [add|delete|edit| [VAPP] [NETWORK] (options)"
27
+
28
+ option :retain_network,
29
+ :long => "--[no-]retain-network",
30
+ :description => "Toggle Retain Network across deployments (default true)",
31
+ :proc => Proc.new { |key| Chef::Config[:knife][:retain_network] = key },
32
+ :boolean => true,
33
+ :default => true
34
+
35
+ option :parent_network,
36
+ :short => "-p PARENT_NETWORK",
37
+ :long => "--parent-network PARENT_NETWORK",
38
+ :description => "Set a parent network. Defaults to the current network.",
39
+ :proc => Proc.new { |key| Chef::Config[:knife][:parent_network] = key }
40
+
41
+ def run
42
+ $stdout.sync = true
43
+
44
+ command_arg = @name_args.shift
45
+ vapp_arg = @name_args.shift
46
+ network_arg = @name_args.shift
47
+
48
+ unless command_arg =~ /add|delete|edit/
49
+ raise ArgumentError, "Invalid command #{command_arg} supplied. Only add, delete and edit are allowed."
50
+ end
51
+
52
+ command = command_arg.to_sym
53
+
54
+ config = {
55
+ :fence_mode => 'bridged',
56
+ :retain_network => locate_config_value(:retain_network)
57
+ }
58
+
59
+ connection.login
60
+
61
+ vapp = get_vapp(vapp_arg)
62
+ network = get_network network_arg
63
+
64
+ unless network
65
+ raise new ArgumentError, "Network #{network_arg} not found in vDC, please use `vapp network internal` if you want an internal network."
66
+ end
67
+
68
+ unless command == :delete
69
+ parent_network_arg = locate_config_value(:parent_network)
70
+ if parent_network_arg
71
+ ui.msg "Retrieving parent network details"
72
+ parent_network = get_network parent_network_arg
73
+ config[:parent_network] = { :id => parent_network[:id],
74
+ :name => parent_network[:name] }
75
+ else
76
+ ui.msg "Forcing parent network to itself"
77
+ config[:parent_network] = { :id => network[:id],
78
+ :name => network[:name] }
79
+ end
80
+ end
81
+
82
+ case command
83
+ when :add
84
+ ui.msg "Adding #{network[:name]} to vApp..."
85
+ task_id, response = connection.add_org_network_to_vapp vapp[:id], network, config
86
+ wait_task(connection, task_id)
87
+ when :delete
88
+ ui.msg "Removing #{network[:name]} from vApp..."
89
+ task_id, response = connection.delete_vapp_network vapp[:id], network
90
+ wait_task(connection, task_id)
91
+ when :edit
92
+ ui.msg "vApp network configuration for #{network[:name]}..."
93
+ task_id, response = connection.set_vapp_network_config vapp[:id], network, config
94
+ wait_task(connection, task_id)
95
+ end
96
+
97
+ connection.logout
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,151 @@
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 VcVappNetworkInternal < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVappCommon
24
+ include Knife::VcNetworkCommon
25
+
26
+ banner "knife vc vapp network internal [add|delete|edit| [VAPP] [NETWORK] (options)"
27
+
28
+ option :gateway,
29
+ :long => "--gateway GATEWAY",
30
+ :description => "Set a gateway"
31
+
32
+ option :netmask,
33
+ :long => "--netmask NETMASK",
34
+ :description => "Set a netmask"
35
+
36
+ option :dns1,
37
+ :long => "--dns1 DNS",
38
+ :description => "Set a DNS"
39
+
40
+ option :dns2,
41
+ :long => "--dns2 DNS",
42
+ :description => "Set a DNS"
43
+
44
+ option :dns_suffix,
45
+ :long => "--dns-suffix DNS_SUFFIX",
46
+ :description => "Set a DNS Suffix"
47
+
48
+ option :start_address,
49
+ :long => "--start-address ADDRESS",
50
+ :description => "Set a start address"
51
+
52
+ option :end_address,
53
+ :long => "--end-address ADDRESS",
54
+ :description => "Set a end address"
55
+
56
+ option :is_inherited,
57
+ :long => "--[no-]inherited",
58
+ :description => "Toggle IsInherited (default false)",
59
+ :proc => Proc.new { |key| Chef::Config[:knife][:is_inherited] = key },
60
+ :boolean => true,
61
+ :default => false
62
+
63
+ option :retain_network,
64
+ :long => "--[no-]retain-network",
65
+ :description => "Toggle Retain Network across deployments (default true)",
66
+ :proc => Proc.new { |key| Chef::Config[:knife][:retain_network] = key },
67
+ :boolean => true,
68
+ :default => true
69
+
70
+ option :parent_network,
71
+ :short => "-p PARENT_NETWORK",
72
+ :long => "--parent-network PARENT_NETWORK",
73
+ :description => "Set a parent network for this internal network",
74
+ :proc => Proc.new { |key| Chef::Config[:knife][:parent_network] = key }
75
+
76
+ def run
77
+ $stdout.sync = true
78
+
79
+ command_arg = @name_args.shift
80
+ vapp_arg = @name_args.shift
81
+ network_arg = @name_args.shift
82
+
83
+ unless command_arg =~ /add|delete|edit/
84
+ raise ArgumentError, "Invalid command #{command_arg} supplied. Only add, delete and edit are allowed."
85
+ end
86
+
87
+ command = command_arg.to_sym
88
+
89
+ config = { :fence_mode => 'isolated' }
90
+
91
+ connection.login
92
+
93
+ vapp = get_vapp(vapp_arg)
94
+
95
+ network = vapp[:networks].select{|n| n[:name] == network_arg }.first
96
+
97
+ unless network
98
+ if command != :add
99
+ raise ArgumentError, "Network #{network_arg} not found in vApp, " \
100
+ "please use `--add` if you want to add new network."
101
+ else
102
+ network = {:name => network_arg}
103
+ end
104
+ end
105
+
106
+ unless command == :delete
107
+ fields = [:gateway, :netmask, :dns1, :dns2, :dns_suffix,
108
+ :start_address, :end_address, :is_inherited, :retain_network]
109
+
110
+ fields.each do |field|
111
+ config[field] = locate_config_value(field)
112
+
113
+ if command == :add && config[field].nil?
114
+ config[field] = ui.ask_question(" #{pretty_symbol(field)}: ")
115
+ end
116
+ end
117
+
118
+ parent_network_arg = locate_config_value(:parent_network)
119
+ if parent_network_arg
120
+ ui.msg "Retrieving parent network details"
121
+ parent_network = get_network parent_network_arg
122
+ config[:parent_network] = { :id => parent_network[:id],
123
+ :name => parent_network[:name] }
124
+ end
125
+
126
+ if parent_network && config[:fence_mode] != 'natRouted'
127
+ ui.info "Setting a parent network for an internal network requires fence mode natRouted. Fixing it..."
128
+ config[:fence_mode] = 'natRouted'
129
+ end
130
+ end
131
+
132
+ case command
133
+ when :add
134
+ ui.msg "Adding #{network[:name]} to vApp..."
135
+ task_id, response = connection.add_internal_network_to_vapp vapp[:id], network, config
136
+ wait_task(connection, task_id)
137
+ when :delete
138
+ ui.msg "Removing #{network[:name]} from vApp..."
139
+ task_id, response = connection.delete_vapp_network vapp[:id], network
140
+ wait_task(connection, task_id)
141
+ when :edit
142
+ ui.msg "vApp network configuration for #{network[:name]}..."
143
+ task_id, response = connection.set_vapp_network_config vapp[:id], network, config
144
+ wait_task(connection, task_id)
145
+ end
146
+
147
+ connection.logout
148
+ end
149
+ end
150
+ end
151
+ 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 VcVappReboot < Chef::Knife
22
+ include Knife::VcCommon
23
+ include Knife::VcVappCommon
24
+
25
+ banner "knife vc vapp reboot [VAPP] (options)"
26
+
27
+
28
+ def run
29
+ $stdout.sync = true
30
+
31
+ vapp_arg = @name_args.shift
32
+
33
+ connection.login
34
+ vapp = get_vapp(vapp_arg)
35
+
36
+ task_id = connection.reboot_vapp vapp[:id]
37
+
38
+ ui.msg "vApp reboot..."
39
+ wait_task(connection, task_id)
40
+
41
+ connection.logout
42
+ end
43
+ end
44
+ end
45
+ end