Contributor
Contributor

Globalization - creating non-english language VM


Hi,


I am trying to create a VM with French language words.


vSphere Client allowing and creating fine, but I am getting below error with Perl API call.


Failed to Create virtual machine "fenêtres" due to 


SOAP Fault:


----



Fault string: 


Error returned by expat parser: unclosed token


 


while parsing SOAP envelope


at line 2, column 3


 


while parsing HTTP request for method createVm


on object of type vim.Folder


at line 1, column 0


Fault detail: InvalidRequestFault .

Failed to Create virtual machine "fenêtres" due to 



SOAP Fault:



----




Fault string: 



Error returned by expat parser: unclosed token



 



while parsing SOAP envelope



at line 2, column 3



 



while parsing HTTP request for method createVm



on object of type vim.Folder



at line 1, column 0



Fault detail: InvalidRequestFault .




 


Do we have to set any language related parameters ?
For connection i set default local to "en_US" to connect non-english vCenter.


Thanks in advance

0 Kudos
1 Reply
Virtuoso
Virtuoso

So I think the problem is the ComplexType object doesn't encode_utf8 like it does for SimpleTypes.  It gets to the property with characters that should be encoded and doesn't.

You can sort of force it yourself.  I have an example below using Rename_Task().  Should be the same issue in your CreateVM_Task() call.  If you're using someone else's script, you'll probably have to wrap the potential french accent characters in encode_utf8.  You could patch up VICommon.pm.  If that's something you think you need to do, let me know.  Should be able to just do it for the 'string-like' properties during serialization.

You will probably get a warning message from LWP about the content header length (I did).  I'm guessing there's something in the HTTP header content-length calculation missing in the VICommon.pm as well.

$ perl test.pl --username=administrator --password=* --server=172.16.2.10 --oldvmname=test --newvmname=fenêtres

Content-Length header value was wrong, fixed at /Library/Perl/5.18/LWP/Protocol/http.pm line 190.

# VM was renamed to 'fenêtres' in the vSphere Client UI

#!/usr/bin/perl

# Created by Reuben Stump (http://www.virtuin.com)

use strict;

use warnings;

use VMware::VIRuntime;

use Encode qw(encode_utf8);

my %opts = (

  oldvmname => {

  type => "=s",

  required => 1,

  },

  newvmname => {

  type => "=s",

  required => 1,

  },

);

Opts::add_options(%opts);

Opts::parse();

Opts::validate();

Util::connect();

my ($old_name, $new_name, $vm);

$old_name = Opts::get_option('oldvmname');

$new_name = encode_utf8(Opts::get_option('newvmname'));

$vm = Vim::find_entity_view(

  view_type => 'VirtualMachine',

  properties => ['name'],

  filter => { 'name' => $old_name }

);

die "Failed to find vm '$old_name'" unless $vm;

# Rename VM

$vm->Rename(newName => $new_name);

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos