Hi there,
Could anybody tell me how to insert some properties of VM into the notification email after successful service provision:
I can do it for Vm.id, vm.name and retirement date, but I couldn’t find how can I add the IP address of VM.
Maybe it is very simple question, but I cannot find the answer. Sorry for this.
The VM includes an ipaddresses
property you would use. It is an array to support multiple IP addresses. If you want to include all you would do something like vm.ipaddresses.join(', ')
or you could just take the first one: vm.ipaddresses.first
Having this data populated at the time the email is sent requires that the provider can obtain the IP from the VM and ManageIQ has collected it as part of the inventory.
Good day Greg,
Thank you for your answer. I’ve tried to use
#{vm['ipaddresses.first']}
#{vm['ipaddresses']}
, for example:
body += “VM ip: #{vm[‘ipaddresses.first’]}”
in Cloud - VM - Provisioning - email - MiqProvision_Complete method,
but I receive blank field in email like this:
VM ip:
I’d like to know how can I receive ip address property in the email notification? We need to send emails with provisioned vm’s properties, like vm id, vm name, vm power state e.t.c.
Your example text is a little off. I would expect it
body += "VM ip: #{vm['ipaddresses'].first}"
or better still
body += "VM ip: #{vm.ipaddresses.first}"
Were you able to verify if the VM’s IP address is known to ManageIQ?
Having this data populated at the time the email is sent requires that the provider can obtain the IP from the VM and ManageIQ has collected it as part of the inventory.
Thank you very much!
#{vm.ipaddresses.first} really helped me.
Thanks again!
@miiraheart That sounds like the data is not available in the database. You can check this by looking for the IP Addresses on the summary page of the VM in the UI.
For some providers I know the IP addresses are only available when the VMs are running.
Thank you for your reply, the IP address are not showing on the summary page even though the vm is running and oVirt guest agent is installed on the vm.
Maybe you need the VM to have an IP address before it sends the mail, for this you can enable the Post-provisioning method.
prov = $evm.root['miq_provision']
vm = prov.destination
if vm.ipaddresses.length.zero?
$evm.log(:info, "VM doesnt have an IP address yet - retrying in 1 minute")
$evm.root['ae_result'] = 'retry'
$evm.root['ae_retry_interval'] = '1.minute'
exit MIQ_OK
end
ip_address = vm.ipaddresses[0]
$evm.log(:info, "IP Address is: #{ip_address}")
Related post:
- Post-provisioning script - Post-provisioning script - #2 by pemcg
It’s worth testing explicitly for IPv4 addresses because sometimes the “first” address in vm.ipaddresses is the IPv6 address. You can use the ‘resolve’ module, for example:
require 'resolv'
...
ip_list = vm.ipaddresses.collect { |ip| ip if ip.match(Resolv::IPv4::Regex) }.compact
Hope this helps,
pemcg