Search in sources :

Example 1 with KeyValue

use of com.vmware.vim25.KeyValue in project cloudstack by apache.

the class LicenseAssignmentManagerMO method isFeatureSupported.

public boolean isFeatureSupported(String featureKey, ManagedObjectReference hostMor) throws Exception {
    boolean featureSupported = false;
    // Retrieve host license properties
    List<KeyAnyValue> props = getHostLicenseProperties(hostMor);
    // Check host license properties to see if specified feature is supported by the license.
    for (KeyAnyValue prop : props) {
        String key = prop.getKey();
        if (key.equalsIgnoreCase(LICENSE_INFO_FEATURE)) {
            KeyValue propValue = (KeyValue) prop.getValue();
            if (propValue.getKey().equalsIgnoreCase(featureKey)) {
                featureSupported = true;
                break;
            }
        }
    }
    return featureSupported;
}
Also used : KeyValue(com.vmware.vim25.KeyValue) KeyAnyValue(com.vmware.vim25.KeyAnyValue)

Example 2 with KeyValue

use of com.vmware.vim25.KeyValue in project photon-model by vmware.

the class OvfDeployer method deployOvf.

public ManagedObjectReference deployOvf(URI ovfUri, ManagedObjectReference host, ManagedObjectReference vmFolder, String vmName, List<OvfNetworkMapping> networks, ManagedObjectReference datastore, Collection<KeyValue> ovfProps, String deploymentConfig, ManagedObjectReference resourcePool) throws Exception {
    String ovfDescriptor = getRetriever().retrieveAsString(ovfUri);
    OvfCreateImportSpecParams params = new OvfCreateImportSpecParams();
    params.setHostSystem(host);
    params.setLocale("US");
    params.setEntityName(vmName);
    if (deploymentConfig == null) {
        deploymentConfig = "";
    }
    params.setDeploymentOption(deploymentConfig);
    params.getNetworkMapping().addAll(networks);
    params.setDiskProvisioning(OvfCreateImportSpecParamsDiskProvisioningType.THIN.name());
    if (ovfProps != null) {
        params.getPropertyMapping().addAll(ovfProps);
    }
    ManagedObjectReference ovfManager = this.connection.getServiceContent().getOvfManager();
    OvfCreateImportSpecResult importSpecResult = getVimPort().createImportSpec(ovfManager, ovfDescriptor, resourcePool, datastore, params);
    if (!importSpecResult.getError().isEmpty()) {
        return VimUtils.rethrow(importSpecResult.getError().get(0));
    }
    long totalBytes = getImportSizeBytes(importSpecResult);
    ManagedObjectReference lease = getVimPort().importVApp(resourcePool, importSpecResult.getImportSpec(), vmFolder, host);
    LeaseProgressUpdater leaseUpdater = new LeaseProgressUpdater(this.connection, lease, totalBytes);
    GetMoRef get = new GetMoRef(this.connection);
    HttpNfcLeaseInfo httpNfcLeaseInfo;
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
    try {
        leaseUpdater.awaitReady();
        logger.info("Lease ready");
        // start updating the lease
        leaseUpdater.start(executorService);
        httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
        List<HttpNfcLeaseDeviceUrl> deviceUrls = httpNfcLeaseInfo.getDeviceUrl();
        String ip = this.connection.getURI().getHost();
        String basePath = extractBasePath(ovfUri);
        for (HttpNfcLeaseDeviceUrl deviceUrl : deviceUrls) {
            String deviceKey = deviceUrl.getImportKey();
            for (OvfFileItem ovfFileItem : importSpecResult.getFileItem()) {
                if (deviceKey.equals(ovfFileItem.getDeviceId())) {
                    logger.debug("Importing device id: {}", deviceKey);
                    String sourceUri = computeDiskSourceUri(basePath, ovfFileItem);
                    String uploadUri = makUploadUri(ip, deviceUrl);
                    uploadVmdkFile(ovfFileItem, sourceUri, uploadUri, leaseUpdater, this.ovfRetriever.getClient());
                    logger.info("Completed uploading VMDK file {}", sourceUri);
                }
            }
        }
        // complete lease
        leaseUpdater.complete();
    } catch (Exception e) {
        leaseUpdater.abort(VimUtils.convertExceptionToFault(e));
        logger.info("Error importing ovf", e);
        throw e;
    } finally {
        executorService.shutdown();
    }
    httpNfcLeaseInfo = get.entityProp(lease, PROP_INFO);
    ManagedObjectReference entity = httpNfcLeaseInfo.getEntity();
    // as this is an OVF it makes sense to enable the OVF transport
    // only the guestInfo is enabled by default
    VmConfigSpec spec = new VmConfigSpec();
    spec.getOvfEnvironmentTransport().add(TRANSPORT_GUESTINFO);
    spec.getOvfEnvironmentTransport().add(TRANSPORT_ISO);
    VirtualMachineConfigSpec reconfig = new VirtualMachineConfigSpec();
    reconfig.setVAppConfig(spec);
    ManagedObjectReference reconfigTask = getVimPort().reconfigVMTask(entity, reconfig);
    VimUtils.waitTaskEnd(this.connection, reconfigTask);
    return entity;
}
Also used : OvfFileItem(com.vmware.vim25.OvfFileItem) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OvfCreateImportSpecResult(com.vmware.vim25.OvfCreateImportSpecResult) FinderException(com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException) IOException(java.io.IOException) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) OvfCreateImportSpecParams(com.vmware.vim25.OvfCreateImportSpecParams) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) HttpNfcLeaseInfo(com.vmware.vim25.HttpNfcLeaseInfo) VmConfigSpec(com.vmware.vim25.VmConfigSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) HttpNfcLeaseDeviceUrl(com.vmware.vim25.HttpNfcLeaseDeviceUrl)

