Search in sources :

Example 56 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method stopIfRunning.

@Override
public boolean stopIfRunning(final String id, final Timeout timeout) throws InterruptedException {
    VirtualMachine vm = getById(id);
    switch(vm.powerState()) {
        case DEALLOCATING:
        case STARTING:
        case DEALLOCATED:
            return false;
        case RUNNING:
            log.info(vm.resourceGroupName() + " - " + vm.name() + " is running, stopping");
            stop(id, timeout);
            return true;
        default:
            throw new IllegalArgumentException("Unknown power state");
    }
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 57 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method stop.

@Override
public void stop(final String id, final Timeout timeout) throws InterruptedException {
    final VirtualMachine vm = getById(id);
    stop(vm, timeout);
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 58 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method startAsync.

@Override
public Future<Void> startAsync(final String id) {
    final VirtualMachine vm = getById(id);
    final String threadName = "Azure Async Call" + vm.resourceGroupName() + " - " + vm.name();
    ThreadRenameCallableWrap<Void> call = new ThreadRenameCallableWrap<Void>(threadName, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            start(vm, Timeout.THIRTY_MINUTES);
            return null;
        }
    });
    return asynchronous.submit(call);
}
Also used : ThreadRenameCallableWrap(com.peterphi.std.threading.ThreadRenameCallableWrap) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudException(com.microsoft.azure.CloudException) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 59 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method requestStartIfStopped.

@Override
public boolean requestStartIfStopped(final String id) {
    VirtualMachine vm = getById(id);
    switch(vm.powerState()) {
        case RUNNING:
        case DEALLOCATING:
        case STARTING:
            return false;
        case DEALLOCATED:
            log.info(vm.resourceGroupName() + " - " + vm.name() + " is deallocated, starting");
            startAsync(id);
            return true;
        default:
            throw new IllegalArgumentException("Unknown power state");
    }
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Example 60 with VirtualMachine

use of com.microsoft.azure.management.compute.VirtualMachine in project stdlib by petergeneric.

the class AzureVMControlImpl method requestStopIfRunning.

@Override
public boolean requestStopIfRunning(final String id) {
    VirtualMachine vm = getById(id);
    switch(vm.powerState()) {
        case DEALLOCATING:
        case STARTING:
        case DEALLOCATED:
            return false;
        case RUNNING:
            log.info(vm.resourceGroupName() + " - " + vm.name() + " is running, stopping");
            stopAsync(id);
            return true;
        default:
            throw new IllegalArgumentException("Unknown power state");
    }
}
Also used : VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine)

Aggregations

VirtualMachine (com.microsoft.azure.management.compute.VirtualMachine)68 ArrayList (java.util.ArrayList)21 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)20 Network (com.microsoft.azure.management.network.Network)17 Date (java.util.Date)12 Disk (com.microsoft.azure.management.compute.Disk)10 PublicIPAddress (com.microsoft.azure.management.network.PublicIPAddress)10 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)9 Creatable (com.microsoft.azure.management.resources.fluentcore.model.Creatable)9 Azure (com.microsoft.azure.management.Azure)8 NetworkInterface (com.microsoft.azure.management.network.NetworkInterface)8 IOException (java.io.IOException)8 StopWatch (org.apache.commons.lang3.time.StopWatch)7 VirtualMachineDataDisk (com.microsoft.azure.management.compute.VirtualMachineDataDisk)6 HashMap (java.util.HashMap)6 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)5 JSchException (com.jcraft.jsch.JSchException)4 CloudException (com.microsoft.azure.CloudException)4 DockerHost (com.microsoft.azure.docker.model.DockerHost)4 NetworkSecurityGroup (com.microsoft.azure.management.network.NetworkSecurityGroup)4