~ubuntu-branches/ubuntu/natty/libvirt/natty-security

« back to all changes in this revision

Viewing changes to src/esx/esx_vi.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-02-23 09:05:46 UTC
  • mfrom: (1.2.8 upstream) (3.4.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110223090546-4pwmrrt7h51hr3l3
Tags: 0.8.8-1ubuntu1
* Resynchronize and merge from Debian unstable. Remaining changes:
  - debian/patches:
    * 9000-delayed_iff_up_bridge.patch
    * 9001-dont_clobber_existing_bridges.patch
    * 9002-better_default_uri_virsh.patch
    * 9003-better-default-arch.patch
    * 9004-libvirtd-group-name.patch
    * 9005-increase-unix-socket-timeout.patch
    * 9006-default-config-test-case.patch
    * 9007-fix-daemon-conf-ftbfs.patch
    * 9011-move-ebtables-script.patch
    * 9014-skip-nodeinfotest.patch
    * 9020-lp545795.patch
    * 9021-fix-uint64_t.patch
  - debian/patches/series:
    * Disable qemu-disable-network.diff.patch
  - debian/control:
    * set ubuntu maintainer
    * Build-Depends:
      - swap libxen to libxen3, qemu to qemu-kvm, and open-iscsi to
        open-iscsi-utils in Build-Depends
      - remove virtualbox Build-Depends
      - add libxml2 and libapparmor-dev Build-Depends
    * convert Vcs-Git to Xs-Debian-Vcs-Git
    * libvirt-bin Depends: move netcat-openbsd, bridge-utils, dnsmasq-base
      (>= 2.46-1), and iptables from Recommends to Depends
    * libvirt-bin Recommends: move qemu to Suggests
    * libvirt-bin Suggests: add apparmor
    * libvirt0 Recommands: move lvm2 to Suggests
  - keep debian/libvirt-bin.apport
  - keep debian/libvirt-bin.cron.daily
  - debian/libvirt-bin.dirs:
    * add apparmor, cron.daily, and apport dirs
  - debian/libvirt-bin.examples:
    * add debian/libvirt-suspendonreboot
  - debian/libvirt-bin.install:
    * add /etc/apparmor.d files
    * add apport hook
  - debian/libvirt-bin.manpages:
    * add debian/libvirt-migrate-qemu-disks.1
  - debian/libvirt-bin.postinst:
    * replace libvirt groupname with libvirtd
    * add each admin user to libvirtd group
    * call apparmor_parser on usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
    * call 'libvirt-migrate-qemu-disks -a' after
      libvirt-bin has started if migrating from
      older than 0.8.3-1ubuntu1
  - debian/libvirt-bin.postrm:
    * replace libvirt groupname with libvirtd
    * remove usr.sbin.libvirtd and
      usr.lib.libvirt.virt-aa-helper
  - keep added files under debian/:
    * libvirt-bin.upstart
    * libvirt-migrate-qemu-disks
    * libvirt-migrate-qemu-disks.1
    * libvirt-suspendonreboot
    * apparmor profiles
  - debian/README.Debian:
    * add 'Apparmor Profile' section
    * add 'Disk migration' section
  - debian/rules:
    * don't build with vbox since virtualbox-ose is in universe
    * add --with-apparmor to DEB_CONFIGURE_EXTRA_FLAGS
    * set DEB_DH_INSTALLINIT_ARGS to '--upstart-only'
    * set DEB_MAKE_CHECK_TARGET to 'check'
    * remove unneeded binary-install/libvirt-bin:: and clean::
      sections (they only deal with sysvinit stuff)
    * add build/libvirt-bin:: section to install
      - apparmor files
      - apport hooks
      - libvirt-migrate-qemu-disks
* The following Ubuntu packaging changes occurred during the divergence
  between Debian and Ubuntu. These changes are not new, but included here
  for completeness: (0.8.5-0ubuntu1 - 0.8.5-0ubuntu5):
  - Have upstart job source /etc/default/libvirt-bin.  This is only a
    temporary fix until upstart provides proper default override support
    through /etc/init/libvirt-bin.override (or any other mechanism).
    (LP: 708172)
  - debian/apparmor/usr.sbin.libvirtd: use PUx instead of Ux for executables
    (LP: 573315)
  - Rebuild with python 2.7 as the python default.
  - debian/libvirt-bin.cron.daily: use shell globbing to enumerate xml files.
    Based on patch thanks to Henryk Plötz (LP: 655176)
* Dropped the following patches included/fixed upstream:
  - 9010-dont-disable-ipv6.patch
  - 9022-build-cleanup-declaration-of-xen-tests.patch
  - 9023-vah-require-uuid.patch
  - 9009-autodetect-nc-params.patch
    * rolled into Debian's
      Autodetect-if-the-remote-nc-command-supports-the-q-o.patch
* Updated the following patches:
  - 9011-move-ebtables-script.patch:
    * LOCALSTATEDIR is defined in configmake.h
  - 9000-9006: added DEP-3 tags
  - 9002-better_default_uri_virsh.patch: updated (context changed)
* New patches:
  - 9022-drop-booton-when-kernel-specified.patch (LP: #720426)
  - 9023-fix-lxc-console-hangup.patch (LP: #668369)
  - 9024-skip-broken-commandtest.patch
* debian/patches/series:
  - don't apply Disable-CHECKSUM-rule.patch: our iptables can do this
  - don't apply Debian-specific Debianize-libvirt-guests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "logging.h"
32
32
#include "util.h"
33
33
#include "uuid.h"
 
34
#include "vmx.h"
34
35
#include "xml.h"
35
36
#include "esx_vi.h"
36
37
#include "esx_vi_methods.h"
498
499
                                           "hostFolder\0") < 0 ||
499
500
        esxVI_LookupObjectContentByType(ctx, ctx->service->rootFolder,
500
501
                                        "Datacenter", propertyNameList,
501
 
                                        &datacenterList) < 0) {
502
 
        goto cleanup;
503
 
    }
504
 
 
505
 
    if (datacenterList == NULL) {
506
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
507
 
                     _("Could not retrieve datacenter list"));
 
502
                                        &datacenterList,
 
503
                                        esxVI_Occurrence_RequiredList) < 0) {
508
504
        goto cleanup;
509
505
    }
510
506
 
538
534
        goto cleanup;
539
535
    }
540
536
 
541
 
    /* Lookup ComputeResource */
 
537
    /* Lookup (Cluster)ComputeResource */
542
538
    esxVI_String_Free(&propertyNameList);
543
539
 
544
540
    if (esxVI_String_AppendValueListToList(&propertyNameList,
547
543
                                           "resourcePool\0") < 0 ||
548
544
        esxVI_LookupObjectContentByType(ctx, ctx->datacenter->hostFolder,
549
545
                                        "ComputeResource", propertyNameList,
550
 
                                        &computeResourceList) < 0) {
551
 
        goto cleanup;
552
 
    }
553
 
 
554
 
    if (computeResourceList == NULL) {
555
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
556
 
                     _("Could not retrieve compute resource list"));
 
546
                                        &computeResourceList,
 
547
                                        esxVI_Occurrence_RequiredList) < 0) {
557
548
        goto cleanup;
558
549
    }
559
550
 
605
596
    esxVI_String_Free(&propertyNameList);
606
597
 
607
598
    if (esxVI_String_AppendValueListToList(&propertyNameList,
608
 
                                           "name\0") < 0 ||
 
599
                                           "name\0"
 
600
                                           "configManager\0") < 0 ||
609
601
        esxVI_LookupObjectContentByType(ctx, ctx->computeResource->_reference,
610
602
                                        "HostSystem", propertyNameList,
611
 
                                        &hostSystemList) < 0) {
612
 
        goto cleanup;
613
 
    }
614
 
 
615
 
    if (hostSystemList == NULL) {
616
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
617
 
                     _("Could not retrieve host system list"));
 
603
                                        &hostSystemList,
 
604
                                        esxVI_Occurrence_RequiredList) < 0) {
618
605
        goto cleanup;
619
606
    }
620
607
 
679
666
 
680
667
    /* Lookup HostSystem */
681
668
    if (esxVI_String_AppendValueListToList(&propertyNameList,
682
 
                                           "name\0") < 0 ||
 
669
                                           "name\0"
 
670
                                           "configManager\0") < 0 ||
683
671
        esxVI_FindByIp(ctx, NULL, hostSystemIpAddress, esxVI_Boolean_False,
684
672
                       &managedObjectReference) < 0 ||
685
673
        esxVI_LookupObjectContentByType(ctx, managedObjectReference,
686
674
                                        "HostSystem", propertyNameList,
687
 
                                        &hostSystem) < 0) {
688
 
        goto cleanup;
689
 
    }
690
 
 
691
 
    if (hostSystem == NULL) {
692
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
693
 
                     _("Could not retrieve host system"));
694
 
        goto cleanup;
695
 
    }
696
 
 
697
 
    if (esxVI_HostSystem_CastFromObjectContent(hostSystem,
 
675
                                        &hostSystem,
 
676
                                        esxVI_Occurrence_RequiredItem) < 0 ||
 
677
        esxVI_HostSystem_CastFromObjectContent(hostSystem,
698
678
                                               &ctx->hostSystem) < 0) {
699
679
        goto cleanup;
700
680
    }
701
681
 
702
 
    /* Lookup ComputeResource */
 
682
    /* Lookup (Cluster)ComputeResource */
703
683
    esxVI_String_Free(&propertyNameList);
704
684
 
705
685
    if (esxVI_String_AppendValueListToList(&propertyNameList,
708
688
                                           "resourcePool\0") < 0 ||
709
689
        esxVI_LookupObjectContentByType(ctx, hostSystem->obj,
710
690
                                        "ComputeResource", propertyNameList,
711
 
                                        &computeResource) < 0) {
712
 
        goto cleanup;
713
 
    }
714
 
 
715
 
    if (computeResource == NULL) {
716
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
717
 
                     _("Could not retrieve compute resource of host system"));
718
 
        goto cleanup;
719
 
    }
720
 
 
721
 
    if (esxVI_ComputeResource_CastFromObjectContent(computeResource,
 
691
                                        &computeResource,
 
692
                                        esxVI_Occurrence_RequiredItem) < 0 ||
 
693
        esxVI_ComputeResource_CastFromObjectContent(computeResource,
722
694
                                                    &ctx->computeResource) < 0) {
723
695
        goto cleanup;
724
696
    }
732
704
                                           "hostFolder\0") < 0 ||
733
705
        esxVI_LookupObjectContentByType(ctx, computeResource->obj,
734
706
                                        "Datacenter", propertyNameList,
735
 
                                        &datacenter) < 0) {
736
 
        goto cleanup;
737
 
    }
738
 
 
739
 
    if (datacenter == NULL) {
740
 
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
741
 
                     _("Could not retrieve datacenter of compute resource"));
742
 
        goto cleanup;
743
 
    }
744
 
 
745
 
    if (esxVI_Datacenter_CastFromObjectContent(datacenter,
 
707
                                        &datacenter,
 
708
                                        esxVI_Occurrence_RequiredItem) < 0 ||
 
709
        esxVI_Datacenter_CastFromObjectContent(datacenter,
746
710
                                               &ctx->datacenter) < 0) {
747
711
        goto cleanup;
748
712
    }
1583
1547
                                           "currentSession") < 0 ||
1584
1548
            esxVI_LookupObjectContentByType(ctx, ctx->service->sessionManager,
1585
1549
                                            "SessionManager", propertyNameList,
1586
 
                                            &sessionManager) < 0) {
 
1550
                                            &sessionManager,
 
1551
                                            esxVI_Occurrence_RequiredItem) < 0) {
1587
1552
            goto cleanup;
1588
1553
        }
1589
1554
 
1633
1598
                                esxVI_ManagedObjectReference *root,
1634
1599
                                const char *type,
1635
1600
                                esxVI_String *propertyNameList,
1636
 
                                esxVI_ObjectContent **objectContentList)
 
1601
                                esxVI_ObjectContent **objectContentList,
 
1602
                                esxVI_Occurrence occurrence)
1637
1603
{
1638
1604
    int result = -1;
1639
1605
    esxVI_ObjectSpec *objectSpec = NULL;
1654
1620
 
1655
1621
    if (STRNEQ(root->type, type)) {
1656
1622
        if (STREQ(root->type, "Folder")) {
1657
 
            if (STREQ(type, "Datacenter") || STREQ(type, "ComputeResource")) {
 
1623
            if (STREQ(type, "Datacenter") || STREQ(type, "ComputeResource") ||
 
1624
                STREQ(type, "ClusterComputeResource")) {
1658
1625
                objectSpec->selectSet = ctx->selectSet_folderToChildEntity;
1659
1626
            } else {
1660
1627
                ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1662
1629
                             type, root->type);
1663
1630
                goto cleanup;
1664
1631
            }
1665
 
        } else if (STREQ(root->type, "ComputeResource")) {
 
1632
        } else if (STREQ(root->type, "ComputeResource") ||
 
1633
                   STREQ(root->type, "ClusterComputeResource")) {
1666
1634
            if (STREQ(type, "HostSystem")) {
1667
1635
                objectSpec->selectSet = ctx->selectSet_computeResourceToHost;
1668
1636
            } else if (STREQ(type, "Datacenter")) {
1674
1642
                goto cleanup;
1675
1643
            }
1676
1644
        } else if (STREQ(root->type, "HostSystem")) {
1677
 
            if (STREQ(type, "ComputeResource")) {
 
1645
            if (STREQ(type, "ComputeResource") ||
 
1646
                STREQ(type, "ClusterComputeResource")) {
1678
1647
                objectSpec->selectSet = ctx->selectSet_hostSystemToParent;
1679
1648
            } else if (STREQ(type, "VirtualMachine")) {
1680
1649
                objectSpec->selectSet = ctx->selectSet_hostSystemToVm;
1704
1673
        esxVI_PropertySpec_AppendToList(&propertyFilterSpec->propSet,
1705
1674
                                        propertySpec) < 0 ||
1706
1675
        esxVI_ObjectSpec_AppendToList(&propertyFilterSpec->objectSet,
1707
 
                                      objectSpec) < 0) {
1708
 
        goto cleanup;
1709
 
    }
1710
 
 
1711
 
    result = esxVI_RetrieveProperties(ctx, propertyFilterSpec,
1712
 
                                      objectContentList);
 
1676
                                      objectSpec) < 0 ||
 
1677
        esxVI_RetrieveProperties(ctx, propertyFilterSpec,
 
1678
                                 objectContentList) < 0) {
 
1679
        goto cleanup;
 
1680
    }
 
1681
 
 
1682
    if (objectContentList == NULL) {
 
1683
        switch (occurrence) {
 
1684
          case esxVI_Occurrence_OptionalItem:
 
1685
          case esxVI_Occurrence_OptionalList:
 
1686
            result = 0;
 
1687
            break;
 
1688
 
 
1689
          case esxVI_Occurrence_RequiredItem:
 
1690
            ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
 
1691
                         _("Could not lookup '%s' from '%s'"),
 
1692
                         type, root->type);
 
1693
            break;
 
1694
 
 
1695
          case esxVI_Occurrence_RequiredList:
 
1696
            ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
 
1697
                         _("Could not lookup '%s' list from '%s'"),
 
1698
                         type, root->type);
 
1699
            break;
 
1700
 
 
1701
          default:
 
1702
            ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
 
1703
                         _("Invalid occurrence value"));
 
1704
            break;
 
1705
        }
 
1706
 
 
1707
        goto cleanup;
 
1708
    }
 
1709
 
 
1710
    result = 0;
1713
1711
 
1714
1712
  cleanup:
