Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have an need to be able to mount an NFS Datastore into VMWare using its DNS Name.
I'm not familiar with MVEL, and there isn't much material that I can find on it.
Can someone assist in creating a function that returns back the DNS name when it is passed an IP address?
I want to do this so that I don't have to customize the certified Mount Datastore command, and it will assist down the line with return parameters.
Solved! See The Solution
1 ACCEPTED SOLUTION
coreywanless has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WFA MVEL fucntions are java functions. You can do anything with a Java code, you can create a function and do it. For the Reverse DNS lookup, the following function will do.
===
function reverseDns(ip)
{
import java.net.*;
InetAddress add = InetAddress.getByName(ip);
String hostfqdn = add.getCanonicalHostName();
return hostfqdn;
}
===
Now you can use it in your workflow and get the DNS names.
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
6 REPLIES 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Corey,
I would recommend you do this using the "System.Net.Dns" .NET class within your WFA Command using PowerShell (IE your command would accept an IP Address as an input parameter but will perform a DNS lookup of the hostname then mount the datastore using the hostname). You could do it one line of PowerShell
> [String]$ipAddress = "192.168.100.10"
> [String]$hostName = [System.Net.Dns]::GetHostEntry($ipAddress).HostName
> $hostName
> TESTWFA1.testlab.local
Or...you could create a PowerShell function to include in your WFA Command. EG:
#'------------------------------------------------------------------------------
Function Get-DNSHostName{
[CmdletBinding()]
Param(
[Parameter(Position=0,
Mandatory=$True,
ValueFromPipeLine=$True,
ValueFromPipeLineByPropertyName=$True)]
[String]$IPAddress
)
Try{
[String]$hostName = [System.Net.Dns]::GetHostEntry($ipAddress).HostName
}Catch{
[String]$hostName = ""
}
Return $hostName;
}#End Function
#'------------------------------------------------------------------------------
[String]$ipAddress = "192.168.100.10"
[String]$hostName = Get-DNSHostName -IPAddress $ipAddress
Write-Host $hostName
Note: This assumes you have configured your A & PTR records in DNS.
Hope that helps
/Matt
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Matt for the reply. I have used a similar method in non-certified commands in WFA. What I am trying to avoid is cloning the "certified" command, and making the modifications to it.
In my example I'm wanting to use the certified command "Create VMware NFS Datastore". So what I was looking to do was use the function capability inside WFA (not powershell functions), and feed the ip address to the function outside of the command to feed to the certified command.
coreywanless has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
WFA MVEL fucntions are java functions. You can do anything with a Java code, you can create a function and do it. For the Reverse DNS lookup, the following function will do.
===
function reverseDns(ip)
{
import java.net.*;
InetAddress add = InetAddress.getByName(ip);
String hostfqdn = add.getCanonicalHostName();
return hostfqdn;
}
===
Now you can use it in your workflow and get the DNS names.
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's exactly what I'm looking for!
One day I will learn java syntax. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi sinhaa,
this is very helpful and sorry for hi-jacking this thread.
But I have the issue, when no entry was found in DNS, an error is thrown.
Since I'm not very familiar with MVEL, how can I achieve it, that a NULL value or a message like 'No DNS entry found!' will be returned?
Thanks,
Tino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't put try/catch blocks in WFA functions. Try the below function.
Its taken care of all 3 cases.
1. IP not pingable.
2. IP Pingable but, DNS entry not found.
3. Found DNS entry, return the FQDN.
function reverseDns(ip) { import java.net.*; InetAddress add = InetAddress.getByName(ip); if(add.isReachable(10000)) { String hostfqdn = add.getCanonicalHostName(); if (add.getHostAddress().contentEquals(hostfqdn)) { return 'IP pingable but DNS entry NOT found'; } else { return hostfqdn; } } else { return 'Host Not Reachable'; } }
sinhaa
If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
