Solved

Nutanix clone VM api and unattend.xml

  • 26 June 2018
  • 4 replies
  • 8549 views

Need some pointers on how to add unattend.xml to API for VM customization.

"uuid": "string",
"vm_customization_config": {
"datasource_type": "CONFIG_DRIVE_V2",
"files_to_inject_list": [
{
"destination_path": "string",
"source_path": "string"
}
icon

Best answer by Chandru 2 July 2018, 21:10

@manubalasree

if you are not specifically looking to upload as a file you can use like below,

You can use http://jagt.github.io/python-single-line-convert/ to convert multi-line xml file to single line

code:
{"spec_list":[
{"name":"windows2016"}
],
"vm_customization_config":
{
"userdata": "\n\n \n \n en-US\n en-US\n en-US\n en-US\n en-US\n \n \n \n \n bgB1AHQAYQBuAGkAeAAvADQAdQBQAGEAcwBzAHcAbwByAGQA\n false</PlainText>\n </Password>\n <Enabled>true</Enabled>\n <Username>Administrator</Username>\n </AutoLogon>\n <OOBE>\n <HideEULAPage>true</HideEULAPage>\n <HideLocalAccountScreen>true</HideLocalAccountScreen>\n <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen>\n <NetworkLocation>Work</NetworkLocation>\n <SkipMachineOOBE>true</SkipMachineOOBE>\n <SkipUserOOBE>true</SkipUserOOBE>\n </OOBE>\n <UserAccounts>\n <AdministratorPassword>\n <Value>bgB1AHQAYQBuAGkAeAAvADQAdQBBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=</Value>\n <PlainText>false</PlainText>\n </AdministratorPassword>\n </UserAccounts>\n </component>\n </settings>\n <settings pass="specialize">\n <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <ComputerName>RobClone-@@{calm_random}@@</ComputerName>\n <RegisteredOwner>Nutanix</RegisteredOwner>\n </component>\n <component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n <Identification>\n <Credentials>\n <Domain>tsapac.local</Domain>\n <Password>nutanix/4u</Password>\n <Username>administrator</Username>\n </Credentials>\n <JoinDomain>tsapac.local</JoinDomain>\n </Identification>\n </component>\n </settings>\n <cpi:offlineImage cpi:source="wim:f:/install.wim#Windows Server 2016 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" ></cpi:offlineImage>\n</unattend>"
}
}

&lt;/pre&gt;</plaintext></password></autologon></component></settings></unattend></pre>
View original

4 replies

Userlevel 3
Badge +12
@manubalasree

if you are not specifically looking to upload as a file you can use like below,

You can use http://jagt.github.io/python-single-line-convert/ to convert multi-line xml file to single line

code:
{"spec_list":[
{"name":"windows2016"}
],
"vm_customization_config":
{
"userdata": "\n\n \n \n en-US\n en-US\n en-US\n en-US\n en-US\n \n \n \n \n bgB1AHQAYQBuAGkAeAAvADQAdQBQAGEAcwBzAHcAbwByAGQA\n false&lt;/PlainText&gt;\n &lt;/Password&gt;\n &lt;Enabled&gt;true&lt;/Enabled&gt;\n &lt;Username&gt;Administrator&lt;/Username&gt;\n &lt;/AutoLogon&gt;\n &lt;OOBE&gt;\n &lt;HideEULAPage&gt;true&lt;/HideEULAPage&gt;\n &lt;HideLocalAccountScreen&gt;true&lt;/HideLocalAccountScreen&gt;\n &lt;HideOEMRegistrationScreen&gt;true&lt;/HideOEMRegistrationScreen&gt;\n &lt;NetworkLocation&gt;Work&lt;/NetworkLocation&gt;\n &lt;SkipMachineOOBE&gt;true&lt;/SkipMachineOOBE&gt;\n &lt;SkipUserOOBE&gt;true&lt;/SkipUserOOBE&gt;\n &lt;/OOBE&gt;\n &lt;UserAccounts&gt;\n &lt;AdministratorPassword&gt;\n &lt;Value&gt;bgB1AHQAYQBuAGkAeAAvADQAdQBBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=&lt;/Value&gt;\n &lt;PlainText&gt;false&lt;/PlainText&gt;\n &lt;/AdministratorPassword&gt;\n &lt;/UserAccounts&gt;\n &lt;/component&gt;\n &lt;/settings&gt;\n &lt;settings pass="specialize"&gt;\n &lt;component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;\n &lt;ComputerName&gt;RobClone-@@{calm_random}@@&lt;/ComputerName&gt;\n &lt;RegisteredOwner&gt;Nutanix&lt;/RegisteredOwner&gt;\n &lt;/component&gt;\n &lt;component name="Microsoft-Windows-UnattendedJoin" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;\n &lt;Identification&gt;\n &lt;Credentials&gt;\n &lt;Domain&gt;tsapac.local&lt;/Domain&gt;\n &lt;Password&gt;nutanix/4u&lt;/Password&gt;\n &lt;Username&gt;administrator&lt;/Username&gt;\n &lt;/Credentials&gt;\n &lt;JoinDomain&gt;tsapac.local&lt;/JoinDomain&gt;\n &lt;/Identification&gt;\n &lt;/component&gt;\n &lt;/settings&gt;\n &lt;cpi:offlineImage cpi:source="wim:f:/install.wim#Windows Server 2016 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" &gt;&lt;/cpi:offlineImage&gt;\n&lt;/unattend&gt;"
}
}

&lt;/pre&gt;</plaintext></password></autologon></component></settings></unattend></pre>
Userlevel 3
Badge +12
the XML spec is getting modified when i post it as reply in the forum.
Hello

Do you have a fully example on how to put directly the XML file in the API call? I don't get where "spec_list" should go

Thanks 😃

Raphaël
Userlevel 3
Badge +12
@RaphaelBubble the spec list the body of the request. An example with curl will look like this

Replace , with the uuid of the vm to clone and with your custom spec.
code:
curl -k -s -u admin https://:9440/api/nutanix/v2/PrismGateway/services/rest/v2.0/vms//clone --header "accept:application/json" --header "Content-type:application/json" -d ''

Reply