VMware Cloud Community
LucD
Leadership
Leadership
Jump to solution

set-oscustomizationspec and IP address

In the set-oscustomizationspec cmdlet there don't seem to be options to customize network related parameters (for example the IP address).

In the "Customization Specification Manager" in the VI Client these customization parameters can be configured.

Is this correct ? Or are we missing something ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
1 Solution

Accepted Solutions
yboychev
Hot Shot
Hot Shot
Jump to solution

Hi,

in the newly released PowerCLI 4.0 Update there is a gropup of commandlets managing NIC customization settings. These are

Get-OSCustomizationNicMapping

,

New-OSCustomizationNicMapping

, and

Set-OSCustomizationNicMapping

. Try them out! Becasue this has been a hot topic for a lot of people I'm planning to put some demo scripts (or a demo video) on how these cmdlets are designed to work in the upcoming days!

Enjoy it!

\Yavor

View solution in original post

Reply
0 Kudos
20 Replies
admin
Immortal
Immortal
Jump to solution

I think we need to look at this interface again - it's less than intuitive. It looks like to set the IP address, you set the customization spec's NamingPrefix to the address you want and set the NamingScheme to NamingScheme.Fixed.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I tested the NamingScheme and NamingContext but those don't seem to change anything related to network customization.

These 2 parameters apparently change the Computer Name.

I tried this:

PS C:\>set-oscustomizationspec -spec (get-oscustomizationspec -name Test) -namingprefix 192.168.21.1 -namingscheme fixed

When I checked via the Customization Wizard in the VI Client the Computer name fields were changed, not the IP address.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Seems like it's probably a bug. We'll have someone look into it.

ITworksHH
Contributor
Contributor
Jump to solution

Hello,

anything new to this thread? I would like to do the same for a mass deployment of servers.

Thanks,

Lars

Reply
0 Kudos
stephen_ng
Contributor
Contributor
Jump to solution

Hello, has there been any progress on this? I've been looking through the customization spec object and can't find anything related to IP addresses either--I would expect a NIC setting of some sort.

Thanks,

Steve

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

After some searching we were unable to find a method to pass the IP address via the current Set-OsCustomizationSpec cmdlet.

We decided to revert to the SDK and use the CloneVM_Task.

For those interested I have attached some skeleton code that shows the creation of the objects that the CloneVM_Task requires.

Note that the script extract only shows how to set the IP settings of the first NIC.

There are quit a lot of other settings that are omitted.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ITworksHH
Contributor
Contributor
Jump to solution

Hi,

that's really nice. I will have a look at it. Seems to solve my problem, too.

Many many thanks!

LS

Reply
0 Kudos
ITworksHH
Contributor
Contributor
Jump to solution

Hi Steve,

I have written an email to on Friday. Perhaps we will get an information starting this week.

But have a look at the solution of LucD - seems to solve the problem for me.

LS

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Steve,

I have written an email to mailto:adias@vmware.com on Friday. Perhaps we will get an information starting this week.

But have a look at the solution of LucD - seems to solve the problem for me.

We have a bug in the Beta toolkit that we plan to address for GA. In the meantime, using LucD's approach will work very well. When we have fixed our OSCustomizationSpec cmdlets, LucD's approach will still work, but the cmdlets should make it easier.

Reply
0 Kudos
stephen_ng
Contributor
Contributor
Jump to solution

Thanks! That's a big help.

One thing I am still having some trouble with is the resource pool for the target guest OS--I'm not using resource pools at all and would like to deploy the target VM directly on the host. How to get a resource pool object given a host name?

Seems like a simple problem but I have been bashing my head against it for a few hours already.

Thanks,

Steve

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The location parameter in the VirtualMachineCloneSpec allows you to specify where the new VM has to be created.

Have a look at the VirtualMachineRelocateSpec entry in the SDK API Reference.

All fields in there are optional.

If you use the host parameter you can specify a target host for the VM clone method.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
stm_cro
Contributor
Contributor
Jump to solution

Hello Stephen,

I ran into the same problem.

Ressourcepool is a property of ComputeResource object.

I don't know how you get the parent object so you can reach COmputeResource object with the Find-EntityViews command

With the following line you can make the link between a host and its resource pool (I only look at the first computeResource / host/ resource pool, you need to add loop to scan for your host!)

$cr=Find-EntityViews computeResource

$computeresource0=$cr[0] #here you get the first computeResource object

$host0_ref=$computeresource0.Host[0] #get the first host referenced

$vmhost_obj=get-view $host0_ref

$vmhost_name= $vmhost_obj.name #here you get your host name, now get the ressource pool

