mirror of https://github.com/apache/jclouds.git
Issue 934: templateOptions.tags,userMetadata for vcloud
This commit is contained in:
parent
d00efae8a7
commit
bb5927515e
|
@ -21,6 +21,7 @@ package org.jclouds.vcloud.compute.functions;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.filter;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue;
|
||||
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
|
||||
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getIpsFromVApp;
|
||||
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.toComputeOs;
|
||||
|
@ -43,6 +44,8 @@ import org.jclouds.vcloud.domain.Status;
|
|||
import org.jclouds.vcloud.domain.VApp;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import static com.google.common.base.Strings.*;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
|
@ -74,6 +77,9 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
|||
builder.ids(from.getHref().toASCIIString());
|
||||
builder.uri(from.getHref());
|
||||
builder.name(from.getName());
|
||||
if (!isNullOrEmpty(from.getDescription()) && from.getDescription().indexOf('=') != -1)
|
||||
addMetadataAndParseTagsFromCommaDelimitedValue(builder,
|
||||
Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription()));
|
||||
builder.hostname(from.getName());
|
||||
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
|
||||
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
||||
|
|
|
@ -23,10 +23,12 @@ import static com.google.common.base.Predicates.not;
|
|||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.get;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue;
|
||||
import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
|
@ -57,6 +59,7 @@ import org.jclouds.vcloud.domain.network.NetworkConfig;
|
|||
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -189,8 +192,10 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
|
||||
|
||||
String description = VCloudTemplateOptions.class.cast(template.getOptions()).getDescription();
|
||||
if (description == null)
|
||||
description = vAppTemplate.getName();
|
||||
if (description == null) {
|
||||
Map<String, String> md = metadataAndTagsAsCommaDelimitedValue(template.getOptions());
|
||||
description = Joiner.on('\n').withKeyValueSeparator("=").join(md);
|
||||
}
|
||||
|
||||
options.description(description);
|
||||
options.deploy(false);
|
||||
|
|
|
@ -18,12 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.compute;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
|
@ -55,11 +53,4 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|||
return new SshjSshClientModule();
|
||||
}
|
||||
|
||||
// vcloud does not support metadata
|
||||
@Override
|
||||
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
|
||||
assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format(
|
||||
"node userMetadata did not match %s %s", userMetadata, node);
|
||||
}
|
||||
|
||||
}
|
|
@ -43,13 +43,16 @@ import org.jclouds.vcloud.compute.config.VCloudComputeServiceDependenciesModule;
|
|||
import org.jclouds.vcloud.domain.ReferenceType;
|
||||
import org.jclouds.vcloud.domain.Status;
|
||||
import org.jclouds.vcloud.domain.VApp;
|
||||
import org.jclouds.vcloud.domain.internal.VAppImpl;
|
||||
import org.jclouds.vcloud.xml.VAppHandler;
|
||||
import org.jclouds.vcloud.xml.ovf.VCloudResourceAllocationSettingDataHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -113,10 +116,40 @@ public class VAppToNodeMetadataTest {
|
|||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||
NodeMetadata node = converter.apply(result);
|
||||
assertEquals(node.getUserMetadata(), ImmutableMap.<String, String>of());
|
||||
assertEquals(node.getTags(), ImmutableSet.<String>of());
|
||||
assertEquals(node.getLocation(), location);
|
||||
assertEquals(node.getPrivateAddresses(), ImmutableSet.of("172.16.7.230"));
|
||||
assertEquals(node.getPublicAddresses(), ImmutableSet.of());
|
||||
}
|
||||
|
||||
|
||||
public void testWithEncodedMetadata() {
|
||||
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
||||
.scope(LocationScope.PROVIDER).build();
|
||||
Injector injector = createInjectorWithLocation(location);
|
||||
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
|
||||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||
ImmutableMap<String, String> metadata = ImmutableMap.<String, String>of("foo", "bar");
|
||||
ImmutableSet<String> tags = ImmutableSet.<String>of("tag1", "tag2");
|
||||
|
||||
String description = Joiner
|
||||
.on('\n')
|
||||
.withKeyValueSeparator("=")
|
||||
.join(ImmutableMap.<String, String> builder().putAll(metadata)
|
||||
.put("jclouds_tags", Joiner.on(',').join(tags)).build());
|
||||
|
||||
result = new VAppImpl(result.getName(), result.getType(), result.getHref(), result.getStatus(), result.getVDC(),
|
||||
description, result.getTasks(), result.isOvfDescriptorUploaded(), result.getChildren(),
|
||||
result.getNetworkSection());
|
||||
|
||||
NodeMetadata node = converter.apply(result);
|
||||
assertEquals(node.getUserMetadata(), metadata);
|
||||
assertEquals(node.getTags(), tags);
|
||||
|
||||
}
|
||||
|
||||
public void testGracefulWhenNoIPs() {
|
||||
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
||||
|
|
|
@ -70,7 +70,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
String instantiateXML = XMLBuilder.create("InstantiateVAppTemplateParams")
|
||||
.a("xmlns", ns).a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1")
|
||||
.a("deploy", "false").a("name", name).a("powerOn", "false")
|
||||
.e("Description").t("UbuntuServer-x64-2GB").up()
|
||||
.e("Description").up()
|
||||
.e("InstantiationParams")
|
||||
.e("NetworkConfigSection")
|
||||
.e("ovf:Info").t("Configuration parameters for logical networks").up()
|
||||
|
@ -127,7 +127,7 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
String instantiateXML = XMLBuilder.create("InstantiateVAppTemplateParams")
|
||||
.a("xmlns", ns).a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1")
|
||||
.a("deploy", "false").a("name", name).a("powerOn", "false")
|
||||
.e("Description").t("UbuntuServer-x64-2GB").up()
|
||||
.e("Description").up()
|
||||
.e("InstantiationParams")
|
||||
.e("NetworkConfigSection")
|
||||
.e("ovf:Info").t("Configuration parameters for logical networks").up()
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<Link rel="controlAccess" type="application/vnd.vmware.vcloud.controlAccess+xml" href="https://1.1.1.1/api/v1.0/vApp/vapp-1/action/controlAccess"/>
|
||||
<Link rel="up" type="application/vnd.vmware.vcloud.vdc+xml" href="https://1.1.1.1/api/v1.0/vdc/1"/>
|
||||
<Link rel="edit" type="application/vnd.vmware.vcloud.vApp+xml" href="https://1.1.1.1/api/v1.0/vApp/vapp-1"/>
|
||||
<Description/>
|
||||
<Description>Example FTP Server vApp</Description>
|
||||
<LeaseSettingsSection type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" href="https://1.1.1.1/api/v1.0/vApp/vapp-1/leaseSettingsSection/" ovf:required="false">
|
||||
<ovf:Info>Lease settings section</ovf:Info>
|
||||
<Link rel="edit" type="application/vnd.vmware.vcloud.leaseSettingsSection+xml" href="https://1.1.1.1/api/v1.0/vApp/vapp-1/leaseSettingsSection/"/>
|
||||
|
|
|
@ -55,6 +55,8 @@ public class BluelockVCloudZone01TemplateBuilderLiveTest extends BaseTemplateBui
|
|||
return !input.version.equals("") || !input.is64Bit;
|
||||
case RHEL:
|
||||
return !input.version.equals("");
|
||||
case WINDOWS:
|
||||
return !input.version.equals("");
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue