use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class PackageRemoval method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
// Make sure openssh-server is manually installed (i.e. not through task-ssh-server)
target.executeCommand("apt-get install openssh-server");
// Only for wheezy? Squeeze has a depencency of install-info -> findutils
Command command = Command.build("apt-get remove --yes aptitude tasksel tasksel-data man-db manpages libxapian22 libboost-iostreams1.49.0 info ");
target.executeCommand(command);
// Maybe:
command = Command.build("apt-get remove --yes groff-base consolekit sane-utils exim4-config installation-report");
target.executeCommand(command);
// Replace netcat with netcat6
target.executeCommand("apt-get install netcat6");
target.executeCommand("apt-get remove netcat-traditional");
// We just want headless...
command = Command.build("apt-get remove --yes dbus openjdk-7-jdk openjdk-7-jre icedtea-7-jre-cacao icedtea-7-jre-jamvm");
target.executeCommand(command);
// Do we need python?? Does it still get installed??
// apt-get remove python
// Warnings??
// apt-get remove install-info
//
// Squeeze:
// apt-get remove aptitude tasksel tasksel-data man-db manpages libxapian22 info
target.executeCommand("apt-get autoremove");
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class ManagedSymlink method doConfigureValidate.
@Handler
public void doConfigureValidate(OpsTarget target) throws Exception {
File filePath = getFilePath();
FilesystemInfo fsInfo = target.getFilesystemInfoFile(filePath);
boolean exists = (fsInfo != null);
File symlinkTarget = getSymlinkTarget();
boolean symlinkTargetMatch = false;
if (fsInfo != null) {
symlinkTargetMatch = Objects.equal(fsInfo.symlinkTarget, symlinkTarget.toString());
}
if (OpsContext.isConfigure()) {
if (!exists) {
target.symlink(symlinkTarget, filePath, false);
createdNewFile = true;
doUpdateAction(target);
} else {
if (!symlinkTargetMatch) {
target.symlink(symlinkTarget, filePath, true);
}
}
configureOwnerAndMode(target, fsInfo);
// FilesystemInfo targetInfo = agent.getFilesystemInfoFile(getSymlinkTarget());
// configureOwnerAndMode(agent, targetInfo, getSymlinkTarget());
}
if (OpsContext.isValidate()) {
if (!exists) {
OpsContext.get().addWarning(this, "DoesNotExist", "Symlink not found: " + filePath);
} else if (!symlinkTargetMatch) {
OpsContext.get().addWarning(this, "TargetMismatch", "Symlink points at wrong target: " + fsInfo);
validateOwner(fsInfo);
// Mode is meaningless on symlinks
// validateMode(fsInfo);
}
}
if (OpsContext.isDelete()) {
if (exists) {
target.rm(filePath);
doUpdateAction(target);
}
}
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class DiskImageController method build.
@Handler
public void build(DiskImage image) throws OpsException, IOException {
String imageId = Tag.IMAGE_ID.findUnique(image.getTags());
if (imageId == null) {
// Check for existing image
MachineProvider targetCloud = cloudHelpers.getCloud(image.cloud);
DiskImageRecipe recipe = platformLayer.getItem(image.recipeId, DiskImageRecipe.class);
ImageStore imageStore = cloud.getImageStore(targetCloud);
List<CloudImage> existingImages = imageStore.findImages(Collections.<Tag>emptyList());
for (CloudImage existingImage : existingImages) {
// TODO: Fetch the parent, fetch the description, see if it's a match??
log.info("Image found, but not know whether we can re-use: " + existingImage);
}
}
if (imageId == null) {
buildImage(image);
}
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class CloudInstanceMapper method doOperation.
@Handler
public void doOperation() throws OpsException, IOException {
Tags instanceTags = instance.getTags();
OpenstackCloud cloud = findCloud();
if (cloud == null) {
throw new OpsException("Could not find cloud");
}
OpenstackComputeClient computeClient = openstack.getComputeClient(cloud);
getRecursionState().pushChildScope(cloud);
List<String> assignedInstanceIds = instanceTags.findAll(Tag.ASSIGNED);
if (assignedInstanceIds.isEmpty()) {
if (createInstance && !OpsContext.isDelete()) {
MachineCreationRequest request = buildMachineCreationRequest();
PlatformLayerKey instanceKey = instance.getKey();
request.tags.add(Tag.buildParentTag(instanceKey));
String serverName = buildServerName();
Server created = openstack.createInstance(cloud, serverName, request);
{
Tag instanceTag = Tag.build(Tag.ASSIGNED, created.getId());
platformLayer.addTag(instance.getKey(), instanceTag);
}
assignedInstanceIds.add(created.getId());
}
}
if (assignedInstanceIds.isEmpty() && !OpsContext.isDelete()) {
throw new OpsException("Instance not yet assigned");
}
Machine machine = null;
OpsTarget target = null;
if (!assignedInstanceIds.isEmpty()) {
if (assignedInstanceIds.size() != 1) {
log.warn("Multiple instance ids found: " + assignedInstanceIds);
}
// We just take the first instance id
String assignedInstanceId = Iterables.getFirst(assignedInstanceIds, null);
Server server = openstack.findServerById(cloud, assignedInstanceId);
if (server == null) {
if (OpsContext.isConfigure()) {
throw new OpsException("Unable to find assigned server: " + assignedInstanceId);
}
} else {
server = openstack.ensureHasPublicIp(cloud, server);
AsyncServerOperation powerOnOperation = openstack.ensurePoweredOn(cloud, server);
if (powerOnOperation != null) {
waitOperation(powerOnOperation);
}
machine = new OpenstackComputeMachine(openstack, cloud, server);
SshKey sshKey = service.getSshKey();
target = machine.getTarget(sshKey);
}
}
if (!assignedInstanceIds.isEmpty() && OpsContext.isDelete()) {
CloudBehaviours cloudBehaviours = new CloudBehaviours(cloud);
boolean supportsSecurityGroups = cloudBehaviours.supportsSecurityGroups();
for (String instanceId : assignedInstanceIds) {
Server server = openstack.findServerById(cloud, instanceId);
if (server == null) {
log.warn("Could not find assigned server: " + instanceId + ", ignoring");
continue;
}
SecurityGroup securityGroup = null;
if (supportsSecurityGroups) {
securityGroup = openstackHelpers.getMachineSecurityGroup(computeClient, server);
}
AsyncServerOperation terminateOperation = openstack.terminateInstance(cloud, instanceId);
if (securityGroup != null) {
// We need to terminate the instance before we delete the security group it uses
if (terminateOperation != null) {
waitOperation(terminateOperation);
}
try {
log.info("Deleting security group: " + securityGroup.getId());
computeClient.root().securityGroups().securityGroup(securityGroup.getId()).delete();
} catch (OpenstackNotFoundException e) {
log.info("Ignoring not-found error while deleting security group: " + securityGroup.getId());
}
}
}
}
RecursionState recursion = getRecursionState();
if (OpsContext.isDelete() && machine == null) {
recursion.setPreventRecursion(true);
} else {
recursion.pushChildScope(machine);
recursion.pushChildScope(target);
}
}
use of org.platformlayer.ops.Handler in project platformlayer by platformlayer.
the class EnsureFirewallIngress method handler.
@Handler
public void handler(OpenstackCloud cloud, OpenstackComputeMachine machine) throws OpsException, OpenstackException {
CloudBehaviours cloudBehaviours = new CloudBehaviours(cloud);
OpenstackComputeClient openstackComputeClient = cloudContext.getComputeClient(cloud);
// Find the public address, although the OpenStack firewall may be blocking it
publicAddress = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());
if (cloudBehaviours.supportsSecurityGroups()) {
Server server = machine.getServer();
SecurityGroup securityGroup = openstackHelpers.getMachineSecurityGroup(openstackComputeClient, server);
securityGroup = openstackComputeClient.root().securityGroups().securityGroup(securityGroup.getId()).show();
SecurityGroupRule matchingRule = findMatchingRule(securityGroup);
if (OpsContext.isConfigure()) {
if (matchingRule == null) {
CreateSecurityGroupRuleRequest rule = new CreateSecurityGroupRuleRequest();
rule.setCidr("0.0.0.0/0");
rule.setIpProtocol("tcp");
rule.setFromPort(model.publicPort);
rule.setToPort(model.publicPort);
rule.setParentGroupId(securityGroup.getId());
openstackComputeClient.root().securityGroupRules().create(rule);
}
}
if (OpsContext.isDelete()) {
if (matchingRule != null) {
openstackComputeClient.root().securityGroupRules().securityGroupRule(matchingRule.id).delete();
}
}
}
}
Aggregations