1715
1713
    /*
1808
1806
 
1809
1807
int
1810
1808
esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName,
1811
 
                 esxVI_Boolean *value, esxVI_Occurrence occurence)
 
1809
                 esxVI_Boolean *value, esxVI_Occurrence occurrence)
1812
1810
{
1813
1811
    esxVI_DynamicProperty *dynamicProperty;
1814
1812
 
1831
1829
    }
1832
1830
 
1833
1831
    if (*value == esxVI_Boolean_Undefined &&
1834
 
        occurence == esxVI_Occurrence_RequiredItem) {
 
1832
        occurrence == esxVI_Occurrence_RequiredItem) {
 
1833
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
 
1834
                     _("Missing '%s' property"), propertyName);
 
1835
        return -1;
 
1836
    }
 
1837
 
 
1838
    return 0;
 
1839
}
 
1840
 
 
1841
 
 
1842
 
 
1843
int
 
1844
esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
 
1845
              esxVI_Long **value, esxVI_Occurrence occurrence)
 
1846
{
 
1847
    esxVI_DynamicProperty *dynamicProperty;
 
1848
 
 
1849
    if (value == NULL || *value != NULL) {
 
1850
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
 
1851
        return -1;
 
1852
    }
 
1853
 
 
1854
    for (dynamicProperty = objectContent->propSet; dynamicProperty != NULL;
 
1855
         dynamicProperty = dynamicProperty->_next) {
 
1856
        if (STREQ(dynamicProperty->name, propertyName)) {
 
1857
            if (esxVI_Long_CastFromAnyType(dynamicProperty->val, value) < 0) {
 
1858
                return -1;
 
1859
            }
 
1860
 
 
1861
            break;
 
1862
        }
 
1863
    }
 
1864
 
 
1865
    if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) {
1835
1866
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1836
1867
                     _("Missing '%s' property"), propertyName);
1837
1868
        return -1;
1845
1876
int
1846
1877
esxVI_GetStringValue(esxVI_ObjectContent *objectContent,
1847
1878
                     const char *propertyName,
1848
 
                     char **value, esxVI_Occurrence occurence)
 
1879
                     char **value, esxVI_Occurrence occurrence)
1849
1880
{
1850
1881
    esxVI_DynamicProperty *dynamicProperty;
1851
1882
 
1867
1898
        }
1868
1899
    }
1869
1900
 
1870
 
    if (*value == NULL && occurence == esxVI_Occurrence_RequiredItem) {
 
1901
    if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) {
1871
1902
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1872
1903
                     _("Missing '%s' property"), propertyName);
1873
1904
        return -1;
1882
1913
esxVI_GetManagedObjectReference(esxVI_ObjectContent *objectContent,
1883
1914
                                const char *propertyName,
1884
1915
                                esxVI_ManagedObjectReference **value,
1885
 
                                esxVI_Occurrence occurence)
 
1916
                                esxVI_Occurrence occurrence)
1886
1917
{
1887
1918
    esxVI_DynamicProperty *dynamicProperty;
1888
1919
 
1903
1934
        }
1904
1935
    }
1905
1936
 
1906
 
    if (*value == NULL && occurence == esxVI_Occurrence_RequiredItem) {
 
1937
    if (*value == NULL && occurrence == esxVI_Occurrence_RequiredItem) {
1907
1938
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
1908
1939
                     _("Missing '%s' property"), propertyName);
1909
1940
        return -1;
2014
2045
                    goto failure;
2015
2046
                }
2016
2047
 
2017
 
                if (esxUtil_UnescapeHexPercent(*name) < 0) {
 
2048
                if (virVMXUnescapeHexPercent(*name) < 0) {
2018
2049
                    ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
2019
2050
                                 _("Domain name contains invalid escape sequence"));
2020
2051
                    goto failure;
2230
2261
 
2231
2262
 
2232
2263
 
2233
 
int esxVI_LookupHostSystemProperties(esxVI_Context *ctx,
2234
 
                                     esxVI_String *propertyNameList,
2235
 
                                     esxVI_ObjectContent **hostSystem)
 
2264
int
 
2265
esxVI_LookupHostSystemProperties(esxVI_Context *ctx,
 
2266
                                 esxVI_String *propertyNameList,
 
2267
                                 esxVI_ObjectContent **hostSystem)
2236
2268
{
2237
2269
    return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
2238
2270
                                           "HostSystem", propertyNameList,
2239
 
                                           hostSystem);
 
2271
                                           hostSystem,
 
2272
                                           esxVI_Occurrence_RequiredItem);
2240
2273
}
2241
2274
 
2242
2275
 
2250
2283
     *        for cluster support */
2251
2284
    return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
2252
2285
                                           "VirtualMachine", propertyNameList,
2253
 
                                           virtualMachineList);
 
2286
                                           virtualMachineList,
 
2287
                                           esxVI_Occurrence_OptionalList);
2254
2288
}
2255
2289
 
2256
2290
 
2292
2326
 
2293
2327
    if (esxVI_LookupObjectContentByType(ctx, managedObjectReference,
2294
2328
                                        "VirtualMachine", propertyNameList,
2295
 
                                        virtualMachine) < 0) {
 
2329
                                        virtualMachine,
 
2330
                                        esxVI_Occurrence_RequiredItem) < 0) {
2296
2331
        goto cleanup;
2297
2332
    }
2298
2333
 
2435
2470
     *        support */
2436
2471
    return esxVI_LookupObjectContentByType(ctx, ctx->hostSystem->_reference,
2437
2472
                                           "Datastore", propertyNameList,
2438
 
                                           datastoreList);
 
2473
                                           datastoreList,
 
2474
                                           esxVI_Occurrence_OptionalList);
2439
2475
}
2440
2476
 
2441
2477
 
2614
2650
 
