/*- * ============LICENSE_START======================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package com.woorea.openstack.nova.api.extensions; import java.util.Map; import com.woorea.openstack.base.client.Entity; import com.woorea.openstack.base.client.HttpMethod; import com.woorea.openstack.base.client.OpenStackClient; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.nova.model.HostAggregate; import com.woorea.openstack.nova.model.HostAggregates; public class AggregatesExtension { private final OpenStackClient CLIENT; public AggregatesExtension(OpenStackClient client) { CLIENT = client; } public List list() { return new List(); } public ShowAggregate showAggregate(String id) { return new ShowAggregate(id); } public UpdateAggregateMetadata updateAggregateMetadata(String id, String name, String availabilityZone) { return new UpdateAggregateMetadata(id, name, availabilityZone); } public CreateAggregate createAggregate(String aggregateName, String availabilityZoneName) { return new CreateAggregate(aggregateName, availabilityZoneName); } public DeleteAggregate deleteAggregate(String id) { return new DeleteAggregate(id); } public AddHost addHost(String aggregateId, String hostId) { return new AddHost(aggregateId, hostId); } public RemoveHost removeHost(String aggregateId, String hostId) { return new RemoveHost(hostId, aggregateId); } public SetMetadata setMetadata(String aggregateId, String key, String value) { return new SetMetadata(aggregateId, key, value); } public class List extends OpenStackRequest { public List() { super(CLIENT, HttpMethod.GET, "/os-aggregates", null, HostAggregates.class); } } public class ShowAggregate extends OpenStackRequest { public ShowAggregate(String id) { super(CLIENT, HttpMethod.GET, new StringBuffer("/os-aggregates/").append(id), null, HostAggregate.class); } } public class UpdateAggregateMetadata extends OpenStackRequest { public UpdateAggregateMetadata(String id, String name, String availabilityZone) { super(CLIENT, HttpMethod.PUT, new StringBuffer("/os-aggregates/").append(id), availabilityZone == null ? Entity.json("{\"aggregate\": {\"name\": \"" + name + "\" }}") : Entity.json("{\"aggregate\": {\"name\": \"" + name + "\", \"availability_zone\": \"" + availabilityZone + "\" }}"), HostAggregate.class); } } public class CreateAggregate extends OpenStackRequest { public CreateAggregate(String name, String availabilityZone) { super(CLIENT, HttpMethod.POST, new StringBuffer("/os-aggregates"), availabilityZone == null ? Entity.json("{\"aggregate\": {\"name\": \"" + name + "\", \"availability_zone\": null }}") : Entity.json("{\"aggregate\": {\"name\": \"" + name + "\", \"availability_zone\": \"" + availabilityZone + "\" }}"), HostAggregate.class); } } public class DeleteAggregate extends OpenStackRequest { public DeleteAggregate(String id) { super(CLIENT, HttpMethod.DELETE, new StringBuffer("/os-aggregates/").append(id), null, null); } } public class AddHost extends OpenStackRequest { public AddHost(String aggregateId, String hostId) { super(CLIENT, HttpMethod.POST, new StringBuffer("/os-aggregates/") .append(aggregateId).append("/action"), Entity.json("{\"add_host\": {\"host\": \"" + hostId + "\" }}"), HostAggregate.class); } } public class RemoveHost extends OpenStackRequest { public RemoveHost(String hostId, String aggregateId) { super(CLIENT, HttpMethod.POST, new StringBuffer("/os-aggregates/") .append(aggregateId).append("/action"), Entity.json("{\"remove_host\": {\"host\": \"" + hostId + "\" }}"), HostAggregate.class); } } public class SetMetadata extends OpenStackRequest { public SetMetadata(String aggregateId, String key, String value) { super(CLIENT, HttpMethod.POST, new StringBuffer("/os-aggregates/") .append(aggregateId).append("/action"), Entity.json("{\"set_metadata\": {\"metadata\": { \"" + key + "\": \"" + value + "\" }}}"), HostAggregate.class); } } }