stumpr
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
Reply
0 Kudos