2615
2651
    if (esxVI_String_AppendValueToList(&propertyNameList, "host") < 0 ||
2616
2652
        esxVI_LookupObjectContentByType(ctx, datastore, "Datastore",
2617
 
                                        propertyNameList, &objectContent) < 0) {
 
2653
                                        propertyNameList, &objectContent,
 
2654
                                        esxVI_Occurrence_RequiredItem) < 0) {
2618
2655
        goto cleanup;
2619
2656
    }
2620
2657
 
2679
2716
 
2680
2717
    if (esxVI_String_AppendValueToList(&propertyNameList, "info") < 0 ||
2681
2718
        esxVI_LookupObjectContentByType(ctx, task, "Task", propertyNameList,
2682
 
                                        &objectContent) < 0) {
 
2719
                                        &objectContent,
 
2720
                                        esxVI_Occurrence_RequiredItem) < 0) {
2683
2721
        goto cleanup;
2684
2722
    }
2685
2723
 
2978
3016
    esxVI_FloppyImageFileQuery *floppyImageFileQuery = NULL;
2979
3017
    esxVI_ManagedObjectReference *task = NULL;
2980
3018
    esxVI_TaskInfoState taskInfoState;
 
3019
    char *taskInfoErrorMessage = NULL;
2981
3020
    esxVI_TaskInfo *taskInfo = NULL;
2982
3021
    esxVI_HostDatastoreBrowserSearchResults *searchResults = NULL;
2983
3022
 
3097
3136
                                   datastorePathWithoutFileName, searchSpec,
3098
3137
                                   &task) < 0 ||
3099
3138
        esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
3100
 
                                    esxVI_Boolean_False, &taskInfoState) < 0) {
 
3139
                                    esxVI_Boolean_False, &taskInfoState,
 
3140
                                    &taskInfoErrorMessage) < 0) {
3101
3141
        goto cleanup;
3102
3142
    }
3103
3143
 
3104
3144
    if (taskInfoState != esxVI_TaskInfoState_Success) {
3105
3145
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
3106
 
                     _("Could not serach in datastore '%s'"), datastoreName);
 
3146
                     _("Could not search in datastore '%s': %s"),
 
3147
                     datastoreName, taskInfoErrorMessage);
3107
3148
        goto cleanup;
3108
3149
    }
3109
3150
 
3148
3189
    esxVI_ManagedObjectReference_Free(&hostDatastoreBrowser);
3149
3190
    esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
3150
3191
    esxVI_ManagedObjectReference_Free(&task);
 
3192
    VIR_FREE(taskInfoErrorMessage);
3151
3193
    esxVI_TaskInfo_Free(&taskInfo);
3152
3194
    esxVI_HostDatastoreBrowserSearchResults_Free(&searchResults);
3153
3195
 
3172
3214
    char *datastorePath = NULL;
3173
3215
    esxVI_ManagedObjectReference *task = NULL;
3174
3216
    esxVI_TaskInfoState taskInfoState;
 
3217
    char *taskInfoErrorMessage = NULL;
3175
3218
    esxVI_TaskInfo *taskInfo = NULL;
3176
3219
 
3177
3220
    if (searchResultsList == NULL || *searchResultsList != NULL) {
3238
3281
                                             datastorePath, searchSpec,
3239
3282
                                             &task) < 0 ||
3240
3283
        esxVI_WaitForTaskCompletion(ctx, task, NULL, esxVI_Occurrence_None,
3241
 
                                    esxVI_Boolean_False, &taskInfoState) < 0) {
 
3284
                                    esxVI_Boolean_False, &taskInfoState,
 
3285
                                    &taskInfoErrorMessage) < 0) {
3242
3286
        goto cleanup;
3243
3287
    }
3244
3288
 
3245
3289
    if (taskInfoState != esxVI_TaskInfoState_Success) {
3246
3290
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR,
3247
 
                     _("Could not serach in datastore '%s'"), datastoreName);
 
3291
                     _("Could not serach in datastore '%s': %s"),
 
3292
                     datastoreName, taskInfoErrorMessage);
3248
3293
        goto cleanup;
3249
3294
    }
3250
3295
 
3263
3308
    esxVI_HostDatastoreBrowserSearchSpec_Free(&searchSpec);
3264
3309
    VIR_FREE(datastorePath);
3265
3310
    esxVI_ManagedObjectReference_Free(&task);
 
3311
    VIR_FREE(taskInfoErrorMessage);
3266
3312
    esxVI_TaskInfo_Free(&taskInfo);
3267
3313
 
3268
3314
    return result;
3329
3375
 
3330
3376
 
3331
3377
int
 
