use of com.vmware.cis.tagging.TagModel 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);
}
}
use of com.vmware.cis.tagging.TagModel in project flowgate by vmware.
the class HostTagClient method getPredefinedTags.
public List<TagModel> getPredefinedTags() {
List<String> tagIDs = getTags();
List<TagModel> tags = new ArrayList<TagModel>();
for (String tagID : tagIDs) {
TagModel tag = taggingService.get(tagID);
if (VCConstants.predefinedTags.keySet().contains(tag.getName())) {
tags.add(tag);
if (tags.size() == VCConstants.predefinedTags.size()) {
break;
}
}
}
return tags;
}
use of com.vmware.cis.tagging.TagModel in project flowgate by vmware.
the class VCDataService method validClusterHostsLocationAntiaffinity.
private void validClusterHostsLocationAntiaffinity(SDDCSoftwareConfig vcInfo, Map<String, Asset> assetDictionary, List<ServerMapping> validMapping) {
Map<String, Set<Asset>> assetsByCluster = new HashMap<String, Set<Asset>>();
for (ServerMapping validServer : validMapping) {
Asset asset = assetDictionary.get(validServer.getAsset());
if (null != validServer.getVcClusterMobID()) {
if (!assetsByCluster.containsKey(validServer.getVcClusterMobID())) {
assetsByCluster.put(validServer.getVcClusterMobID(), new HashSet<Asset>());
}
assetsByCluster.get(validServer.getVcClusterMobID()).add(asset);
}
}
Set<Asset> needTagHost = new HashSet<>();
for (String clusterMob : assetsByCluster.keySet()) {
if (assetsByCluster.get(clusterMob).size() > 1) {
String location = "%s-%s-%s-%s-%s-%s-%d";
Map<String, Set<Asset>> assetsByLocation = new HashMap<String, Set<Asset>>();
for (Asset asset : assetsByCluster.get(clusterMob)) {
String assetLocation = String.format(location, asset.getRegion(), asset.getCountry(), asset.getCity(), asset.getBuilding(), asset.getFloor(), asset.getCabinetAssetNumber(), asset.getCabinetUnitPosition());
if (!assetsByLocation.containsKey(assetLocation)) {
assetsByLocation.put(assetLocation, new HashSet<Asset>());
}
assetsByLocation.get(assetLocation).add(asset);
}
for (String local : assetsByLocation.keySet()) {
if (assetsByLocation.get(local).size() > 1) {
// now we need to tag the hosts
needTagHost.addAll(assetsByLocation.get(local));
}
}
}
}
if (!needTagHost.isEmpty()) {
Map<String, ServerMapping> assetIDMapping = new HashMap<String, ServerMapping>();
for (ServerMapping mapping : validMapping) {
assetIDMapping.put(mapping.getAsset(), mapping);
}
try (HostTagClient client = new HostTagClient(vcInfo.getServerURL(), vcInfo.getUserName(), vcInfo.getPassword(), !vcInfo.isVerifyCert())) {
client.initConnection();
TagModel locationTag = client.getTagByName(VCConstants.locationAntiAffinityTagName);
for (Asset a : needTagHost) {
client.attachTagToHost(locationTag.getId(), assetIDMapping.get(a.getId()).getVcMobID());
}
} catch (Exception exception) {
logger.warn("Failed to tag the host, will try to tag it in next run.", exception);
}
}
}
Aggregations