Search in sources :

Example 1 with Host

use of cz.metacentrum.perun.openapi.model.Host 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");
}
Also used : PerunRPC(cz.metacentrum.perun.openapi.PerunRPC) AttributesManagerApi(cz.metacentrum.perun.openapi.AttributesManagerApi) Attribute(cz.metacentrum.perun.openapi.model.Attribute) InputSetHostAttribute(cz.metacentrum.perun.openapi.model.InputSetHostAttribute) Host(cz.metacentrum.perun.openapi.model.Host) InputSetHostAttribute(cz.metacentrum.perun.openapi.model.InputSetHostAttribute)

Aggregations

AttributesManagerApi (cz.metacentrum.perun.openapi.AttributesManagerApi)1 PerunRPC (cz.metacentrum.perun.openapi.PerunRPC)1 Attribute (cz.metacentrum.perun.openapi.model.Attribute)1 Host (cz.metacentrum.perun.openapi.model.Host)1 InputSetHostAttribute (cz.metacentrum.perun.openapi.model.InputSetHostAttribute)1