3378
esxVI_LookupAutoStartDefaults(esxVI_Context *ctx,
 
3379
                              esxVI_AutoStartDefaults **defaults)
 
3380
{
 
3381
    int result = -1;
 
3382
    esxVI_String *propertyNameList = NULL;
 
3383
    esxVI_ObjectContent *hostAutoStartManager = NULL;
 
3384
    esxVI_DynamicProperty *dynamicProperty = NULL;
 
3385
 
 
3386
    if (defaults == NULL || *defaults != NULL) {
 
3387
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
 
3388
        return -1;
 
3389
    }
 
3390
 
 
3391
    /*
 
3392
     * Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
 
3393
     * for some reason this is much faster than looking up the same info from
 
3394
     * the HostSystem config.
 
3395
     */
 
3396
    if (esxVI_String_AppendValueToList(&propertyNameList,
 
3397
                                       "config.defaults") < 0 ||
 
3398
        esxVI_LookupObjectContentByType
 
3399
          (ctx, ctx->hostSystem->configManager->autoStartManager,
 
3400
           "HostAutoStartManager", propertyNameList,
 
3401
           &hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
 
3402
        goto cleanup;
 
3403
    }
 
3404
 
 
3405
    for (dynamicProperty = hostAutoStartManager->propSet;
 
3406
         dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) {
 
3407
        if (STREQ(dynamicProperty->name, "config.defaults")) {
 
3408
            if (esxVI_AutoStartDefaults_CastFromAnyType(dynamicProperty->val,
 
3409
                                                        defaults) < 0) {
 
3410
                goto cleanup;
 
3411
            }
 
3412
 
 
3413
            break;
 
3414
        }
 
3415
    }
 
3416
 
 
3417
    if (*defaults == NULL) {
 
3418
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
 
3419
                     _("Could not retrieve the AutoStartDefaults object"));
 
3420
        goto cleanup;
 
3421
    }
 
3422
 
 
3423
    result = 0;
 
3424
 
 
3425
  cleanup:
 
3426
    esxVI_String_Free(&propertyNameList);
 
3427
    esxVI_ObjectContent_Free(&hostAutoStartManager);
 
3428
 
 
3429
    return result;
 
3430
}
 
3431
 
 
3432
 
 
3433
 
 
3434
int
 
3435
esxVI_LookupAutoStartPowerInfoList(esxVI_Context *ctx,
 
3436
                                   esxVI_AutoStartPowerInfo **powerInfoList)
 
3437
{
 
3438
    int result = -1;
 
3439
    esxVI_String *propertyNameList = NULL;
 
3440
    esxVI_ObjectContent *hostAutoStartManager = NULL;
 
3441
    esxVI_DynamicProperty *dynamicProperty = NULL;
 
3442
 
 
3443
    if (powerInfoList == NULL || *powerInfoList != NULL) {
 
3444
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
 
3445
        return -1;
 
3446
    }
 
3447
 
 
3448
    /*
 
3449
     * Lookup HostAutoStartManagerConfig from the HostAutoStartManager because
 
3450
     * for some reason this is much faster than looking up the same info from
 
3451
     * the HostSystem config.
 
3452
     */
 
3453
    if (esxVI_String_AppendValueToList(&propertyNameList,
 
3454
                                       "config.powerInfo") < 0 ||
 
3455
        esxVI_LookupObjectContentByType
 
3456
          (ctx, ctx->hostSystem->configManager->autoStartManager,
 
3457
           "HostAutoStartManager", propertyNameList,
 
3458
           &hostAutoStartManager, esxVI_Occurrence_RequiredItem) < 0) {
 
3459
        goto cleanup;
 
3460
    }
 
3461
 
 
3462
    for (dynamicProperty = hostAutoStartManager->propSet;
 
3463
         dynamicProperty != NULL; dynamicProperty = dynamicProperty->_next) {
 
3464
        if (STREQ(dynamicProperty->name, "config.powerInfo")) {
 
3465
            if (esxVI_AutoStartPowerInfo_CastListFromAnyType
 
3466
                  (dynamicProperty->val, powerInfoList) < 0) {
 
3467
                goto cleanup;
 
3468
            }
 
3469
 
 
3470
            break;
 
3471
        }
 
3472
    }
 
3473
 
 
3474
    result = 0;
 
3475
 
 
3476
  cleanup:
 
3477
    esxVI_String_Free(&propertyNameList);
 
3478
    esxVI_ObjectContent_Free(&hostAutoStartManager);
 
3479
 
 
3480
    return result;
 
3481
}
 
