How to get vlans available in VMware Vcenter?


#1

How to get vlans available in VMware Vcenter?


#2

Hi Andres

If you just have a single vCenter and want to retrieve all of the vlans then from automate it would just be:

vlans = $evm.vmdb('lan').all

Hope this helps,
pemcg


#3

@pemcg Thanks Peter. It’s been very helpful.


#5

Hi

The pproblem is that my vlan is: vlan80(dvSwitch1). When i list de vlan with vlans = $evm.vmdb(‘lan’).all only take the name and no take the prefij: dvSwitch1

But, when i go to the infraestructure-> virtual machine-> lifecycle-> provision vms . In the folder network, the list is ok.

imagen


#6

Hi @pemcg. Do you know how to get the ip address of a provisioned VM?
Thanks for your help.


#7

You can use vm.ipaddresses.join


#8

That drop down is just appending the name of the switch. You could get the same effect yourself in a dynamic dialog such as this (this example runs from a button on a cluster object in the WebUI, and lists all lans in the cluster):

begin
  lans = {}
  $evm.root['ems_cluster'].hosts.each do |host|
    lans['!'] = '-- select from list --'
    host.lans.each do |lan|
      lans[lan.id] = "#{lan.name} (#{lan.switch.name})"
    end
  end

  list_values = {
    'sort_by'    => :value,
    'data_type'  => :string,
    'required'   => true,
    'values'     => lans
  }
  list_values.each { |key, value| $evm.object[key] = value }

 rescue => err
  $evm.log(:error, "[#{err}]\n#{err.backtrace.join("\n")}")
  exit MIQ_STOP
end

#9

I have this problem when I aply the scritp:

ERROR – : [undefined method `hosts’ for nil:NilClass]

Thanks,


#10

Are you running the script from a custom button on your cluster object?

It looks like you don’t have $evm.root[‘ems_cluster’] defined.

pemcg


#11

I am apply this script to a custom service dialog:


#12

ok, so you need to lookup the cluster object yourself, something like

cluster = $evm.vmdb(:ems_cluster).where(:name => 'my_cluster_name').first
cluster.hosts.each do |host|
...

#13

Sorry, but I do not understand. My cluster is called: Cluster_Internet_LC. How would it stay?


#14

Yeah!!! Is OK!!!


#15

The problem today is:

:frowning:


#16

Hi, the new.

The problem with of has no EMS is ok, the problem is the template, but when i executed the sctrip and send the value, the value of vlan es number, in this case is : 870. This configuration is no read for the vmware, attach of image with the problem:
imagen