use of cz.metacentrum.perun.openapi.model.InputSetHostAttribute in project perun by CESNET.
the class SetFacilityHostsAttributeValue method executeCommand.
@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
int facilityId = this.getFacilityId(ctx, true);
int attributeDefinitionId = this.getAttributeDefinitionId(ctx, true);
String value = ctx.getCommandLine().getOptionValue("w");
Object attributeValue;
if (value.matches("\\d+")) {
attributeValue = Integer.valueOf(value);
} else {
attributeValue = value;
}
PerunRPC perunRPC = ctx.getPerunRPC();
AttributesManagerApi attributesManager = perunRPC.getAttributesManager();
List<Host> hosts = perunRPC.getFacilitiesManager().getHosts(facilityId);
for (Host host : hosts) {
Attribute attribute = attributesManager.getHostAttributeById(host.getId(), attributeDefinitionId);
attribute.setValue(attributeValue);
System.out.println("setting attribute on host " + host.getHostname() + " to " + attributeValue + " ...");
attributesManager.setHostAttribute(new InputSetHostAttribute().host(host.getId()).attribute(attribute));
}
System.out.println("OK");
}
Aggregations