You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/05/22 11:04:59 UTC
[14/23] incubator-brooklyn git commit: set a bunch of tags telling
more about the user/app/entity for which a VM is created
set a bunch of tags telling more about the user/app/entity for which a VM is created
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/41c2d9b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/41c2d9b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/41c2d9b9
Branch: refs/heads/master
Commit: 41c2d9b90867222e5248806bc9aabe09a776b74d
Parents: 8008df4
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri May 8 14:21:06 2015 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri May 8 18:51:50 2015 +0100
----------------------------------------------------------------------
.../location/jclouds/JcloudsLocation.java | 65 +++++++++++++++++---
.../location/jclouds/JcloudsLocationConfig.java | 5 +-
2 files changed, 60 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/41c2d9b9/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index 1e1dccf..4e1c24e 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -90,6 +90,7 @@ import org.slf4j.LoggerFactory;
import brooklyn.config.ConfigKey;
import brooklyn.config.ConfigKey.HasConfigKey;
import brooklyn.config.ConfigUtils;
+import brooklyn.entity.Entity;
import brooklyn.entity.basic.Sanitizer;
import brooklyn.entity.rebind.persister.LocationWithObjectStore;
import brooklyn.entity.rebind.persister.PersistenceObjectStore;
@@ -108,6 +109,7 @@ import brooklyn.location.basic.LocationConfigUtils.OsCredential;
import brooklyn.location.basic.SshMachineLocation;
import brooklyn.location.cloud.AbstractCloudMachineProvisioningLocation;
import brooklyn.location.cloud.AvailabilityZoneExtension;
+import brooklyn.location.cloud.names.AbstractCloudMachineNamer;
import brooklyn.location.cloud.names.CloudMachineNamer;
import brooklyn.location.jclouds.JcloudsPredicates.NodeInLocation;
import brooklyn.location.jclouds.networking.JcloudsPortForwarderExtension;
@@ -117,6 +119,7 @@ import brooklyn.management.AccessController;
import brooklyn.util.ResourceUtils;
import brooklyn.util.collections.MutableList;
import brooklyn.util.collections.MutableMap;
+import brooklyn.util.collections.MutableSet;
import brooklyn.util.config.ConfigBag;
import brooklyn.util.crypto.SecureKeys;
import brooklyn.util.exceptions.CompoundRuntimeException;
@@ -596,21 +599,33 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
userCredentials = initTemplateForCreateUser(template, setup);
}
- //FIXME initialCredentials = initUserTemplateOptions(template, setup);
- for (JcloudsLocationCustomizer customizer : getCustomizers(setup)) {
- customizer.customize(this, computeService, template);
- customizer.customize(this, computeService, template.getOptions());
+ templateTimestamp = Duration.of(provisioningStopwatch);
+ // "Name" sets jclouds hostname
+ template.getOptions().getUserMetadata().put("Name", cloudMachineNamer.generateNewMachineUniqueNameFromGroupId(setup, groupId));
+
+ if (setup.get(JcloudsLocationConfig.INCLUDE_BROOKLYN_USER_METADATA)) {
+ template.getOptions().getUserMetadata().put("brooklyn-user", System.getProperty("user.name"));
+
+ Object context = setup.get(CALLER_CONTEXT);
+ if (context instanceof Entity) {
+ Entity entity = (Entity)context;
+ template.getOptions().getUserMetadata().put("brooklyn-app-id", entity.getApplicationId());
+ template.getOptions().getUserMetadata().put("brooklyn-app-name", entity.getApplication().getDisplayName());
+ template.getOptions().getUserMetadata().put("brooklyn-entity-id", entity.getId());
+ template.getOptions().getUserMetadata().put("brooklyn-entity-name", entity.getDisplayName());
+ template.getOptions().getUserMetadata().put("brooklyn-server-creation-date", Time.makeDateSimpleStampString());
+ }
}
+
+ customizeTemplate(setup, computeService, template);
+
LOG.debug("jclouds using template {} / options {} to provision machine in {}",
new Object[] {template, template.getOptions(), setup.getDescription()});
if (!setup.getUnusedConfig().isEmpty())
LOG.debug("NOTE: unused flags passed to obtain VM in "+setup.getDescription()+": "+
setup.getUnusedConfig());
-
- templateTimestamp = Duration.of(provisioningStopwatch);
- template.getOptions().getUserMetadata().put("Name", cloudMachineNamer.generateNewMachineUniqueNameFromGroupId(setup, groupId));
-
+
nodes = computeService.createNodesInGroup(groupId, 1, template);
provisionTimestamp = Duration.of(provisioningStopwatch);
} finally {
@@ -1089,6 +1104,37 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
})
.build();
+ /** hook whereby template customizations can be made for various clouds */
+ protected void customizeTemplate(ConfigBag setup, ComputeService computeService, Template template) {
+ for (JcloudsLocationCustomizer customizer : getCustomizers(setup)) {
+ customizer.customize(this, computeService, template);
+ customizer.customize(this, computeService, template.getOptions());
+ }
+
+ // these things are nice on softlayer
+ if (template.getOptions() instanceof SoftLayerTemplateOptions) {
+ SoftLayerTemplateOptions slT = ((SoftLayerTemplateOptions)template.getOptions());
+ if (Strings.isEmpty(slT.getDomainName())) {
+ // set a quasi-sensible domain name if none was provided (better than the default, jclouds.org)
+ slT.domainName("brooklyn.local");
+ }
+ // convert user metadata to tags because user metadata is otherwise ignored
+ Map<String, String> md = slT.getUserMetadata();
+ if (md!=null && !md.isEmpty()) {
+ Set<String> tags = MutableSet.copyOf(slT.getTags());
+ for (Map.Entry<String,String> entry: md.entrySet()) {
+ if ("Name".equalsIgnoreCase(entry.getKey())) {
+ // skip "Name" but use the other tags
+ } else {
+ tags.add(AbstractCloudMachineNamer.sanitize(entry.getKey())+":"+AbstractCloudMachineNamer.sanitize(entry.getValue()));
+ }
+ }
+ slT.tags(tags);
+ }
+ // TODO put user metadata and tags into notes, when jclouds exposes notes, because metadata not exposed via web portal
+ }
+ }
+
private static boolean listedAvailableTemplatesOnNoSuchTemplate = false;
/** returns the jclouds Template which describes the image to be built, for the given config and compute service */
@@ -1465,6 +1511,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
AdminAccess.Builder adminBuilder = AdminAccess.builder()
.adminUsername(user)
.grantSudoToAdminUser(grantUserSudo);
+ adminBuilder.cryptFunction(Sha512Crypt.function());
boolean useKey = Strings.isNonBlank(pubKey);
adminBuilder.cryptFunction(Sha512Crypt.function());
@@ -1519,7 +1566,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
LOG.debug("Machine we are about to create in "+this+" will be customized with: "+
statements);
- return new UserCreation(createdUserCreds, statements);
+ return new UserCreation(createdUserCreds, statements);
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/41c2d9b9/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
index 3e03837..a3a0304 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
@@ -77,7 +77,7 @@ public interface JcloudsLocationConfig extends CloudLocationConfig {
@SuppressWarnings("serial")
public static final ConfigKey<List<String>> EXTRA_PUBLIC_KEY_URLS_TO_AUTH = ConfigKeys.newConfigKey(new TypeToken<List<String>>() {},
"extraSshPublicKeyUrls", "Additional public keys (files or URLs, in SSH2/RFC4716/id_rsa.pub format) to add to authorized_keys", null);
-
+
public static final ConfigKey<Boolean> DONT_CREATE_USER = ConfigKeys.newBooleanConfigKey("dontCreateUser",
"Whether to skip creation of 'user' when provisioning machines (default false)", false);
public static final ConfigKey<Boolean> GRANT_USER_SUDO = ConfigKeys.newBooleanConfigKey("grantUserSudo",
@@ -161,6 +161,9 @@ public interface JcloudsLocationConfig extends CloudLocationConfig {
@Deprecated /** @deprecated since 0.7.0 use #USER_METADATA_MAP */
public static final ConfigKey<Object> USER_METADATA = USER_METADATA_MAP;
+ public static final ConfigKey<Boolean> INCLUDE_BROOKLYN_USER_METADATA = ConfigKeys.newBooleanConfigKey("includeBrooklynUserMetadata",
+ "Whether to set metadata about the context of a machine, e.g. brooklyn-entity-id, brooklyn-app-name (default true)", true);
+
public static final ConfigKey<Boolean> MAP_DEV_RANDOM_TO_DEV_URANDOM = ConfigKeys.newBooleanConfigKey(
"installDevUrandom", "Map /dev/random to /dev/urandom to prevent halting on insufficient entropy", true);