3482
 
 
3483
 
 
3484
 
 
3485
int
3332
3486
esxVI_HandleVirtualMachineQuestion
3333
3487
  (esxVI_Context *ctx, esxVI_ManagedObjectReference *virtualMachine,
3334
3488
   esxVI_VirtualMachineQuestionInfo *questionInfo,
3441
3595
                            const unsigned char *virtualMachineUuid,
3442
3596
                            esxVI_Occurrence virtualMachineOccurrence,
3443
3597
                            esxVI_Boolean autoAnswer,
3444
 
                            esxVI_TaskInfoState *finalState)
 
3598
                            esxVI_TaskInfoState *finalState,
 
3599
                            char **errorMessage)
3445
3600
{
3446
3601
    int result = -1;
3447
3602
    esxVI_ObjectSpec *objectSpec = NULL;
3458
3613
    esxVI_Boolean blocked = esxVI_Boolean_Undefined;
3459
3614
    esxVI_TaskInfo *taskInfo = NULL;
3460
3615
 
 
3616
    if (errorMessage == NULL || *errorMessage != NULL) {
 
3617
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
 
3618
        return -1;
 
3619
    }
 
3620
 
3461
3621
    version = strdup("");
3462
3622
 
3463
3623
    if (version == NULL) {
3578
3738
        goto cleanup;
3579
3739
    }
3580
3740
 
 
3741
    if (*finalState != esxVI_TaskInfoState_Success) {
 
3742
        if (esxVI_LookupTaskInfoByTask(ctx, task, &taskInfo)) {
 
3743
            goto cleanup;
 
3744
        }
 
3745
 
 
3746
        if (taskInfo->error == NULL) {
 
3747
            *errorMessage = strdup(_("Unknown error"));
 
3748
 
 
3749
            if (*errorMessage == NULL) {
 
3750
                virReportOOMError();
 
3751
                goto cleanup;
 
3752
            }
 
3753
        } else if (taskInfo->error->localizedMessage == NULL) {
 
3754
            *errorMessage = strdup(taskInfo->error->fault->_actualType);
 
3755
 
 
3756
            if (*errorMessage == NULL) {
 
3757
                virReportOOMError();
 
3758
                goto cleanup;
 
3759
            }
 
3760
        } else {
 
3761
            if (virAsprintf(errorMessage, "%s - %s",
 
3762
                            taskInfo->error->fault->_actualType,
 
3763
                            taskInfo->error->localizedMessage) < 0) {
 
3764
                virReportOOMError();
 
3765
                goto cleanup;
 
3766
            }
 
3767
        }
 
3768
    }
 
3769
 
3581
3770
    result = 0;
3582
3771
 
3583
3772
  cleanup:
3646
3835
 
3647
3836
    return 0;
3648
3837
}
 
3838
 
 
3839
 
 
3840
 
 
3841
int
 
3842
esxVI_ProductVersionToDefaultVirtualHWVersion(esxVI_ProductVersion productVersion)
 
3843
{
 
3844
    /*
 
3845
     * virtualHW.version compatibility matrix:
 
3846
     *
 
3847
     *              4 7    API
 
3848
     *   ESX 3.5    +      2.5
 
3849
     *   ESX 4.0    + +    4.0
 
3850
     *   ESX 4.1    + +    4.1
 
3851
     *   GSX 2.0    + +    2.5
 
3852
     */
 
3853
    switch (productVersion) {
 
3854
      case esxVI_ProductVersion_ESX35:
 
3855
      case esxVI_ProductVersion_VPX25:
 
3856
        return 4;
 
3857
 
 
3858
      case esxVI_ProductVersion_GSX20:
 
3859
      case esxVI_ProductVersion_ESX40:
 
3860
      case esxVI_ProductVersion_ESX41:
 
3861
      case esxVI_ProductVersion_VPX40:
 
3862
      case esxVI_ProductVersion_VPX41:
 
3863
        return 7;
 
3864
 
 
3865
      case esxVI_ProductVersion_ESX4x:
 
3866
      case esxVI_ProductVersion_VPX4x:
 
3867
        return 7;
 
3868
 
 
3869
      default:
 
3870
        ESX_VI_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
 
3871
                     _("Unexpected product version"));
 
3872
        return -1;
 
3873
    }
 
3874
}