http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java deleted file mode 100644 index 2a478db..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/event/Event.java +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.event; - -import java.util.Date; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.SeverityType; -import com.abiquo.server.core.event.EventDto; - -public class Event extends DomainWrapper<EventDto> { - /** - * Constructor to be used only by the builder. - */ - protected Event(final ApiContext<AbiquoApi> context, final EventDto target) { - super(context, target); - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public String getUser() { - return target.getUser(); - } - - public void setUser(final String user) { - target.setUser(user); - } - - public String getStacktrace() { - return target.getStacktrace(); - } - - public void setStacktrace(final String stacktrace) { - target.setStacktrace(stacktrace); - } - - public String getComponent() { - return target.getComponent(); - } - - public void setComponent(final String component) { - target.setComponent(component); - } - - public String getPerformedBy() { - return target.getPerformedBy(); - } - - public void setPerformedBy(final String performedBy) { - target.setPerformedBy(performedBy); - } - - public Integer getIdNetwork() { - return target.getIdNetwork(); - } - - public void setIdNetwork(final Integer idNetwork) { - target.setIdNetwork(idNetwork); - } - - public String getIdVolume() { - return target.getIdVolume(); - } - - public void setIdVolume(final String idVolume) { - target.setIdVolume(idVolume); - } - - public String getStoragePool() { - return target.getStoragePool(); - } - - public void setStoragePool(final String storagePool) { - target.setStoragePool(storagePool); - } - - public Date getTimestamp() { - return target.getTimestamp(); - } - - public void setTimestamp(final Date timestamp) { - target.setTimestamp(timestamp); - } - - public String getVirtualApp() { - return target.getVirtualApp(); - } - - public void setVirtualApp(final String virtualApp) { - target.setVirtualApp(virtualApp); - } - - public String getDatacenter() { - return target.getDatacenter(); - } - - public void setDatacenter(final String datacenter) { - target.setDatacenter(datacenter); - } - - public String getActionPerformed() { - return target.getActionPerformed(); - } - - public void setActionPerformed(final String actionPerformed) { - target.setActionPerformed(actionPerformed); - } - - public Integer getIdVirtualMachine() { - return target.getIdVirtualMachine(); - } - - public void setIdVirtualMachine(final Integer idVirtualMachine) { - target.setIdVirtualMachine(idVirtualMachine); - } - - public String getVirtualDatacenter() { - return target.getVirtualDatacenter(); - } - - public void setVirtualDatacenter(final String virtualDatacenter) { - target.setVirtualDatacenter(virtualDatacenter); - } - - public String getEnterprise() { - return target.getEnterprise(); - } - - public void setEnterprise(final String enterprise) { - target.setEnterprise(enterprise); - } - - public String getStorageSystem() { - return target.getStorageSystem(); - } - - public void setStorageSystem(final String storageSystem) { - target.setStorageSystem(storageSystem); - } - - public Integer getIdPhysicalMachine() { - return target.getIdPhysicalMachine(); - } - - public void setIdPhysicalMachine(final Integer idPhysicalMachine) { - target.setIdPhysicalMachine(idPhysicalMachine); - } - - public SeverityType getSeverity() { - return target.getSeverity(); - } - - public void setSeverity(final SeverityType severity) { - target.setSeverity(severity); - } - - public Integer getIdStorageSystem() { - return target.getIdStorageSystem(); - } - - public void setIdStorageSystem(final Integer idStorageSystem) { - target.setIdStorageSystem(idStorageSystem); - } - - public Integer getIdDatacenter() { - return target.getIdDatacenter(); - } - - public void setIdDatacenter(final Integer idDatacenter) { - target.setIdDatacenter(idDatacenter); - } - - public String getNetwork() { - return target.getNetwork(); - } - - public void setNetwork(final String network) { - target.setNetwork(network); - } - - public String getPhysicalMachine() { - return target.getPhysicalMachine(); - } - - public void setPhysicalMachine(final String physicalMachine) { - target.setPhysicalMachine(physicalMachine); - } - - public String getRack() { - return target.getRack(); - } - - public void setRack(final String rack) { - target.setRack(rack); - } - - public Integer getIdVirtualDatacenter() { - return target.getIdVirtualDatacenter(); - } - - public void setIdVirtualDatacenter(final Integer idVirtualDatacenter) { - target.setIdVirtualDatacenter(idVirtualDatacenter); - } - - public Integer getIdSubnet() { - return target.getIdSubnet(); - } - - public void setIdSubnet(final Integer idSubnet) { - target.setIdSubnet(idSubnet); - } - - public String getVolume() { - return target.getVolume(); - } - - public void setVolume(final String volume) { - target.setVolume(volume); - } - - public String getSubnet() { - return target.getSubnet(); - } - - public void setSubnet(final String subnet) { - target.setSubnet(subnet); - } - - public Integer getIdUser() { - return target.getIdUser(); - } - - public void setIdUser(final Integer idUser) { - target.setIdUser(idUser); - } - - public String getIdStoragePool() { - return target.getIdStoragePool(); - } - - public void setIdStoragePool(final String idStoragePool) { - target.setIdStoragePool(idStoragePool); - } - - public Integer getIdRack() { - return target.getIdRack(); - } - - public void setIdRack(final Integer idRack) { - target.setIdRack(idRack); - } - - public String getVirtualMachine() { - return target.getVirtualMachine(); - } - - public void setVirtualMachine(final String virtualMachine) { - target.setVirtualMachine(virtualMachine); - } - - public Integer getIdVirtualApp() { - return target.getIdVirtualApp(); - } - - public void setIdVirtualApp(final Integer idVirtualApp) { - target.setIdVirtualApp(idVirtualApp); - } - - public Integer getIdEnterprise() { - return target.getIdEnterprise(); - } - - public void setIdEnterprise(final Integer idEnterprise) { - target.setIdEnterprise(idEnterprise); - } - - @Override - public String toString() { - return "Event [id=" + getId() + ", idUser=" + getIdUser() + ", user=" + getUser() + ", idEnterprise=" - + getIdEnterprise() + ", enterprise=" + getEnterprise() + ", actionPerformed=" + getActionPerformed() - + ", component=" + getComponent() + ", idDatacenter=" + getIdDatacenter() + ", datacenter=" - + getDatacenter() + ", idStoragePool=" + getIdStoragePool() + ", storagePool=" + getStoragePool() - + ", idVolume=" + getIdVolume() + ", volume=" + getVolume() + ", idNetwork=" + getIdNetwork() - + ", network=" + getNetwork() + ", idPhysicalMachine=" + getIdPhysicalMachine() + ", physicalMachine=" - + getPhysicalMachine() + ", idRack=" + getIdRack() + ", rack=" + getRack() + ", idStorageSystem=" - + getIdStorageSystem() + ", storageSystem=" + getStorageSystem() + ", idSubnet=" + getIdSubnet() - + ", subnet=" + getSubnet() + ", idVirtualApp=" + getIdVirtualApp() + ", virtualApp=" + getVirtualApp() - + ", idVirtualDatacenter=" + getIdVirtualDatacenter() + ", virtualDatacenter=" + getVirtualDatacenter() - + ", idVirtualMachine=" + getIdVirtualMachine() + ", virtualMachine=" + getVirtualMachine() - + ", stacktrace=" + getStacktrace() + ", performedBy=" + getPerformedBy() + ", severity=" + getSeverity() - + "]"; - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java deleted file mode 100644 index 183b981..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/event/options/EventOptions.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.event.options; - -import java.util.Date; -import java.util.Map; -import java.util.Map.Entry; - -import org.jclouds.abiquo.domain.options.FilterOptions.BaseFilterOptionsBuilder; -import org.jclouds.http.options.BaseHttpRequestOptions; - -import com.abiquo.model.enumerator.ComponentType; -import com.abiquo.model.enumerator.EventType; -import com.abiquo.model.enumerator.SeverityType; -import com.google.common.collect.Maps; - -/** - * Available options to query events. - */ -public class EventOptions extends BaseHttpRequestOptions { - public static Builder builder() { - return new Builder(); - } - - @Override - protected Object clone() throws CloneNotSupportedException { - EventOptions options = new EventOptions(); - options.queryParameters.putAll(queryParameters); - return options; - } - - public static class Builder extends BaseFilterOptionsBuilder<Builder> { - private Map<String, String> filters = Maps.newHashMap(); - - public Builder filters(final Map<String, String> filters) { - this.filters = filters; - return this; - } - - public Builder severity(final SeverityType severity) { - this.filters.put("severity", severity.name()); - return this; - } - - public Builder component(final ComponentType component) { - this.filters.put("component", component.name()); - return this; - } - - public Builder actionPerformed(final EventType action) { - this.filters.put("actionperformed", action.name()); - return this; - } - - public Builder datacenterName(final String dc) { - this.filters.put("datacenter", dc); - return this; - } - - public Builder rackName(final String rack) { - this.filters.put("rack", rack); - return this; - } - - public Builder physicalMachineName(final String pm) { - this.filters.put("physicalmachine", pm); - return this; - } - - public Builder storageSystemName(final String ss) { - this.filters.put("storagesystem", ss); - return this; - } - - public Builder storagePoolName(final String sp) { - this.filters.put("storagepool", sp); - return this; - } - - public Builder volumeName(final String volume) { - this.filters.put("volume", volume); - return this; - } - - public Builder networkName(final String network) { - this.filters.put("network", network); - return this; - } - - public Builder subnetName(final String subnet) { - this.filters.put("subnet", subnet); - return this; - } - - public Builder enterpriseName(final String ent) { - this.filters.put("enterprise", ent); - return this; - } - - public Builder userName(final String user) { - this.filters.put("user", user); - return this; - } - - public Builder virtualDatacenterName(final String vdc) { - this.filters.put("virtualdatacenter", vdc); - return this; - } - - public Builder virtualAppName(final String vapp) { - this.filters.put("virtualapp", vapp); - return this; - } - - public Builder virtualMachineName(final String vm) { - this.filters.put("virtualMachine", vm); - return this; - } - - public Builder performedBy(final String pb) { - this.filters.put("performedBy", pb); - return this; - } - - public Builder description(final String description) { - this.filters.put("stacktrace", description); - return this; - } - - public Builder dateFrom(final Date date) { - this.filters.put("datefrom", String.valueOf(date.getTime())); - return this; - } - - public Builder dateTo(final Date date) { - this.filters.put("dateTo", String.valueOf(date.getTime())); - return this; - } - - public EventOptions build() { - EventOptions options = new EventOptions(); - - for (Entry<String, String> filter : filters.entrySet()) { - options.queryParameters.put(filter.getKey(), filter.getValue()); - } - - return addFilterOptions(options); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java deleted file mode 100644 index c9df896..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/AbiquoException.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.exception; - -import static com.google.common.collect.Iterables.any; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; - -import java.util.List; - -import javax.ws.rs.core.Response.Status; - -import com.abiquo.model.transport.error.ErrorDto; -import com.abiquo.model.transport.error.ErrorsDto; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; - -/** - * Abiquo API exception. - */ -public class AbiquoException extends RuntimeException { - - private static final long serialVersionUID = 3627304442037389536L; - - /** The HTTP status. */ - private Status httpStatus; - - /** The errors. */ - private ErrorsDto errors; - - public AbiquoException(final Status httpStatus, final ErrorsDto errors) { - super(); - this.httpStatus = httpStatus; - this.errors = errors; - } - - /** - * Check if there is an error with the given code. - */ - public boolean hasError(final String code) { - return any(errors.getCollection(), code(code)); - } - - /** - * Find the first error with the given code. - */ - public ErrorDto findError(final String code) { - return find(errors.getCollection(), code(code), null); - } - - /** - * Find all errors with the given code. - */ - public List<ErrorDto> findErrors(final String code) { - return ImmutableList.copyOf(filter(errors.getCollection(), code(code))); - } - - /** - * Get the number of errors. - */ - public int numErrors() { - return errors.getCollection().size(); - } - - /** - * Get the list of all errors. - */ - public List<ErrorDto> getErrors() { - return errors.getCollection(); - } - - /** - * Get the HTTP status code. - */ - public int getHttpStatusCode() { - return httpStatus.getStatusCode(); - } - - /** - * Get the HTTP status name. - */ - public String getHttpStatusName() { - return httpStatus.getReasonPhrase(); - } - - /** - * Get the HTTP status. - */ - public Status getHttpStatus() { - return httpStatus; - } - - @Override - public String getMessage() { - return errors.toString(); - } - - private static Predicate<ErrorDto> code(final String code) { - return new Predicate<ErrorDto>() { - @Override - public boolean apply(ErrorDto input) { - return input.getCode().equals(code); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java deleted file mode 100644 index 7587ec2..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/BuilderException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.exception; - -/** - * Exception thrown during domain object building. - */ -public class BuilderException extends RuntimeException { - - private static final long serialVersionUID = 540948631643049450L; - - /** - * Creates a {@link BuilderException} with the given message. - * - * @param message - * The message. - */ - public BuilderException(String message) { - super(message); - } - - /** - * Creates a {@link BuilderException} with the given cause. - * - * @param cause - * The cause. - */ - public BuilderException(Throwable cause) { - super(cause); - } - - /** - * Creates a {@link BuilderException} with the given message and cause. - * - * @param message - * The message. - * @param cause - * The cause. - */ - public BuilderException(String message, Throwable cause) { - super(message, cause); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java deleted file mode 100644 index f2a4f37..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/exception/WrapperException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.exception; - -import org.jclouds.abiquo.domain.DomainWrapper; - -import com.abiquo.model.transport.SingleResourceTransportDto; - -/** - * Exception thrown during the wrapping process. - */ -public class WrapperException extends RuntimeException { - - private static final long serialVersionUID = 3756802225851609583L; - - private Class<? extends DomainWrapper<?>> wrapperClass; - - private SingleResourceTransportDto target; - - public WrapperException(final Class<? extends DomainWrapper<?>> wrapperClass, - final SingleResourceTransportDto target, Throwable cause) { - super(cause); - this.wrapperClass = wrapperClass; - this.target = target; - } - - @Override - public String getMessage() { - String msg = "Could not wrap object [" + target + "] in class " + wrapperClass.getName() + ": "; - return msg + super.getMessage(); - } - - public Class<? extends DomainWrapper<?>> getWrapperClass() { - return wrapperClass; - } - - public void setWrapperClass(Class<? extends DomainWrapper<?>> wrapperClass) { - this.wrapperClass = wrapperClass; - } - - public SingleResourceTransportDto getTarget() { - return target; - } - - public void setTarget(SingleResourceTransportDto target) { - this.target = target; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java deleted file mode 100644 index 58322cf..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datacenter.java +++ /dev/null @@ -1,794 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.infrastructure; - -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.transform; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.enterprise.Limits; -import org.jclouds.abiquo.domain.infrastructure.options.DatacenterOptions; -import org.jclouds.abiquo.domain.infrastructure.options.IpmiOptions; -import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; -import org.jclouds.abiquo.domain.network.Network; -import org.jclouds.abiquo.domain.network.NetworkServiceType; -import org.jclouds.abiquo.domain.network.options.NetworkOptions; -import org.jclouds.abiquo.predicates.NetworkServiceTypePredicates; -import org.jclouds.collect.PagedIterable; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.enumerator.MachineIpmiState; -import com.abiquo.model.enumerator.MachineState; -import com.abiquo.model.enumerator.NetworkType; -import com.abiquo.model.enumerator.RemoteServiceType; -import com.abiquo.model.enumerator.VlanTagAvailabilityType; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.abiquo.server.core.cloud.HypervisorTypeDto; -import com.abiquo.server.core.cloud.HypervisorTypesDto; -import com.abiquo.server.core.enterprise.DatacentersLimitsDto; -import com.abiquo.server.core.infrastructure.DatacenterDto; -import com.abiquo.server.core.infrastructure.MachineDto; -import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; -import com.abiquo.server.core.infrastructure.MachineStateDto; -import com.abiquo.server.core.infrastructure.MachinesDto; -import com.abiquo.server.core.infrastructure.RackDto; -import com.abiquo.server.core.infrastructure.RacksDto; -import com.abiquo.server.core.infrastructure.RemoteServicesDto; -import com.abiquo.server.core.infrastructure.network.NetworkServiceTypeDto; -import com.abiquo.server.core.infrastructure.network.NetworkServiceTypesDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworksDto; -import com.abiquo.server.core.infrastructure.network.VlanTagAvailabilityDto; -import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; -import com.abiquo.server.core.infrastructure.storage.StorageDevicesDto; -import com.abiquo.server.core.infrastructure.storage.StorageDevicesMetadataDto; -import com.abiquo.server.core.infrastructure.storage.TiersDto; -import com.google.common.base.Function; - -/** - * Adds high level functionality to {@link DatacenterDto}. - * - * @see API: <a - * href="http://community.abiquo.com/display/ABI20/DatacenterResource"> - * http://community.abiquo.com/display/ABI20/DatacenterResource</a> - */ -public class Datacenter extends DomainWrapper<DatacenterDto> { - /** - * IP address of the datacenter (used to create all remote services with the - * same ip). - */ - private String ip; - - /** - * Constructor to be used only by the builder. - */ - protected Datacenter(final ApiContext<AbiquoApi> context, final DatacenterDto target) { - super(context, target); - } - - // Domain operations - - /** - * Delete the datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-DeleteanexistingDatacenter" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- DeleteanexistingDatacenter</a> - */ - public void delete() { - context.getApi().getInfrastructureApi().deleteDatacenter(target); - target = null; - } - - /** - * Create a datacenter in Abiquo. This method will perform several calls to - * the API if remote services have been defined in the builder. Different - * remote services will be created depending on the {@link AbiquoEdition}. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-CreateanewDatacenter" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- CreateanewDatacenter</a> - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-CreateaRemoteService" - * > http://community.abiquo.com/display/ABI20/RemoteServiceResource# - * RemoteServiceResource- CreateaRemoteService</a> - */ - public void save() { - // Datacenter must be persisted first, so links get populated in the - // target object - target = context.getApi().getInfrastructureApi().createDatacenter(target); - - // If remote services data is set, create remote services. - if (ip != null) { - createRemoteServices(); - } - } - - /** - * Update datacenter information in the server with the data from this - * datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Updateanexistingdatacenter" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Updateanexistingdatacenter </a> - */ - public void update() { - target = context.getApi().getInfrastructureApi().updateDatacenter(target); - } - - /** - * The cloud administrator will find it useful to know if a VLAN Tag is - * already assigned before creating a new Public or External Network. This - * method provides this functionality: Check if a tag is available inside the - * Datacenter. Please refer link for more information. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource-Checkthetagavailability" - * > http://community.abiquo.com/display/ABI20/PublicNetworkResource# - * PublicNetworkResource- Checkthetagavailability</a> - * @return Availability state of the tag. - */ - public VlanTagAvailabilityType checkTagAvailability(final int tag) { - VlanTagAvailabilityDto availability = context.getApi().getInfrastructureApi().checkTagAvailability(target, tag); - - return availability.getAvailable(); - } - - // Children access - - /** - * Retrieve the list of unmanaged racks in this datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrievealistofRacks" - * > http://community.abiquo.com/display/ABI20/RackResource#RackResource - * - RetrievealistofRacks</a> - * @return List of unmanaged racks in this datacenter. - */ - public Iterable<Rack> listRacks() { - RacksDto racks = context.getApi().getInfrastructureApi().listRacks(target); - return wrap(context, Rack.class, racks.getCollection()); - } - - /** - * Retrieve a single unmanaged rack. - * - * @param id - * Unique ID of the rack in this datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaRack" - * > - * http://community.abiquo.com/display/ABI20/RackResource#RackResource- - * RetrieveaRack</a> - * @return Unmanaged rack with the given id or <code>null</code> if it does - * not exist. - */ - public Rack getRack(final Integer id) { - RackDto rack = context.getApi().getInfrastructureApi().getRack(target, id); - return wrap(context, Rack.class, rack); - } - - /** - * Retrieve the list of supported storage devices. - * <p> - * This method will get the list of the storage devices that are supported in - * the datacenter. - * - * @return List of supported storage devices. This list has only the default - * information for the storage devices, such as the management and - * iscsi ports, or the default credentials to access the device. - */ - public Iterable<StorageDeviceMetadata> listSupportedStorageDevices() { - StorageDevicesMetadataDto devices = context.getApi().getInfrastructureApi().listSupportedStorageDevices(target); - return wrap(context, StorageDeviceMetadata.class, devices.getCollection()); - } - - /** - * Retrieve the list of storage devices in this datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Retrievethelistofstoragedevices" - * > http://community.abiquo.com/display/ABI20/StorageDeviceResource# - * StorageDeviceResource- Retrievethelistofstoragedevices</a> - * @return List of storage devices in this datacenter. - */ - public Iterable<StorageDevice> listStorageDevices() { - StorageDevicesDto devices = context.getApi().getInfrastructureApi().listStorageDevices(target); - return wrap(context, StorageDevice.class, devices.getCollection()); - } - - /** - * Retrieve a single storage device. - * - * @param id - * Unique ID of the storage device in this datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/StorageDeviceResource#StorageDeviceResource-Retrieveastoragedevice" - * > http://community.abiquo.com/display/ABI20/StorageDeviceResource# - * StorageDeviceResource- Retrieveastoragedevice</a> - * @return Storage device with the given id or <code>null</code> if it does - * not exist. - */ - public StorageDevice getStorageDevice(final Integer id) { - StorageDeviceDto device = context.getApi().getInfrastructureApi().getStorageDevice(target, id); - return wrap(context, StorageDevice.class, device); - } - - /** - * Return the list of Network Service Types defined in a datacenter. By - * default, a Network Service Type called 'Service Network' will be created - * with the datacenter. - * - * @return List of network services in this datacenter. - */ - public Iterable<NetworkServiceType> listNetworkServiceTypes() { - NetworkServiceTypesDto dtos = context.getApi().getInfrastructureApi().listNetworkServiceTypes(target); - return wrap(context, NetworkServiceType.class, dtos.getCollection()); - } - - /** - * Retrieve a single network service type. - * - * @param id - * Unique ID of the network service type in this datacenter. - * @return Network Service Type with the given id or <code>null</code> if it - * does not exist. - */ - public NetworkServiceType getNetworkServiceType(final Integer id) { - NetworkServiceTypeDto nst = context.getApi().getInfrastructureApi().getNetworkServiceType(target, id); - return wrap(context, NetworkServiceType.class, nst); - } - - /** - * Return the default network service type used by the datacenter. This - * datacenter will be the one used by {@link PrivateNetwork}. Even it can not - * be deleted, it can be modified. - * - * @return the defult {@link NetworkServiceType} - */ - public NetworkServiceType defaultNetworkServiceType() { - return find(listNetworkServiceTypes(), NetworkServiceTypePredicates.isDefault()); - } - - /** - * Retrieve the list of remote services of this datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/RemoteServiceResource#RemoteServiceResource-RetrievealistofRemoteServices" - * > http://community.abiquo.com/display/ABI20/RemoteServiceResource# - * RemoteServiceResource- RetrievealistofRemoteServices</a> - * @return List of remote services in this datacenter. - */ - public Iterable<RemoteService> listRemoteServices() { - RemoteServicesDto remoteServices = context.getApi().getInfrastructureApi().listRemoteServices(target); - return wrap(context, RemoteService.class, remoteServices.getCollection()); - } - - private void createRemoteServices() { - createRemoteService(RemoteServiceType.BPM_SERVICE); - createRemoteService(RemoteServiceType.DHCP_SERVICE); - createRemoteService(RemoteServiceType.STORAGE_SYSTEM_MONITOR); - createRemoteService(RemoteServiceType.APPLIANCE_MANAGER); - createRemoteService(RemoteServiceType.VIRTUAL_SYSTEM_MONITOR); - createRemoteService(RemoteServiceType.NODE_COLLECTOR); - createRemoteService(RemoteServiceType.VIRTUAL_FACTORY); - } - - private void createRemoteService(final RemoteServiceType type) { - RemoteService.builder(context, this).type(type).ip(this.ip).build().save(); - } - - /** - * Retrieve the list of datacenter limits by all enterprises. The Datacenter - * Limits resource allows you to assign datacenters and allocated resources - * in them to be used by an enterprise. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrievelimitsbydatacenter" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrievelimitsbydatacenter</a> - * @return List of datacenter limits by all enterprises. - */ - public Iterable<Limits> listLimits() { - DatacentersLimitsDto dto = context.getApi().getInfrastructureApi().listLimits(this.unwrap()); - return DomainWrapper.wrap(context, Limits.class, dto.getCollection()); - } - - /** - * Retrieve the list of tiers in ths datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/TierResource#TierResource-Retrievethelistoftiers" - * > - * http://community.abiquo.com/display/ABI20/TierResource#TierResource- - * Retrievethelistoftiers </a> - * @return List of tiers in this datacenter. - */ - public Iterable<Tier> listTiers() { - TiersDto dto = context.getApi().getInfrastructureApi().listTiers(this.unwrap()); - return DomainWrapper.wrap(context, Tier.class, dto.getCollection()); - } - - /** - * Retrieve the list of public, external and unmanaged networks in this - * datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource-Getthelistofpublicnetworks" - * > http://community.abiquo.com/display/ABI20/PublicNetworkResource# - * PublicNetworkResource- Getthelistofpublicnetworks</a> - * @return List of public, external and unmanaged networks in this - * datacenter. - */ - public Iterable<Network<?>> listNetworks() { - VLANNetworksDto networks = context.getApi().getInfrastructureApi().listNetworks(target); - return Network.wrapNetworks(context, networks.getCollection()); - } - - /** - * Retrieve the list of networks of this datacenter matching the given type. - * - * @param type - * Network type filter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource-Getthelistofpublicnetworks" - * > http://community.abiquo.com/display/ABI20/PublicNetworkResource# - * PublicNetworkResource- Getthelistofpublicnetworks</a> - * @return List of networks of this datacenter matching the given type. - */ - public Iterable<Network<?>> listNetworks(final NetworkType type) { - NetworkOptions options = NetworkOptions.builder().type(type).build(); - VLANNetworksDto networks = context.getApi().getInfrastructureApi().listNetworks(target, options); - return Network.wrapNetworks(context, networks.getCollection()); - } - - /** - * Retrieve a single public, external or unmanaged network from this - * datacenter. - * {@link org.jclouds.abiquo.domain.network.Network#toExternalNetwork}, - * {@link org.jclouds.abiquo.domain.network.Network#toPublicNetwork} and - * {@link org.jclouds.abiquo.domain.network.Network#toUnmanagedNetwork} can - * be used to convert the Network into the appropriate domain object. - * - * @param id - * Unique ID of the network in this datacenter. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/PublicNetworkResource#PublicNetworkResource-Getthelistofpublicnetworks" - * > http://community.abiquo.com/display/ABI20/StorageDeviceResource# - * PublicNetworkResource# - * PublicNetworkResource-Getthelistofpublicnetworks</a> - * @return Network with the given id or <code>null</code> if it does not - * exist. - */ - public Network<?> getNetwork(final Integer id) { - VLANNetworkDto network = context.getApi().getInfrastructureApi().getNetwork(target, id); - return Network.wrapNetwork(context, network); - } - - // Actions - - /** - * Retrieve the hypervisor type from remote machine. - * - * @param ip - * IP address of the physical machine. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrievethehypervisortypefromremotemachine" - * http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrievethehypervisortypefromremotemachine</a> - * @return Hypervisor type of the remote machine. - * @throws Exception - * If the hypervisor type information cannot be retrieved. - */ - public HypervisorType getHypervisorType(final String ip) { - DatacenterOptions options = DatacenterOptions.builder().ip(ip).build(); - - String type = context.getApi().getInfrastructureApi().getHypervisorTypeFromMachine(target, options); - - return HypervisorType.valueOf(type); - } - - /** - * Retrieve the list of available hypervisor types in the datacenter. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveavailablehypervisortypes" - * http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrieveavailablehypervisortypes</a> - * @return List of available hypervisor types in the datacenter. - */ - public Iterable<HypervisorType> listAvailableHypervisors() { - HypervisorTypesDto types = context.getApi().getInfrastructureApi().getHypervisorTypes(target); - return getHypervisorTypes(types); - } - - private Iterable<HypervisorType> getHypervisorTypes(final HypervisorTypesDto dtos) { - return transform(dtos.getCollection(), new Function<HypervisorTypeDto, HypervisorType>() { - @Override - public HypervisorType apply(HypervisorTypeDto input) { - return HypervisorType.fromId(input.getId()); - } - }); - } - - /** - * Searches a remote machine and retrieves an Machine object with its - * information. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @return A physical machine if found or <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveremotemachineinformation" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrieveremotemachineinformation</a> - */ - public Machine discoverSingleMachine(final String ip, final HypervisorType hypervisorType, final String user, - final String password) { - return discoverSingleMachine(ip, hypervisorType, user, password, hypervisorType.defaultPort); - } - - /** - * Searches a remote machine and retrieves an Machine object with its - * information. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @param port - * Port to connect. - * @return A physical machine if found or <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveremotemachineinformation" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrieveremotemachineinformation</a> - */ - public Machine discoverSingleMachine(final String ip, final HypervisorType hypervisorType, final String user, - final String password, final int port) { - MachineDto dto = context - .getApi() - .getInfrastructureApi() - .discoverSingleMachine(target, ip, hypervisorType, user, password, - MachineOptions.builder().port(port).build()); - - // Credentials are not returned by the API - dto.setUser(user); - dto.setPassword(password); - - return wrap(context, Machine.class, dto); - } - - /** - * Searches multiple remote machines and retrieves an Machine list with its - * information. - * - * @param ipFrom - * IP address of the remote first hypervisor to check. - * @param ipTo - * IP address of the remote last hypervisor to check. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @return The physical machine list. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrievealistofremotemachineinformation" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrievealistofremotemachineinformation</a> - */ - public Iterable<Machine> discoverMultipleMachines(final String ipFrom, final String ipTo, - final HypervisorType hypervisorType, final String user, final String password) { - return discoverMultipleMachines(ipFrom, ipTo, hypervisorType, user, password, hypervisorType.defaultPort); - } - - /** - * Searches multiple remote machines and retrieves an Machine list with its - * information. - * - * @param ipFrom - * IP address of the remote first hypervisor to check. - * @param ipTo - * IP address of the remote last hypervisor to check. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @param port - * Port to connect. - * @return The physical machine list. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrievealistofremotemachineinformation" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrievealistofremotemachineinformation</a> - */ - public Iterable<Machine> discoverMultipleMachines(final String ipFrom, final String ipTo, - final HypervisorType hypervisorType, final String user, final String password, final int port) { - MachinesDto dto = context - .getApi() - .getInfrastructureApi() - .discoverMultipleMachines(target, ipFrom, ipTo, hypervisorType, user, password, - MachineOptions.builder().port(port).build()); - - // Credentials are not returned by the API - for (MachineDto machine : dto.getCollection()) { - machine.setUser(user); - machine.setPassword(password); - } - - return wrap(context, Machine.class, dto.getCollection()); - } - - /** - * Check the state of a remote machine. This feature is used to check the - * state from a remote machine giving its location, user, password and - * hypervisor type. This machine does not need to be managed by Abiquo. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @return The physical machine state if the machine is found or - * <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Checkthestatefromremotemachine" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Checkthestatefromremotemachine</a> - */ - public MachineState checkMachineState(final String ip, final HypervisorType hypervisorType, final String user, - final String password) { - return checkMachineState(ip, hypervisorType, user, password, - MachineOptions.builder().port(hypervisorType.defaultPort).build()); - } - - /** - * Check the state of a remote machine. This feature is used to check the - * state from a remote machine giving its location, user, password and - * hypervisor type. This machine does not need to be managed by Abiquo. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param hypervisorType - * Kind of hypervisor we want to connect. Valid values are {vbox, - * kvm, xen-3, vmx-04, hyperv-301, xenserver}. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @param options - * . - * @return The physical machine state if the machine is found or - * <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Checkthestatefromremotemachine" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Checkthestatefromremotemachine</a> - */ - public MachineState checkMachineState(final String ip, final HypervisorType hypervisorType, final String user, - final String password, final MachineOptions options) { - MachineStateDto dto = context.getApi().getInfrastructureApi() - .checkMachineState(target, ip, hypervisorType, user, password, options); - - return dto.getState(); - } - - /** - * Check the ipmi configuration state of a remote machine. This feature is - * used to check the ipmi configuration state from a remote machine giving - * its location, user and password. This machine does not need to be managed - * by Abiquo. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @return The physical machine state if the machine is found or - * <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Checktheipmistatefromremotemachine" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Checktheipmistatefromremotemachine</a> - */ - public MachineIpmiState checkMachineIpmiState(final String ip, final String user, final String password) { - MachineIpmiStateDto dto = context.getApi().getInfrastructureApi() - .checkMachineIpmiState(target, ip, user, password); - return dto.getState(); - } - - /** - * Check the ipmi configuration state of a remote machine. This feature is - * used to check the ipmi configuration state from a remote machine giving - * its location, user and password. This machine does not need to be managed - * by Abiquo. - * - * @param ip - * IP address of the remote hypervisor to connect. - * @param user - * User to log in. - * @param password - * Password to authenticate. - * @return The physical machine state if the machine is found or - * <code>null</code>. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Checktheipmistatefromremotemachine" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Checktheipmistatefromremotemachine</a> - */ - public MachineIpmiState checkMachineIpmiState(final String ip, final String user, final String password, - final IpmiOptions options) { - MachineIpmiStateDto dto = context.getApi().getInfrastructureApi() - .checkMachineIpmiState(target, ip, user, password, options); - return dto.getState(); - } - - /** - * Retrieve the list of virtual machine templates in the repository of this - * datacenter. - * - * @param enterprise - * Owner of the templates. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource#VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates" - * > http://community.abiquo.com/display/ABI20/ - * VirtualMachineTemplateResource# - * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates</a> - * @return List of virtual machine templates in the repository of this - * datacenter. - */ - public Iterable<VirtualMachineTemplate> listTemplatesInRepository(final Enterprise enterprise) { - PagedIterable<VirtualMachineTemplateDto> templates = context.getApi().getVirtualMachineTemplateApi() - .listVirtualMachineTemplates(enterprise.getId(), target.getId()); - return wrap(context, VirtualMachineTemplate.class, templates.concat()); - } - - /** - * Retrieve a single virtual machine template in of this datacenter from the - * given enterprise. - * - * @param enterprise - * Owner of the templates. - * @param id - * Unique ID of the template in the datacenter repository for the - * given enterprise. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/VirtualMachineTemplateResource#VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates" - * > http://community.abiquo.com/display/ABI20/ - * VirtualMachineTemplateResource# - * VirtualMachineTemplateResource-Retrieveallvirtualmachinetemplates</a> - * @return Virtual machine template with the given id in the given enterprise - * or <code>null</code> if it does not exist. - */ - public VirtualMachineTemplate getTemplateInRepository(final Enterprise enterprise, final Integer id) { - VirtualMachineTemplateDto template = context.getApi().getVirtualMachineTemplateApi() - .getVirtualMachineTemplate(enterprise.getId(), target.getId(), id); - return wrap(context, VirtualMachineTemplate.class, template); - } - - // Builder - - public static Builder builder(final ApiContext<AbiquoApi> context) { - return new Builder(context); - } - - public static class Builder { - private ApiContext<AbiquoApi> context; - - private String name; - - private String location; - - private String ip; - - public Builder(final ApiContext<AbiquoApi> context) { - super(); - this.context = context; - } - - public Builder remoteServices(final String ip) { - this.ip = ip; - return this; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder location(final String location) { - this.location = location; - return this; - } - - public Datacenter build() { - DatacenterDto dto = new DatacenterDto(); - dto.setName(name); - dto.setLocation(location); - Datacenter datacenter = new Datacenter(context, dto); - datacenter.ip = ip; - return datacenter; - } - - public static Builder fromDatacenter(final Datacenter in) { - return Datacenter.builder(in.context).name(in.getName()).location(in.getLocation()); - } - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public String getLocation() { - return target.getLocation(); - } - - public String getName() { - return target.getName(); - } - - public void setLocation(final String location) { - target.setLocation(location); - } - - public void setName(final String name) { - target.setName(name); - } - - public String getUUID() { - return target.getUuid(); - } - - @Override - public String toString() { - return "Datacenter [id=" + getId() + ", location=" + getLocation() + ", name=" + getName() + ", uuid=" - + getUUID() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java deleted file mode 100644 index b2c93a3..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Datastore.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.infrastructure; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.rest.ApiContext; - -import com.abiquo.server.core.infrastructure.DatastoreDto; - -/** - * Adds high level functionality to {@link DatastoreDto}. - */ -public class Datastore extends DomainWrapper<DatastoreDto> { - /** - * Constructor to be used only by the builder. This resource cannot be - * created. - */ - private Datastore(final ApiContext<AbiquoApi> context, final DatastoreDto target) { - super(context, target); - } - - // Delegate methods - - public String getDatastoreUUID() { - return target.getDatastoreUUID(); - } - - public String getDirectory() { - return target.getDirectory(); - } - - public Integer getId() { - return target.getId(); - } - - public String getName() { - return target.getName(); - } - - public String getRootPath() { - return target.getRootPath(); - } - - public long getSize() { - return target.getSize(); - } - - public long getUsedSize() { - return target.getUsedSize(); - } - - public boolean isEnabled() { - return target.isEnabled(); - } - - public void setEnabled(final boolean enabled) { - target.setEnabled(enabled); - } - - @Override - public String toString() { - return "Datastore [id=" + getId() + ", uuid=" + getDatastoreUUID() + ", directory=" + getDirectory() + ", name=" - + getName() + ", rootPath=" + getRootPath() + ", size=" + getSize() + ", usedSize=" + getUsedSize() - + ", enabled=" + isEnabled() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java deleted file mode 100644 index 05e4a0a..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/Machine.java +++ /dev/null @@ -1,626 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.infrastructure; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.ImmutableList.copyOf; - -import java.util.List; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.infrastructure.options.MachineOptions; -import org.jclouds.abiquo.reference.ValidationErrors; -import org.jclouds.abiquo.reference.rest.ParentLinkName; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.enumerator.MachineIpmiState; -import com.abiquo.model.enumerator.MachineState; -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; -import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; -import com.abiquo.server.core.enterprise.EnterpriseDto; -import com.abiquo.server.core.infrastructure.DatastoresDto; -import com.abiquo.server.core.infrastructure.MachineDto; -import com.abiquo.server.core.infrastructure.MachineIpmiStateDto; -import com.abiquo.server.core.infrastructure.MachineStateDto; -import com.abiquo.server.core.infrastructure.RackDto; -import com.abiquo.server.core.infrastructure.network.NetworkInterfacesDto; -import com.google.inject.TypeLiteral; - -/** - * Adds high level functionality to {@link MachineDto}. This resource allows you - * to manage physical machines in the cloud infrastructure. - * - * @see API: <a - * href="http://community.abiquo.com/display/ABI20/MachineResource"> - * http://community.abiquo.com/display/ABI20/MachineResource</a> - */ -public class Machine extends DomainWrapper<MachineDto> { - /** The default virtual ram used in MB. */ - protected static final int DEFAULT_VRAM_USED = 1; - - /** The default virtual cpu used in MB. */ - protected static final int DEFAULT_VCPU_USED = 1; - - /** The rack where the machine belongs. */ - protected Rack rack; - - /** - * Constructor to be used only by the builder. - */ - protected Machine(final ApiContext<AbiquoApi> context, final MachineDto target) { - super(context, target); - } - - /** - * Create a new physical machine in Abiquo. The best way to create a machine - * if first calling {@link Datacenter#discoverSingleMachine} or - * {@link Datacenter#discoverMultipleMachines}. This will return a new - * {@link Machine}. The following steps are: enabling a datastore, selecting - * a virtual switch and choosing a rack. Refer link for more information. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/DatacenterResource#DatacenterResource-Retrieveremotemachineinformation" - * > http://community.abiquo.com/display/ABI20/DatacenterResource# - * DatacenterResource- Retrieveremotemachineinformation</a> - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/MachineResource#MachineResource-Createamachine" - * > http://community.abiquo.com/display/ABI20/MachineResource# - * MachineResource- Createamachine</a> - */ - public void save() { - target = context.getApi().getInfrastructureApi().createMachine(rack.unwrap(), target); - } - - public void delete() { - context.getApi().getInfrastructureApi().deleteMachine(target); - target = null; - } - - public void update() { - target = context.getApi().getInfrastructureApi().updateMachine(target); - } - - public MachineState check() { - MachineStateDto dto = context.getApi().getInfrastructureApi().checkMachineState(target, true); - MachineState state = dto.getState(); - target.setState(state); - return state; - } - - public MachineIpmiState checkIpmi() { - MachineIpmiStateDto dto = context.getApi().getInfrastructureApi().checkMachineIpmiState(target); - return dto.getState(); - } - - // Parent access - /** - * Retrieve the unmanaged rack where the machine is. - * - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/RackResource#RackResource-RetrieveaRack" - * > - * http://community.abiquo.com/display/ABI20/RackResource#RackResource- - * RetrieveaRack</a> - */ - public Rack getRack() { - RESTLink link = checkNotNull(target.searchLink(ParentLinkName.RACK), ValidationErrors.MISSING_REQUIRED_LINK + " " - + ParentLinkName.RACK); - - HttpResponse response = context.getApi().get(link); - - ParseXMLWithJAXB<RackDto> parser = new ParseXMLWithJAXB<RackDto>(context.utils().xml(), - TypeLiteral.get(RackDto.class)); - - return wrap(context, Rack.class, parser.apply(response)); - } - - // Children access - - public Iterable<Datastore> getDatastores() { - return wrap(context, Datastore.class, target.getDatastores().getCollection()); - } - - public Iterable<NetworkInterface> getNetworkInterfaces() { - return wrap(context, NetworkInterface.class, target.getNetworkInterfaces().getCollection()); - } - - /** - * Gets the list of virtual machines in the physical machine. - * - * @return The list of virtual machines in the physical machine. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource-Retrievethelistofvirtualmachinesbymachine'shypervisor" - * > http://community.abiquo.com/display/ABI20/Machine+Resource# - * MachineResource- - * Retrievethelistofvirtualmachinesbymachine'shypervisor</a> - */ - public Iterable<VirtualMachine> listVirtualMachines() { - MachineOptions options = MachineOptions.builder().sync(false).build(); - VirtualMachinesWithNodeExtendedDto vms = context.getApi().getInfrastructureApi() - .listVirtualMachinesByMachine(target, options); - return wrap(context, VirtualMachine.class, vms.getCollection()); - } - - public VirtualMachine getVirtualMachine(final Integer virtualMachineId) { - VirtualMachineWithNodeExtendedDto vm = context.getApi().getInfrastructureApi() - .getVirtualMachine(target, virtualMachineId); - return wrap(context, VirtualMachine.class, vm); - } - - /** - * Gets the list of virtual machines in the physical machine synchronizing - * virtual machines from remote hypervisor with abiquo's database. - * - * @return The list of virtual machines in the physical machine. - * @see API: <a href= - * "http://community.abiquo.com/display/ABI20/Machine+Resource#MachineResource-Retrievethelistofvirtualmachinesbymachine'shypervisor" - * > http://community.abiquo.com/display/ABI20/Machine+Resource# - * MachineResource- - * Retrievethelistofvirtualmachinesbymachine'shypervisor</a> - */ - public Iterable<VirtualMachine> listRemoteVirtualMachines() { - MachineOptions options = MachineOptions.builder().sync(true).build(); - VirtualMachinesWithNodeExtendedDto vms = context.getApi().getInfrastructureApi() - .listVirtualMachinesByMachine(target, options); - return wrap(context, VirtualMachine.class, vms.getCollection()); - } - - /** - * Reserve the machine for the given enterprise. - * <p> - * When a {@link Machine} is reserved for an {@link Enterprise}, only the - * users of that enterprise will be able to deploy {@link VirtualMachine}s in - * it. - * - * @param enterprise - * The enterprise reserving the machine. - */ - public void reserveFor(final Enterprise enterprise) { - target = context.getApi().getInfrastructureApi().reserveMachine(enterprise.unwrap(), target); - } - - /** - * Cancels the machine reservation for the given enterprise. - * - * @param enterprise - * The enterprise to cancel reservation for. - */ - public void cancelReservationFor(final Enterprise enterprise) { - context.getApi().getInfrastructureApi().cancelReservation(enterprise.unwrap(), target); - target.getLinks().remove(target.searchLink(ParentLinkName.ENTERPRISE)); - } - - /** - * Check if the machine is reserved. - * - * @return Boolean indicating if the machine is reserved for an enterprise. - */ - public boolean isReserved() { - return target.searchLink(ParentLinkName.ENTERPRISE) != null; - } - - /** - * Get the enterprise that has reserved the machine or <code>null</code> if - * the machine is not reserved. - * - * @return The enterprise that has reserved the machine or <code>null</code> - * if the machine is not reserved. - */ - public Enterprise getOwnerEnterprise() { - if (!isReserved()) { - return null; - } - - EnterpriseDto enterprise = context.getApi().getEnterpriseApi() - .getEnterprise(target.getIdFromLink(ParentLinkName.ENTERPRISE)); - - return wrap(context, Enterprise.class, enterprise); - } - - // Builder - - public static Builder builder(final ApiContext<AbiquoApi> context, final Rack rack) { - return new Builder(context, rack); - } - - public static class Builder { - private ApiContext<AbiquoApi> context; - - private String name; - - private String description; - - private Integer virtualRamInMb; - - private Integer virtualRamUsedInMb = DEFAULT_VRAM_USED; - - private Integer virtualCpuCores; - - private Integer virtualCpusUsed = DEFAULT_VCPU_USED; - - private Integer port; - - private String ip; - - private MachineState state = MachineState.STOPPED; - - private String ipService; - - private HypervisorType type; - - private String user; - - private String password; - - private Iterable<Datastore> datastores; - - private Iterable<NetworkInterface> networkInterfaces; - - private String ipmiIp; - - private Integer ipmiPort; - - private String ipmiUser; - - private String ipmiPassword; - - private Rack rack; - - public Builder(final ApiContext<AbiquoApi> context, final Rack rack) { - super(); - checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Rack.class); - this.rack = rack; - this.context = context; - } - - public Builder state(final MachineState state) { - this.state = state; - return this; - } - - public Builder ipmiPassword(final String ipmiPassword) { - this.ipmiPassword = ipmiPassword; - return this; - } - - public Builder ipmiUser(final String ipmiUser) { - this.ipmiUser = ipmiUser; - return this; - } - - public Builder ipmiPort(final int ipmiPort) { - this.ipmiPort = ipmiPort; - return this; - } - - public Builder ipmiIp(final String ipmiIp) { - this.ipmiIp = ipmiIp; - return this; - } - - public Builder user(final String user) { - this.user = user; - return this; - } - - public Builder ip(final String ip) { - this.ip = ip; - if (ipService == null) { - ipService = ip; - } - return this; - } - - public Builder ipService(final String ipService) { - this.ipService = ipService; - return this; - } - - public Builder password(final String password) { - this.password = password; - return this; - } - - public Builder name(final String name) { - this.name = name; - return this; - } - - public Builder description(final String description) { - this.description = description; - return this; - } - - public Builder port(final int port) { - this.port = port; - return this; - } - - public Builder datastores(final Iterable<Datastore> datastores) { - this.datastores = datastores; - return this; - } - - public Builder networkInterfaces(final Iterable<NetworkInterface> networkInterfaces) { - this.networkInterfaces = networkInterfaces; - return this; - } - - public Builder virtualRamInMb(final int virtualRamInMb) { - this.virtualRamInMb = virtualRamInMb; - return this; - } - - public Builder virtualRamUsedInMb(final int virtualRamUsedInMb) { - this.virtualRamUsedInMb = virtualRamUsedInMb; - return this; - } - - public Builder virtualCpuCores(final int virtualCpuCores) { - this.virtualCpuCores = virtualCpuCores; - return this; - } - - public Builder virtualCpusUsed(final int virtualCpusUsed) { - this.virtualCpusUsed = virtualCpusUsed; - return this; - } - - public Builder hypervisorType(final HypervisorType hypervisorType) { - this.type = hypervisorType; - - // Sets default hypervisor port - if (this.port == null) { - this.port = hypervisorType.defaultPort; - } - - return this; - } - - public Builder rack(final Rack rack) { - checkNotNull(rack, ValidationErrors.NULL_RESOURCE + Datacenter.class); - this.rack = rack; - return this; - } - - public Machine build() { - MachineDto dto = new MachineDto(); - dto.setName(name); - dto.setDescription(description); - dto.setVirtualRamInMb(virtualRamInMb); - dto.setVirtualRamUsedInMb(virtualRamUsedInMb); - dto.setVirtualCpuCores(virtualCpuCores); - dto.setVirtualCpusUsed(virtualCpusUsed); - if (port != null) { - dto.setPort(port); - } - dto.setIp(ip); - dto.setIpService(ipService); - dto.setType(type); - dto.setUser(user); - dto.setPassword(password); - dto.setIpmiIP(ipmiIp); - dto.setIpmiPassword(ipmiPassword); - if (ipmiPort != null) { - dto.setIpmiPort(ipmiPort); - } - dto.setIpmiUser(ipmiUser); - dto.setState(state); - - DatastoresDto datastoresDto = new DatastoresDto(); - datastoresDto.getCollection().addAll(copyOf(unwrap(datastores))); - dto.setDatastores(datastoresDto); - - NetworkInterfacesDto networkInterfacesDto = new NetworkInterfacesDto(); - networkInterfacesDto.getCollection().addAll(copyOf(unwrap(networkInterfaces))); - dto.setNetworkInterfaces(networkInterfacesDto); - - Machine machine = new Machine(context, dto); - machine.rack = rack; - - return machine; - } - - public static Builder fromMachine(final Machine in) { - Builder builder = Machine.builder(in.context, in.rack).name(in.getName()).description(in.getDescription()) - .virtualCpuCores(in.getVirtualCpuCores()).virtualCpusUsed(in.getVirtualCpusUsed()) - .virtualRamInMb(in.getVirtualRamInMb()).virtualRamUsedInMb(in.getVirtualRamUsedInMb()) - .port(in.getPort()).ip(in.getIp()).ipService(in.getIpService()).hypervisorType(in.getType()) - .user(in.getUser()).password(in.getPassword()).ipmiIp(in.getIpmiIp()).ipmiPassword(in.getIpmiPassword()) - .ipmiUser(in.getIpmiUser()).state(in.getState()).datastores(in.getDatastores()) - .networkInterfaces(in.getNetworkInterfaces()); - - // Parameters that can be null - if (in.getIpmiPort() != null) { - builder.ipmiPort(in.getIpmiPort()); - } - - return builder; - } - } - - // Delegate methods - - public Integer getId() { - return target.getId(); - } - - public String getIp() { - return target.getIp(); - } - - public String getIpmiIp() { - return target.getIpmiIP(); - } - - public String getIpmiPassword() { - return target.getIpmiPassword(); - } - - public Integer getIpmiPort() { - return target.getIpmiPort(); - } - - public String getIpmiUser() { - return target.getIpmiUser(); - } - - public String getIpService() { - return target.getIpService(); - } - - public String getName() { - return target.getName(); - } - - public String getPassword() { - return target.getPassword(); - } - - public Integer getPort() { - return target.getPort(); - } - - public MachineState getState() { - return target.getState(); - } - - public HypervisorType getType() { - return target.getType(); - } - - public String getUser() { - return target.getUser(); - } - - public Integer getVirtualCpuCores() { - return target.getVirtualCpuCores(); - } - - public Integer getVirtualCpusUsed() { - return target.getVirtualCpusUsed(); - } - - public Integer getVirtualRamInMb() { - return target.getVirtualRamInMb(); - } - - public Integer getVirtualRamUsedInMb() { - return target.getVirtualRamUsedInMb(); - } - - public void setDatastores(final List<Datastore> datastores) { - DatastoresDto datastoresDto = new DatastoresDto(); - datastoresDto.getCollection().addAll(copyOf(unwrap(datastores))); - target.setDatastores(datastoresDto); - } - - public void setDescription(final String description) { - target.setDescription(description); - } - - public void setIp(final String ip) { - target.setIp(ip); - } - - public void setIpmiIp(final String ipmiIp) { - target.setIpmiIP(ipmiIp); - } - - public void setIpmiPassword(final String ipmiPassword) { - target.setIpmiPassword(ipmiPassword); - } - - public void setIpmiPort(final Integer ipmiPort) { - target.setIpmiPort(ipmiPort); - } - - public void setIpmiUser(final String ipmiUser) { - target.setIpmiUser(ipmiUser); - } - - public void setIpService(final String ipService) { - target.setIpService(ipService); - } - - public void setName(final String name) { - target.setName(name); - } - - public void setPassword(final String password) { - target.setPassword(password); - } - - public void setPort(final Integer port) { - target.setPort(port); - } - - public void setState(final MachineState state) { - target.setState(state); - } - - public void setType(final HypervisorType type) { - target.setType(type); - } - - public void setUser(final String user) { - target.setUser(user); - } - - public void setVirtualCpuCores(final Integer virtualCpuCores) { - target.setVirtualCpuCores(virtualCpuCores); - } - - public void setVirtualCpusUsed(final Integer virtualCpusUsed) { - target.setVirtualCpusUsed(virtualCpusUsed); - } - - public void setVirtualRamInMb(final Integer virtualRamInMb) { - target.setVirtualRamInMb(virtualRamInMb); - } - - public void setVirtualRamUsedInMb(final Integer virtualRamUsedInMb) { - target.setVirtualRamUsedInMb(virtualRamUsedInMb); - } - - public String getDescription() { - return target.getDescription(); - } - - public void setRack(final Rack rack) { - this.rack = rack; - } - - @Override - public String toString() { - return "Machine [id=" + getId() + ", ip=" + getIp() + ", ipmiIp=" + getIpmiIp() + ", ipmiPassword=" - + getIpmiPassword() + ", ipmiPort=" + getIpmiPort() + ", ipmiUser=" + getIpmiUser() + ", ipService=" - + getIpService() + ", name=" + getName() + ", password=" + getPassword() + ", port=" + getPort() - + ", state=" + getState() + ", type=" + getType() + ", user=" + getUser() + ", virtualCpuCores=" - + getVirtualCpuCores() + ", virtualCpusUsed=" + getVirtualCpusUsed() + ", getVirtualRamInMb()=" - + getVirtualRamInMb() + ", virtualRamUsedInMb=" + getVirtualRamUsedInMb() + ", description=" - + getDescription() + "]"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/NetworkInterface.java ---------------------------------------------------------------------- diff --git a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/NetworkInterface.java b/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/NetworkInterface.java deleted file mode 100644 index aec201b..0000000 --- a/abiquo/src/main/java/org/jclouds/abiquo/domain/infrastructure/NetworkInterface.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ -package org.jclouds.abiquo.domain.infrastructure; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.DomainWrapper; -import org.jclouds.abiquo.domain.network.NetworkServiceType; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.rest.ApiContext; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.infrastructure.network.NetworkInterfaceDto; -import com.abiquo.server.core.infrastructure.network.NetworkServiceTypeDto; -import com.google.inject.TypeLiteral; - -/** - * Represents a physical attached NIC. - * - * Allows to specify the {@link NetworkServiceType} for the network interface. - * This way all network interfaces have the information of the kind of network - * they are attached to. - */ -public class NetworkInterface extends DomainWrapper<NetworkInterfaceDto> { - /** - * Constructor to be used only by the builder. This resource cannot be - * created. - */ - protected NetworkInterface(final ApiContext<AbiquoApi> context, final NetworkInterfaceDto target) { - super(context, target); - } - - public String getName() { - return target.getName(); - } - - public String getMac() { - return target.getMac(); - } - - public void setNetworkServiceType(final NetworkServiceType type) { - checkNotNull(type, "network service type cannot be null"); - target.setNetworkServiceTypeLink(type.unwrap().getEditLink().getHref()); - } - - public NetworkServiceType getNetworkServiceType() { - RESTLink link = target.getNetworkServiceTypeLink(); - - HttpResponse response = context.getApi().get(link); - - ParseXMLWithJAXB<NetworkServiceTypeDto> parser = new ParseXMLWithJAXB<NetworkServiceTypeDto>(context.utils() - .xml(), TypeLiteral.get(NetworkServiceTypeDto.class)); - - return wrap(context, NetworkServiceType.class, parser.apply(response)); - } -}
