org.dasein.cloud.cloudstack.compute.VMCapabilities Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dasein-cloud-cloudstack Show documentation
Show all versions of dasein-cloud-cloudstack Show documentation
Implements the Dasein Cloud API for Cloud.com Cloudstack-based public and private clouds.
/**
* Copyright (C) 2009-2015 Dell, Inc.
*
* ====================================================================
* 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.
* ====================================================================
*/
package org.dasein.cloud.cloudstack.compute;
import org.dasein.cloud.AbstractCapabilities;
import org.dasein.cloud.Capabilities;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.Requirement;
import org.dasein.cloud.VisibleScope;
import org.dasein.cloud.cloudstack.CSServiceProvider;
import org.dasein.cloud.cloudstack.CSVersion;
import org.dasein.cloud.compute.Architecture;
import org.dasein.cloud.compute.ImageClass;
import org.dasein.cloud.compute.Platform;
import org.dasein.cloud.compute.VMScalingCapabilities;
import org.dasein.cloud.compute.VirtualMachineCapabilities;
import org.dasein.cloud.compute.VmState;
import org.dasein.cloud.cloudstack.CSCloud;
import org.dasein.cloud.util.APITrace;
import org.dasein.cloud.util.NamingConstraints;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
/**
* Describes the capabilities of Cloudstack with respect to Dasein virtual machine operations.
* Created by Danielle Mayne: 3/03/14 12:51 PM
* @author Danielle Mayne
* @version 2014.03 initial version
* @since 2014.03
*/
public class VMCapabilities extends AbstractCapabilities implements VirtualMachineCapabilities {
public VMCapabilities(@Nonnull CSCloud cloud) { super(cloud); }
@Override
public boolean canAlter(@Nonnull VmState fromState) throws CloudException, InternalException {
if (!getProvider().getProviderName().contains("Datapipe")) {
return fromState.equals(VmState.STOPPED);
}
return false;
}
@Override
public boolean canClone(@Nonnull VmState fromState) throws CloudException, InternalException {
return false;
}
@Override
public boolean canPause(@Nonnull VmState fromState) throws CloudException, InternalException {
return false;
}
@Override
public boolean canReboot(@Nonnull VmState fromState) throws CloudException, InternalException {
return !VmState.ERROR.equals(fromState);
}
@Override
public boolean canResume(@Nonnull VmState fromState) throws CloudException, InternalException {
return false;
}
@Override
public boolean canStart(@Nonnull VmState fromState) throws CloudException, InternalException {
return !VmState.RUNNING.equals(fromState) && !VmState.ERROR.equals(fromState);
}
@Override
public boolean canStop(@Nonnull VmState fromState) throws CloudException, InternalException {
return !fromState.equals(VmState.STOPPED) && !VmState.ERROR.equals(fromState);
}
@Override
public boolean canSuspend(@Nonnull VmState fromState) throws CloudException, InternalException {
return false;
}
@Override
public boolean canTerminate(@Nonnull VmState fromState) throws CloudException, InternalException {
return !fromState.equals(VmState.TERMINATED) && !VmState.ERROR.equals(fromState);
}
@Override
public boolean canUnpause(@Nonnull VmState fromState) throws CloudException, InternalException {
return false;
}
@Override
public int getMaximumVirtualMachineCount() throws CloudException, InternalException {
return Capabilities.LIMIT_UNKNOWN;
}
@Override
public int getCostFactor(@Nonnull VmState state) throws CloudException, InternalException {
return 100;
}
@Nonnull
@Override
public String getProviderTermForVirtualMachine(@Nonnull Locale locale) throws CloudException, InternalException {
return "virtual machine";
}
@Nullable
@Override
public VMScalingCapabilities getVerticalScalingCapabilities() throws CloudException, InternalException {
return VMScalingCapabilities.getInstance(false, true, false);
}
@Nonnull
@Override
public NamingConstraints getVirtualMachineNamingConstraints() throws CloudException, InternalException {
return NamingConstraints.getAlphaNumeric(1, 64);
}
@Nullable
@Override
public VisibleScope getVirtualMachineVisibleScope() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Nullable
@Override
public VisibleScope getVirtualMachineProductVisibleScope() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Nonnull
@Override
public Requirement identifyDataCenterLaunchRequirement() throws CloudException, InternalException {
return Requirement.REQUIRED;
}
@Nonnull
@Override
public Requirement identifyImageRequirement(@Nonnull ImageClass cls) throws CloudException, InternalException {
return (cls.equals(ImageClass.MACHINE) ? Requirement.REQUIRED : Requirement.NONE);
}
@Nonnull
@Override
public Requirement identifyPasswordRequirement(Platform platform) throws CloudException, InternalException {
return Requirement.NONE;
}
@Nonnull
@Override
public Requirement identifyRootVolumeRequirement() throws CloudException, InternalException {
return Requirement.NONE;
}
@Nonnull
@Override
public Requirement identifyShellKeyRequirement(Platform platform) throws CloudException, InternalException {
if( Platform.WINDOWS.equals(platform) ) {
return Requirement.NONE;
}
return Requirement.OPTIONAL;
}
@Nonnull
@Override
public Requirement identifyStaticIPRequirement() throws CloudException, InternalException {
return Requirement.NONE;
}
@Nonnull
@Override
public Requirement identifySubnetRequirement() throws CloudException, InternalException {
return Requirement.NONE;
}
@Nonnull
@Override
public Requirement identifyVlanRequirement() throws CloudException, InternalException {
APITrace.begin(getProvider(), "VM.identifyVlanRequirement");
try {
if( getProvider().getServiceProvider().equals(CSServiceProvider.DATAPIPE) ) {
return Requirement.NONE;
}
if( getProvider().getVersion().greaterThan(CSVersion.CS21) ) {
ProviderContext ctx = getProvider().getContext();
if( ctx == null ) {
throw new CloudException("No context was set for this request");
}
String regionId = ctx.getRegionId();
if( regionId == null ) {
throw new CloudException("No region was set for this request");
}
return (getProvider().getDataCenterServices().requiresNetwork(regionId) ? Requirement.REQUIRED : Requirement.OPTIONAL);
}
return Requirement.OPTIONAL;
}
finally {
APITrace.end();
}
}
@Override
public boolean isAPITerminationPreventable() throws CloudException, InternalException {
return false;
}
@Override
public boolean isBasicAnalyticsSupported() throws CloudException, InternalException {
return false;
}
@Override
public boolean isExtendedAnalyticsSupported() throws CloudException, InternalException {
return false;
}
@Override
public boolean isUserDataSupported() throws CloudException, InternalException {
return true;
}
@Override
public boolean isUserDefinedPrivateIPSupported() throws CloudException, InternalException {
return false;
}
private transient Collection architectures;
@Nonnull
@Override
public Iterable listSupportedArchitectures() throws InternalException, CloudException {
if( architectures == null ) {
ArrayList a = new ArrayList();
a.add(Architecture.I32);
a.add(Architecture.I64);
architectures = Collections.unmodifiableList(a);
}
return architectures;
}
@Override
public boolean supportsSpotVirtualMachines() throws InternalException, CloudException {
return false;
}
@Override
public boolean supportsClientRequestToken() throws InternalException, CloudException {
return false;
}
@Override
public boolean isVMProductDCConstrained() throws InternalException, CloudException{
return false;
}
@Override
public boolean supportsCloudStoredShellKey() throws InternalException, CloudException{
return true;
}
@Override
public boolean supportsAlterVM() {
if (!getProvider().getProviderName().contains("Datapipe")) {
return true;
}
return false;
}
@Override
public boolean supportsClone() {
return false;
}
@Override
public boolean supportsPause() {
return false;
}
@Override
public boolean supportsReboot() {
return true;
}
@Override
public boolean supportsResume() {
return false;
}
@Override
public boolean supportsStart() {
return true;
}
@Override
public boolean supportsStop() {
return true;
}
@Override
public boolean supportsSuspend() {
return false;
}
@Override
public boolean supportsTerminate() {
return true;
}
@Override
public boolean supportsUnPause() {
return false;
}
}