AddVirtualSwitch

Hello

I want to change policies when creating a vSwitch, it works when you create a portgroup but receive

a specified parameter was not correct.

Example on a portgroup:

My $vSwitch = $vsnameOpt;

My $pgName = $pgOpt;

My $vlan = 0 if (defined $vlanOpt).

My $hostTeamPolicy = new HostNicTeamingPolicy (policy = & gt;) "loadbalance_srcid");

My $hostNetSecPolicy = new HostNetworkSecurityPolicy (allowPromiscuous = & gt; '1',

forgedTransmits = & gt; '1',

macChanges = & gt; '1' );

My $hostNetPolicy = new HostNetworkPolicy (security = & gt; $hostNetSecPolicy,

nicTeaming = & gt; $hostTeamPolicy);

My $hostPGSpec = new HostPortGroupSpec (name = & gt; $pgName,

policy = & gt; $hostNetPolicy,

vlanId = & gt; $vlan.

vswitchName = & gt; $vSwitch);

My $host_views = HostUtils::get_hosts ('HostSystem');

If {($host_views)

{foreach (@$host_views)}

My $host_view = $_;

My $net = Vim::get_view (mo_ref = & gt; $host_view - & gt configManager - & gt; networkSystem);

EVAL {$net - & gt; AddPortGroup (_C = & gt; $net, portgrp = & gt; $hostPGSpec); };

If ($@)

print_screen ('clear ', 'green',' PortGroup is created: ", $pgName." "") -& gt; ". $vSwitch);

}

}

Example for a vSwitch and I received a specified parameter was not correct:

My $vSwitch = $vsnameOpt;

My $host_views = HostUtils::get_hosts ('HostSystem');

My $hostNetSecPolicy = new HostNetworkSecurityPolicy (allowPromiscuous = & gt; '1',

forgedTransmits = & gt; '1',

macChanges = & gt; '1' );

My $hostNetPolicy = new HostNetworkPolicy (security = & gt; $hostNetSecPolicy);

My $HostVSspec = new HostVirtualSwitchSpec (numPorts = & gt; '256',

policy = & gt; $hostNetPolicy);

If {($host_views)

{foreach (@$host_views)}

My $host_view = $_;

My $net = Vim::get_view (mo_ref = & gt; $host_view - & gt configManager - & gt; networkSystem);

EVAL {$net - & gt; AddVirtualSwitch ('vswitchName' = & gt; $vSwitch, 'spec' = & gt; $HostVSspec) ;} ;

If ($@)

print_screen ("clear ',' green ',' Virtual Switch is created:", $vSwitch);

}

}

Any ideas?

Thank you

Dominic

The reason can be explained in this thread: Re: HostNicOrderPolicy

Here's a script that does what you want: addvSwitchWSecurityPolicy.pl, unfortunately due to the limitation... you touch many more properties, if you wish. Probably why default esxcfg-vswitch-a vSwitchX just lets you add and you must update the vSwitch after that you created as a workaround, else you will need to define a lot right from the start.

=========================================================================

William Lam

VMware vExpert 2009

Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

repository scripts vGhetto

VMware Code Central - Scripts/code samples for developers and administrators

http://Twitter.com/lamw

If you find this information useful, please give points to "correct" or "useful".

Tags: VMware

Similar Questions

  • How to retrieve the names of vSwitch

    Hello list,

    I have a query regarding the recovery of all the names of vSwitch just after the creation of a new vSwitch using perl sdk. Here is the code snippet I've tried.

    My $host_view = Vim::find_entity_view (view_type = > 'HostSystem');

    My $netSys = Vim::get_view (mo_ref = > $host_view->-> networkSystem configManager);

    EVAL {$netSys-> AddVirtualSwitch ('vswitchName' = > 'vSwitch10') ;};}

    if ($@) ;

    If ($@)

    My $vswitches = $netSys - > networkInfo-> vswitch;

    foreach my {$vswitch (@$vswitches)}

    printing $vswitch-> name;

    }

    Note that on the system, there is a default created vSwitch vSwitch0. In addition to this, I create a vSwitch called 'vSwitch10' using the code above. Just after the creation of the vSwitch, I'm reading the names of the vSwitches available in this system. But I see that only vSwitch0 is recovered...

    If I question the vSwitches since a different perl script names, vSwitch0 and vSwitch10 are retrieved.

    I'm missing something in the passage above the code. This means the VMware::VIRuntime libs; AppUtil::HostUtil; must be reloaded after creating a vswitch?

    Thank you

    Ghislain

    You will need refresh networkSystem display to see the changes.

    You can use update_view_data() on netSys, or get the view again once.

    $netSys->update_view_data();
    

    It should work

    =========================================================================

    William Lam

    VMware vExpert 2009,2010

    VMware scripts and resources at: http://www.virtuallyghetto.com/

    Twitter: @lamw

    repository scripts vGhetto

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    VMware Code Central - Scripts/code samples for developers and administrators

    VMware developer community

    If you find this information useful, please give points to "correct" or "useful".

  • Help me to fill that void, you can!

    Hello

    I try to send the req SOAP message to call the addvirtualswitch method

    but I don't know what I should put in "?" symbol

    " & lt; soapenv:Envelope xmlns:soapenv = ' http://schemas.xmlsoap.org/SOAP/envelope/ "xmlns:urn =" urn: vim25 "& gt; "

    & lt; soapenv:header / & gt;

    & lt; soapenv:body & gt;

    & lt; urn: AddVirtualSwitch & gt;

    & lt; urn: _this type = 'HostNetworkSystem' & gt;? & lt; / urn: _this & gt;

    I think it should be ha-host but it returned the error like this

    " & lt; soapenv:Envelope xmlns:soapenc = ' http://schemas.xmlsoap.org/SOAP/encoding/ "xmlns:soapenv =" " http://schemas.xmlsoap.org/SOAP/envelope/ "container =" " http://www.w3.org/2001/XMLSchema "" xmlns: xsi = " " http://www.w3.org/2001/XMLSchema-instance "& gt; .

    & lt; soapenv:body & gt;

    & lt; soapenv:fault & gt;

    & lt; faultcode & gt; ServerFaultCode & lt; / faultcode & gt;

    & lt; faultstring & gt; The application refers to an unexpected or unknown type. & lt; / faultstring & gt;

    & lt; retail & gt;

    & lt; InvalidTypeFault xsi: type = "InvalidType" xmlns = "urn: vim25" & gt;

    & lt; argument & gt; [N7Hostsvc6HaHostE:0xa40dbc4] & lt; / argument & gt;

    & lt; / InvalidTypeFault & gt;

    & lt; / detail & gt;

    & lt; / soapenv:Fault & gt;

    & lt; / soapenv:Body & gt;

    & lt; / soapenv:Envelope & gt;

    Thank you for all the suggestions

    If you call the operation directly on the ESX Server, then you must pass "networkSystem' which is the ID of the managed object corresponding to HostNetworkSystem on the host. If you want to send the SOAP on VirtualCenter, you must get the managed object ID of HostNetworkSystem corresponding to desired host where you want to create a virtual switch. You can get this with the help of MOB connecting to VirtualCenter: https://< VirtualCenter IP > / mob

    In addition, the method "AddVirtualSwitch" takes "vswitchName" and "spec" as parameters. "spec" parameter is optional and you can skip the same, but you must pass 'vswitchName' as is the required parameter.

    Hope this information is useful.

Maybe you are looking for