Search in sources :

Example 1 with CategoryModel

use of com.vmware.cis.tagging.CategoryModel in project flowgate by vmware.

the class VCDataService method syncCustomAttributes.

private void syncCustomAttributes(SDDCSoftwareConfig vc) {
    try (VsphereClient vsphereClient = connectVsphere(vc)) {
        for (String key : VCConstants.hostCustomAttrMapping.values()) {
            vsphereClient.createCustomAttribute(key, VCConstants.HOSTSYSTEM);
        }
        // Add the PDU information;
        vsphereClient.createCustomAttribute(VCConstants.ASSET_PDUs, VCConstants.HOSTSYSTEM);
        // Add host switch information;
        vsphereClient.createCustomAttribute(VCConstants.ASSET_SWITCHs, VCConstants.HOSTSYSTEM);
    } catch (ConnectionException connectionException) {
        checkAndUpdateIntegrationStatus(vc, connectionException.getMessage());
        return;
    } catch (ExecutionException executionException) {
        if (executionException.getCause() instanceof InvalidLogin) {
            logger.error("Failed to push data to " + vc.getServerURL(), executionException);
            IntegrationStatus integrationStatus = vc.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail("Invalid username or password.");
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(vc);
            return;
        }
    } catch (Exception exception) {
        logger.error("Failed to sync the host metadata to VC ", exception);
        return;
    }
    try (HostTagClient client = new HostTagClient(vc.getServerURL(), vc.getUserName(), vc.getPassword(), !vc.isVerifyCert())) {
        client.initConnection();
        TagModel tag = client.getTagByName(VCConstants.locationAntiAffinityTagName);
        String categoryID;
        if (tag == null) {
            CategoryModel category = client.getTagCategoryByName(VCConstants.categoryName);
            if (category == null) {
                categoryID = client.createTagCategory(VCConstants.categoryName, VCConstants.categoryDescription, Cardinality.MULTIPLE);
            } else {
                categoryID = category.getId();
            }
            client.createTag(VCConstants.locationAntiAffinityTagName, VCConstants.locationAntiAffinityTagDescription, categoryID);
        }
    } catch (Exception exception) {
        logger.error("Faild to check the predefined tag information", exception);
    }
}
Also used : VsphereClient(com.vmware.flowgate.vcworker.client.VsphereClient) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) InvalidLogin(com.vmware.vim.binding.vim.fault.InvalidLogin) HostTagClient(com.vmware.flowgate.vcworker.client.HostTagClient) CategoryModel(com.vmware.cis.tagging.CategoryModel) ExecutionException(java.util.concurrent.ExecutionException) TagModel(com.vmware.cis.tagging.TagModel) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CategoryModel (com.vmware.cis.tagging.CategoryModel)1 TagModel (com.vmware.cis.tagging.TagModel)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1 HostTagClient (com.vmware.flowgate.vcworker.client.HostTagClient)1 VsphereClient (com.vmware.flowgate.vcworker.client.VsphereClient)1 InvalidLogin (com.vmware.vim.binding.vim.fault.InvalidLogin)1 ConnectionException (com.vmware.vim.vmomi.client.exception.ConnectionException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1