2017-11-24T10:24:27.388Z error vpxd[7F996F9F3700] [Originator@6876 sub=SoapAdapter]
--> Required property id is missing from data object of type OvfConsumerOstNode
-->
--> while parsing serialized DataObject of type vim.OvfConsumer.OstNode
--> at line 11, column 8
-->
--> while parsing property "instantiationOst" of static type OvfConsumerOstNode
-->
--> while parsing serialized DataObject of type vim.ImportSpec
--> at line 7, column 6
-->
--> while parsing call information for method ImportVApp
--> at line 5, column 4
-->
--> while parsing SOAP body
--> at line 4, column 2
-->
--> while parsing SOAP envelope
--> at line 2, column 0
-->
--> while parsing HTTP request for method importVApp
--> on object of type vim.ResourcePool
--> at line 1, column 0
2017-11-24T10:24:31.053Z info vpxd[7F996F8F1700] [Originator@6876 sub=vpxLro opID=2dc64d86] [VpxLRO] -- BEGIN task-internal-18777 -- SessionManager -- vim.SessionManager.sessionIsActive -- 520abc27-ebc2-2ccc-42bf-864790e61a93(52ef17e8-51fb-0da9-5fca-d490400cd24d)
"use strict";
let username = '<user>';
let password = '<password>';
let host = '<vCenter host>';
const VConnect = require('vsphere-connect');
const fs = require('fs');
let v = VConnect(host, {ignoreSSL: true})
v.createClient().then(client => {
return client.login(username, password).then((c) => {
const vim = client._soapClient.types.vim25;
return client.retrieve({
type: 'ClusterComputeResource',
id: 'domain-c7'
}).then((clu) => {
const cluster = clu[0].moRef;
console.log(cluster);
return client.retrieve({
type: 'Network',
id: 'network-22'
}).then((net) => {
const network = net[0].moRef;
console.log(network);
return client.retrieve({
type: 'Datastore',
id: 'datastore-154'
}).then((dst) => {
const ds = dst[0].moRef;
console.log(ds);
return client.retrieve({
type: 'Folder',
id: 'group-v3'
}).then((fl) => {
const folder = fl[0].moRef;
console.log(folder);
return client.retrieve({
type: 'ResourcePool',
id: 'resgroup-8'
}).then((rpool) => {
const rp = rpool[0].moRef;
console.log(rp);
// download https://communities.vmware.com/servlet/JiveServlet/downloadBody/21621-102-3-28798/Tiny%20Linux%20VM.ova and untar
const ovfDescriptor1 = fs.readFileSync('~/Tiny Linux VM.ovf').toString();
const specParams = getImportSpecParams(vim, network);
return client.method('CreateImportSpec', {
_this: client.serviceContent.ovfManager,
ovfDescriptor: ovfDescriptor1,
resourcePool: rp,
datastore: ds,
cisp: { locale: 'US', deploymentOption: '', entityName: 'testvmw' }
}).then((imspec) => {
console.log('imspec', imspec.importSpec);
console.log(imspec.importSpec)
return client.method('ImportVApp', {
_this: rp,
spec: imspec.importSpec,
folder: folder
}).then((vapp) => {
console.log('vapp', vapp);
})
}).catch((err1) => console.log('err1', err1))
})
})
})
})
})
})
}).catch((err) => console.log('err', err))
function getImportSpecParams(vim, network) {
const propertyMappings = [];
const ovfPropertyKeys = {
host_ip: host,
host_username: username,
host_password: password,
proxy: '172.18.192.3',
static_ip: '172.18.200.186',
static_netmask: '255.255.255.0',
static_gateway: '172.18.192.20',
static_dns: '172.18.192.5'
};
for (const key in ovfPropertyKeys) {
const param = new vim.KeyValue();
param.key = key;
param.value = ovfPropertyKeys[key];
propertyMappings.push(param);
}
const networkMapping = new vim.OvfNetworkMapping();
networkMapping.name = 'Network';
networkMapping.network = network;
const importSpecParams = new vim.OvfCreateImportSpecParams();
importSpecParams.entityName = 'testvm1';
importSpecParams.diskProvisioning = 'thin';
importSpecParams.propertyMapping = propertyMappings;
importSpecParams.ipAllocationPolicy = 'fixedPolicy';
importSpecParams.deploymentOption = '';
importSpecParams.locale = 'US';
importSpecParams.networkMapping = [networkMapping];
return importSpecParams;
}