Quantcast

FindingHostIPaddr

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

FindingHostIPaddr

mahdijava
hi

   does anyone know how i can find host ip address when i traverse through managed objects? which class i should use and how?(i try to write a simple code to power off or on hosts in vcenter. so i have to identify them!)

thank you so much in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

hartsock
Administrator

On Mon, Dec 22, 2014 at 2:10 PM, mahdijava [via pyvmomi] <[hidden email]> wrote:
hi

   does anyone know how i can find host ip address when i traverse through managed objects? which class i should use and how?(i try to write a simple code to power off or on hosts in vcenter. so i have to identify them!)

thank you so much in advance.


If you reply to this email, your message will be added to the discussion below:
http://pyvmomi.2338814.n4.nabble.com/FindingHostIPaddr-tp10.html
To start a new topic under pyvmomi, email [hidden email]
To unsubscribe from pyvmomi, click here.
NAML



--
# Shawn.Hartsock - twitter: @hartsock
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

hartsock
Administrator
In reply to this post by mahdijava
Okay... so I found this:

Realized you wanted *host* IP... 

The host will typically be network-addressable by it's host.name value in vCenter but that isn't always the case 100% of the time. On occasion the vCenter name can be something else.

Assuming you know how to find your host either through inventory traversal, looking at a virtual machine's host, or some other mechanism ... once you have a reference to the host you can find the ip of the host systems physical nics using this...

<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.ConfigInfo.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.ConfigInfo.html#field_detail
<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.NetworkInfo.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.NetworkInfo.html#field_detail
<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.PhysicalNic.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.PhysicalNic.html#field_detail

In pyVmomi speak:

    my_host.network.pnic[index].spec.ip.ipAddress

Basically, you have a list of pnic objects, one of them has your ip address that you want. You can't really tell which ip is the 'correct' one to use without some other deciding factor thought and a host should have multiple physical NIC and therefore multiple IP addresses.

Happy hacking!


On Mon, Dec 22, 2014 at 2:10 PM, mahdijava [via pyvmomi] <[hidden email]> wrote:
hi

   does anyone know how i can find host ip address when i traverse through managed objects? which class i should use and how?(i try to write a simple code to power off or on hosts in vcenter. so i have to identify them!)

thank you so much in advance.


If you reply to this email, your message will be added to the discussion below:
http://pyvmomi.2338814.n4.nabble.com/FindingHostIPaddr-tp10.html
To start a new topic under pyvmomi, email [hidden email]
To unsubscribe from pyvmomi, click here.
NAML



--
# Shawn.Hartsock - twitter: @hartsock
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

mahdijava
In reply to this post by hartsock
thank you so much for quick response.

 but i need host ip address not guest OS.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

hartsock
Administrator
The host will typically be network-addressable by it's host.name value in vCenter but that isn't always the case 100% of the time. On occasion the vCenter name can be something else.

If the host is named it's IP as in your diagram use...

host.name

... if you can't trust that you probably have bigger problems...

Assuming you know how to find your host either through inventory traversal, looking at a virtual machine's host, or some other mechanism ... once you have a reference to the host you can find the ip of the host systems physical nics using this...

http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.HostSystem.html
<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.ConfigInfo.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.ConfigInfo.html#field_detail
<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.NetworkInfo.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.NetworkInfo.html#field_detail
<a href="http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.PhysicalNic.html#field_detail">http://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.host.PhysicalNic.html#field_detail
http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.host.PhysicalNic.Specification.html

In pyVmomi speak:

    my_host.network.pnic[index].spec.ip.ipAddress

Basically, you have a list of pnic objects, one of them has your ip address that you want. You can't really tell which ip is the 'correct' one to use without some other deciding factor thought and a host should have multiple physical NIC and therefore multiple IP addresses.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

mahdijava
i think i dont know how to find it using inventory traversal.i'll find it finally!!

by the way,thank you so much.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

hartsock
Administrator
Here's a quick and dirty way to get all the hosts in your system:

On Mon, Dec 22, 2014 at 2:47 PM, mahdijava [via pyvmomi] <[hidden email]> wrote:
i think i dont know how to find it using inventory traversal.i'll find it finally!!

by the way,thank you so much.


If you reply to this email, your message will be added to the discussion below:
http://pyvmomi.2338814.n4.nabble.com/FindingHostIPaddr-tp10p15.html
To start a new topic under pyvmomi, email [hidden email]
To unsubscribe from pyvmomi, click here.
NAML



--
# Shawn.Hartsock - twitter: @hartsock
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: FindingHostIPaddr

mahdijava
thank you so much.
that worked perfectly.

On Tue, Dec 23, 2014 at 1:30 AM, hartsock [via pyvmomi] <[hidden email]> wrote:
Here's a quick and dirty way to get all the hosts in your system:

On Mon, Dec 22, 2014 at 2:47 PM, mahdijava [via pyvmomi] <[hidden email]> wrote:
i think i dont know how to find it using inventory traversal.i'll find it finally!!

by the way,thank you so much.


If you reply to this email, your message will be added to the discussion below:
http://pyvmomi.2338814.n4.nabble.com/FindingHostIPaddr-tp10p15.html
To start a new topic under pyvmomi, email [hidden email]
To unsubscribe from pyvmomi, click here.
NAML



--
# Shawn.Hartsock - twitter: @hartsock



If you reply to this email, your message will be added to the discussion below:
http://pyvmomi.2338814.n4.nabble.com/FindingHostIPaddr-tp10p16.html
To unsubscribe from FindingHostIPaddr, click here.
NAML

Loading...