Example 3 with KeyValue

use of com.vmware.vim25.KeyValue in project cs-actions by CloudSlang.

the class DeployOvfTemplateService method createLeaseSetup.

protected ImmutablePair<ManagedObjectReference, OvfCreateImportSpecResult> createLeaseSetup(final ConnectionResources connectionResources, final VmInputs vmInputs, final String templatePath, final Map<String, String> ovfNetworkMap, final Map<String, String> ovfPropertyMap) throws Exception {
    final ManagedObjectReference ovfManager = getOvfManager(connectionResources);
    final VmUtils vmUtils = new VmUtils();
    final ManagedObjectReference resourcePool;
    if (StringUtilities.isBlank(vmInputs.getClusterName())) {
        resourcePool = vmUtils.getMorResourcePool(vmInputs.getResourcePool(), connectionResources);
    } else {
        ManagedObjectReference clusterMor = new MorObjectHandler().getSpecificMor(connectionResources, connectionResources.getMorRootFolder(), ClusterParameter.CLUSTER_COMPUTE_RESOURCE.getValue(), vmInputs.getClusterName());
        resourcePool = vmUtils.getMorResourcePoolFromCluster(connectionResources, clusterMor, vmInputs.getResourcePool());
    }
    final ManagedObjectReference hostMor = vmUtils.getMorHost(vmInputs.getHostname(), connectionResources, null);
    final ManagedObjectReference datastoreMor = vmUtils.getMorDataStore(vmInputs.getDataStore(), connectionResources, null, vmInputs);
    final ManagedObjectReference folderMor = vmUtils.getMorFolder(vmInputs.getFolderName(), connectionResources);
    final List<OvfNetworkMapping> ovfNetworkMappings = getOvfNetworkMappings(ovfNetworkMap, connectionResources);
    final List<KeyValue> ovfPropertyMappings = getOvfPropertyMappings(ovfPropertyMap);
    final OvfCreateImportSpecResult importSpecResult = connectionResources.getVimPortType().createImportSpec(ovfManager, getOvfTemplateAsString(templatePath), resourcePool, datastoreMor, getOvfCreateImportSpecParams(vmInputs, hostMor, ovfNetworkMappings, ovfPropertyMappings));
    checkImportSpecResultForErrors(importSpecResult);
    final ManagedObjectReference httpNfcLease = OvfUtils.getHttpNfcLease(connectionResources, importSpecResult.getImportSpec(), resourcePool, hostMor, folderMor);
    return ImmutablePair.of(httpNfcLease, importSpecResult);
}
Also used : KeyValue(com.vmware.vim25.KeyValue) OvfNetworkMapping(com.vmware.vim25.OvfNetworkMapping) VmUtils(io.cloudslang.content.vmware.services.utils.VmUtils) OvfCreateImportSpecResult(com.vmware.vim25.OvfCreateImportSpecResult) MorObjectHandler(io.cloudslang.content.vmware.services.helpers.MorObjectHandler) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with KeyValue

use of com.vmware.vim25.KeyValue in project cs-actions by CloudSlang.

the class DeployOvfTemplateService method getOvfPropertyMappings.

private List<KeyValue> getOvfPropertyMappings(final Map<String, String> ovfPropertyMap) {
    final List<KeyValue> mappings = new ArrayList<>();
    for (Map.Entry<String, String> entry : ovfPropertyMap.entrySet()) {
        final KeyValue keyValue = new KeyValue();
        keyValue.setKey(entry.getKey());
        keyValue.setValue(entry.getValue());
        mappings.add(keyValue);
    }
    return mappings;
}
Also used : KeyValue(com.vmware.vim25.KeyValue) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 5 with KeyValue

use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.

the class OtlpProtobufUtils method annotationsFromAttributes.

@VisibleForTesting
static List<Annotation> annotationsFromAttributes(List<KeyValue> attributesList) {
    List<Annotation> annotations = new ArrayList<>();
    for (KeyValue attribute : attributesList) {
        String key = attribute.getKey().equals(SOURCE_KEY) ? "_source" : attribute.getKey();
        Annotation.Builder annotationBuilder = Annotation.newBuilder().setKey(key);
        if (!attribute.hasValue()) {
            annotationBuilder.setValue("");
        } else {
            annotationBuilder.setValue(fromAnyValue(attribute.getValue()));
        }
        annotations.add(annotationBuilder.build());
    }
    return annotations;
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Annotation(wavefront.report.Annotation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

KeyValue (io.opentelemetry.proto.common.v1.KeyValue)15 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)9 Annotation (wavefront.report.Annotation)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Span (io.opentelemetry.proto.trace.v1.Span)5 KeyValue (com.vmware.vim25.KeyValue)3 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 OvfCreateImportSpecParams (com.vmware.vim25.OvfCreateImportSpecParams)2 OvfCreateImportSpecResult (com.vmware.vim25.OvfCreateImportSpecResult)2 AnyValue (io.opentelemetry.proto.common.v1.AnyValue)2 ArrayValue (io.opentelemetry.proto.common.v1.ArrayValue)2 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 HttpNfcLeaseDeviceUrl (com.vmware.vim25.HttpNfcLeaseDeviceUrl)1 HttpNfcLeaseInfo (com.vmware.vim25.HttpNfcLeaseInfo)1 KeyAnyValue (com.vmware.vim25.KeyAnyValue)1 OvfFileItem (com.vmware.vim25.OvfFileItem)1