【问题标题】:Using vSphere VI Java API to get annotation notes使用 vSphere VI Java API 获取注释说明
【发布时间】:2023-03-17 04:50:02
【问题描述】:

任何人都知道如何使用 vSphere VI Java API 来提取虚拟机“摘要”选项卡的“注释”部分中的值?我环顾四周并梳理了 API 文档,但在任何地方都没有看到。

【问题讨论】:

    标签: java vmware vsphere


    【解决方案1】:

    首先查看VirtualMachineConfigSpec 的API 文档。

    那么你可以从java中做到这一点

    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    configSpec.setAnnotation = "Your annotation string here" 
    reconfigVM_Task(vmMOR, configSpec);
    

    【讨论】:

    【解决方案2】:

    我在 Perl SDK 中做了这个,但是重新做它以使用 Java API 应该很容易。 您从 Virtual Machine object 获得注释,它具有 VirtualMachineSummary 类的名为 summary 的属性,该属性具有 VirtualMachineConfigSummary 类的 config它有一个 string 类型的 annotation 字段,这是您所需要的。

    my $vmname = "vmname you are looking for";
    # Get all VMs
    my $vms = Vim::find_entity_views(
            view_type => 'VirtualMachine',
            filter => {"config.name" => qr/^$vmname$/i},
    );
    
    # Iterate over the VMs, getting their annotations
    foreach my $vm (@{ $vms }) {
      my $notes = $vm->summary->config->annotation;
      my $name = $vm->summary->config->name;
      if (not defined $notes) {
        print " - VM: $name  has no notes\n";
      }
      elsif ($notes =~ m/^\$*/) {
        print " - VM: $name  has empty notes\n";
      }
      else {
        print " - VM: $name  notes: '$notes'\n";
      }
    }
    

    这里是完整代码:https://communities.vmware.com/message/2613855#2613855

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-01
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多