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);
}
}
Aggregations