use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeClient method listMachineTypes.
private Iterable<MachineType> listMachineTypes(String projectId) throws OpsException {
List<MachineType> ret = Lists.newArrayList();
MachineTypeList machineTypeList;
try {
log.debug("Listing machine types in project " + projectId);
machineTypeList = compute.machineTypes().list(projectId).execute();
} catch (IOException e) {
throw new OpsException("Error listing machine types", e);
}
if (machineTypeList.getItems() != null) {
ret.addAll(machineTypeList.getItems());
}
return ret;
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeClient method deleteFirewallRule.
public void deleteFirewallRule(Firewall rule) throws OpsException {
try {
log.debug("Deleting firewall rule: " + rule);
Operation operation = compute.firewalls().delete(projectId, rule.getName()).execute();
waitComplete(operation, 5, TimeUnit.MINUTES);
// TODO: Check success of operation?
} catch (IOException e) {
throw new OpsException("Error deleting firewall", e);
} catch (TimeoutException e) {
throw new OpsException("Timeout while waiting for firewall deletion", e);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class GoogleComputeMachine method terminate.
@Override
public void terminate() throws OpsException {
try {
Operation operation = computeClient.terminateInstance(instance.getName());
computeClient.waitComplete(operation, 5, TimeUnit.MINUTES);
} catch (TimeoutException e) {
throw new OpsException("Timeout waiting for instance termination", e);
}
refreshState();
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class CloudInstanceMapper method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
Tag tag = Tag.build(Tag.ASSIGNED, instance.getKey().getUrl());
List<DirectHost> hosts = Lists.newArrayList(platformLayer.listItems(DirectHost.class, TagFilter.byTag(tag)));
if (hosts.size() > 1) {
// Huh?
throw new OpsException("Multiple hosts already assigned");
}
DirectHost host;
if (hosts.isEmpty()) {
if (OpsContext.isDelete()) {
host = null;
} else {
if (createInstance) {
DirectCloudHost cloudHost = cloudMap.pickHost(instance);
host = cloudHost.getModel();
platformLayer.addTag(host.getKey(), tag);
} else {
throw new OpsException("Instance not yet assigned");
}
}
} else {
host = hosts.get(0);
}
RecursionState recursion = getRecursionState();
if (host != null) {
this.cloud = platformLayer.getItem(host.cloud, DirectCloud.class);
this.hostTarget = directHelpers.toTarget(host);
recursion.pushChildScope(cloud);
recursion.pushChildScope(host);
recursion.pushChildScope(hostTarget);
} else {
if (!OpsContext.isDelete()) {
throw new IllegalStateException();
}
log.info("No host set; won't recurse in");
recursion.setPreventRecursion(true);
}
}
use of org.platformlayer.ops.OpsException in project platformlayer by platformlayer.
the class NetworkTunDevice method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (OpsContext.isConfigure()) {
Command findCommand = Command.build("/sbin/ifconfig {0}", interfaceName);
boolean found = false;
try {
target.executeCommand(findCommand);
found = true;
} catch (ProcessExecutionException e) {
ProcessExecution execution = e.getExecution();
if (execution.getExitCode() == 1 && execution.getStdErr().contains("Device not found")) {
found = false;
} else {
throw new OpsException("Error checking for interface", e);
}
}
if (!found) {
// This is actually idempotent, but I think it's scary to rely on it being so
Command command = Command.build("/usr/sbin/tunctl -t {0}", interfaceName);
target.executeCommand(command);
}
{
// TODO: Safe to re-run?
Command command = Command.build("ifconfig {0} up", interfaceName);
target.executeCommand(command);
}
if (bridgeName != null) {
// TODO: Safe to re-run?
Command command = Command.build("brctl addif {0} {1}", bridgeName.get(), interfaceName);
try {
target.executeCommand(command);
} catch (ProcessExecutionException e) {
ProcessExecution execution = e.getExecution();
if (execution.getExitCode() == 1 && execution.getStdErr().contains("already a member of a bridge")) {
// OK
// TODO: Check that the bridge is bridgeName
} else {
throw new OpsException("Error attaching interface to bridge", e);
}
}
}
}
if (OpsContext.isDelete()) {
// TODO: Implement
log.warn("NetworkTunDevice delete not implemented");
}
}
Aggregations