Class: VCloudSdk::VApp
Constant Summary
Infrastructure::ERROR_STATUSES, Infrastructure::SUCCESS_STATUS
Instance Method Summary
collapse
Methods included from Powerable
#power_off, #power_on, #status
Constructor Details
#initialize(session, link) ⇒ VApp
Returns a new instance of VApp.
10
11
12
13
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 10
def initialize(session, link)
@session = session
@link = link
end
|
Instance Method Details
#add_network_by_name(network_name, vapp_net_name = nil, fence_mode = Xml::FENCE_MODES[:BRIDGED]) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 96
def add_network_by_name(
network_name,
vapp_net_name = nil,
fence_mode = Xml::FENCE_MODES[:BRIDGED])
fail CloudError,
"Invalid fence mode '#{fence_mode}'" unless Xml::FENCE_MODES
.each_value
.any? { |m| m == fence_mode }
network = find_network_by_name(network_name)
new_vapp_net_name = vapp_net_name.nil? ? network.name : vapp_net_name
network_config_param = network_config_param(
network,
new_vapp_net_name,
fence_mode)
payload = entity_xml.network_config_section
payload.add_network_config(network_config_param)
task = connection.put(payload.href,
payload,
Xml::MEDIA_TYPE[:NETWORK_CONFIG_SECTION])
monitor_task(task)
end
|
#delete ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 19
def delete
vapp = entity_xml
vapp_name = name
if is_status?(vapp, :POWERED_ON)
fail CloudError,
"vApp #{vapp_name} is powered on, power-off before deleting."
end
wait_for_running_tasks(vapp, "VApp #{vapp_name}")
Config.logger.info "Deleting vApp #{vapp_name}."
monitor_task(connection.delete(vapp.remove_link),
@session.time_limit[:delete_vapp]) do |task|
Config.logger.info "vApp #{vapp_name} deleted."
return task
end
fail ApiRequestError,
"Fail to delete vApp #{vapp_name}"
end
|
#delete_network_by_name(name) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 118
def delete_network_by_name(name)
unless list_networks.any? { |network_name| network_name == name}
fail ObjectNotFoundError,
"Network '#{name}' is not found"
end
fail CloudError,
%Q{
Network '#{name}' is being used by one or more VMs.
Please remove the NIC(s) in VM(s) that are in use of the network.
Check logs for details.
} if network_in_use?(name)
payload = entity_xml.network_config_section
payload.delete_network_config(name)
task = connection.put(payload.href,
payload,
Xml::MEDIA_TYPE[:NETWORK_CONFIG_SECTION])
monitor_task(task)
nil
end
|
#find_vm_by_name(name) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 69
def find_vm_by_name(name)
entity_xml.vms.each do |vm|
return VCloudSdk::VM.new(@session, vm.href) if vm.name == name
end
fail ObjectNotFoundError, "VM '#{name}' is not found"
end
|
#list_networks ⇒ Object
89
90
91
92
93
94
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 89
def list_networks
entity_xml
.network_config_section
.network_configs
.map { |network_config| network_config.network_name }
end
|
#list_vms ⇒ Object
63
64
65
66
67
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 63
def list_vms
entity_xml.vms.map do |vm|
vm.name
end
end
|
#name ⇒ Object
15
16
17
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 15
def name
entity_xml.name
end
|
#recompose_from_vapp_template(catalog_name, template_name) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 41
def recompose_from_vapp_template(catalog_name, template_name)
recompose_vapp_link = get_recompose_vapp_link
Config.logger.info "Recomposing from template '#{template_name}' in catalog '#{catalog_name}'."
catalog = find_catalog_by_name catalog_name
template = catalog.find_vapp_template_by_name template_name
task = connection.post recompose_vapp_link.href,
recompose_from_vapp_template_param(template)
monitor_task task, @session.time_limit[:recompose_vapp]
Config.logger.info "vApp #{name} is recomposed."
self
end
|
#remove_vm_by_name(vm_name) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 77
def remove_vm_by_name(vm_name)
target_vm = find_vm_by_name vm_name
recompose_vapp_link = get_recompose_vapp_link
task = connection.post recompose_vapp_link.href,
remove_vm_param(target_vm)
monitor_task task, @session.time_limit[:recompose_vapp]
Config.logger.info "VM #{vm_name} is removed."
self
end
|
#vms ⇒ Object
57
58
59
60
61
|
# File 'lib/ruby_vcloud_sdk/vapp.rb', line 57
def vms
entity_xml.vms.map do |vm|
VCloudSdk::VM.new(@session, vm.href)
end
end
|