$respool_ref=$computeresource0.ResourcePool #here you get a reference

$respool_obj=Get-View $respool_ref #this is the object you can use with a commandlet

I'm just learning...

Reply
0 Kudos
stephen_ng
Contributor
Contributor
Jump to solution

Thanks LucD for your reply.

I think Location.Pool must be set if I am cloning from a template (which is my case):

For a clone from a template to a virtual machine is argument is required.

So I guess I will have to hunt around for the resource after all....

Steve

Reply
0 Kudos
stephen_ng
Contributor
Contributor
Jump to solution

Thanks! That did the trick.

The code I finally wound up using is:

$filter = New-Object -TypeName "System.Collections.Specialized.NameValueCollection"

$filter.Add("Name", $Hostname)

$ComputeResource = Find-EntityViews ComputeResource -Filter $filter

$vmclonespec = New-Object VMware.Vim.VirtualMachineCloneSpec

$vmclonespec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec

$vmclonespec.Location.Pool = $ComputeResource.ResourcePool

$vmclonespec.Location.Host = (Get-View (Get-vmHost $Hostname).id).moref

$vmclonespec.Location.Datastore = (Get-View (Get-Datastore -VMHost (Get-vmHost $Hostname)).id).moref

Reply
0 Kudos
andehacks
Contributor
Contributor
Jump to solution

I am curious if there is any update to this post. PowerCLI is no longer beta and from what I can tell there is nothing different than the beta CLI tools. I am trying to work around this issue by generating my own XML file with the IP,gateway, and computername all set according to the XML of an exported version stored on the server. I am just having an issue passing the xml to the new-oscustomizationspec cmdlet. It doesn't appear there is anyway of importing except for the gui. Is this something that was also overlooked, or am I completely off base here?

Also in my reading I have seen that if you set -namingscheme to custom, you can have an external app supply these. I have code already written to do this. Is there any documentation on what the app needs to be written in(can it be a powershell function?), does it need to take in any args, and what/how(formatting) should it return?

Reply
0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

Hi,

in the newly released PowerCLI 4.0 Update there is a gropup of commandlets managing NIC customization settings. These are

Get-OSCustomizationNicMapping

,

New-OSCustomizationNicMapping

, and

Set-OSCustomizationNicMapping

. Try them out! Becasue this has been a hot topic for a lot of people I'm planning to put some demo scripts (or a demo video) on how these cmdlets are designed to work in the upcoming days!

Enjoy it!

\Yavor

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Thanks Yavor, I will try them out.

Can't wait to see to the demo(s0.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
andehacks
Contributor
Contributor
Jump to solution

So I have been trying to use these new cmd-lets and I have run into even more issues. Everytime I create a new OScustomizationSpec and then create a new OScustomizationNicMapping, I end up with 2 NICs in the OScustomizationspec, so when I go to apply it to the vm, i get a

Cannot deploy template:

fault.NicSettingMismatch.summary

error

12/2/2009 7:21:37 PM

I have tried not setting DNSsuffix and DNS servers in the OScustomizationSpec, In the GUI this looks like it solved it since when editing the spec it has "typical settings" for networking. But if you add a OScustomizationNicMapping to that spec you still end up with 2 NICs. All that changes is the settings in the second NIC to be totally blank. If I do set DNS and DNSsuffix, those are the only populated items in NIC2. But I always end up with 2 NICs.

My workaround has been to after creating my OScustomizationSpec to do the following.

$specmap = get-oscustomizationnicmapping -spec $spec

remove-oscustomizationnicmapping $specmap

Then i can add my actual OScustomizationNicMapping to the OScustomizationSpec and do a set-vm

Any thoughts on why things work like this. It's very counter intuitive, if not a complete pain to figure out as its not documented anywhere.

Reply
0 Kudos
admin
Immortal
Immortal
Jump to solution

When you create a new OSCustomizationSpec one NIC is automatically created for you. This behavior is the same as in the VI Client which also creates a default NIC. So when you use New-OSCustomizationNicMapping cmdlet it creates a new NIC and adds it to the spec, making a total of 2. There are 2 things you can do:

  1. Remove the default NIC (created when you created the spec) and then create the NIC you want using New-OSCustomizationNicMapping cmdlet - this is the approach you used

  2. Edit the existing NIC so that it is configured as you want, e.g.:

Get-OSCustomizationNicMapping -Spec $spec | Set-OSCustomizationNicMapping ...

I think your confusion is because of that default NIC being created when you create the spec. I hope now things are a bit more clear.

Reply
0 Kudos