Пример #1
0
 public void endElement(String uri, String name, String qName) {
   taskHandler.endElement(uri, name, qName);
   if (qName.equals("Task")) {
     this.tasks.add(taskHandler.getResult());
   } else if (qName.equals("Description")) {
     if (inFirewallRule) firewallRuleDescription = currentOrNull();
     else orgDescription = currentOrNull();
   } else if (qName.equals("FenceMode")) {
     fenceMode = FenceMode.fromValue(currentOrNull());
   } else if (qName.equals("StartAddress")) {
     startAddress = currentOrNull();
   } else if (qName.equals("EndAddress")) {
     endAddress = currentOrNull();
   } else if (qName.equals("AllocatedIpAddress")) {
     allocatedIpAddresses.add(currentOrNull());
   } else if (qName.equals("IpRange")) {
     ipRanges.add(new IpRange(startAddress, endAddress));
     this.startAddress = null;
     this.endAddress = null;
   } else if (qName.equals("IsInherited")) {
     inherited = Boolean.parseBoolean(currentOrNull());
   } else if (qName.equals("Gateway")) {
     gateway = currentOrNull();
   } else if (qName.equals("Netmask")) {
     netmask = currentOrNull();
   } else if (qName.equals("Dns1")) {
     dns1 = currentOrNull();
   } else if (qName.equals("Dns2")) {
     dns2 = currentOrNull();
   } else if (qName.equals("DnsSuffix")) {
     dnsSuffix = currentOrNull();
   } else if (qName.equals("IpScope")) {
     ipScope =
         new IpScope(
             inherited, gateway, netmask, dns1, dns2, dnsSuffix, ipRanges, allocatedIpAddresses);
     this.inherited = false;
     this.gateway = null;
     this.netmask = null;
     this.dns1 = null;
     this.dns2 = null;
     this.dnsSuffix = null;
     this.ipRanges = Sets.newLinkedHashSet();
     this.allocatedIpAddresses = Sets.newLinkedHashSet();
   } else if (qName.equals("IsEnabled")) {
     if (inFirewallRule) firewallRuleEnabled = Boolean.parseBoolean(currentOrNull());
     else serviceEnabled = Boolean.parseBoolean(currentOrNull());
   } else if (qName.equals("DefaultLeaseTime")) {
     defaultLeaseTime = Integer.parseInt(currentOrNull());
   } else if (qName.equals("MaxLeaseTime")) {
     maxLeaseTime = Integer.parseInt(currentOrNull());
   } else if (qName.equals("DhcpService")) {
     this.dhcpService =
         new DhcpService(
             serviceEnabled, defaultLeaseTime, maxLeaseTime, Iterables.getOnlyElement(ipRanges));
     this.serviceEnabled = false;
     this.defaultLeaseTime = null;
     this.maxLeaseTime = null;
     this.ipRanges = Sets.newLinkedHashSet();
   } else if (qName.equals("Policy")) {
     if (inFirewallRule) firewallPolicy = FirewallPolicy.fromValue(currentOrNull());
     else natPolicy = NatPolicy.fromValue(currentOrNull());
   } else if (qName.equals("Tcp")) {
     tcp = Boolean.parseBoolean(currentOrNull());
   } else if (qName.equals("Udp")) {
     udp = Boolean.parseBoolean(currentOrNull());
   } else if (qName.equals("Protocols")) {
     this.protocols = new FirewallProtocols(tcp, udp);
     this.tcp = false;
     this.udp = false;
   } else if (qName.equals("DestinationIp")) {
     this.destinationIp = currentOrNull();
   } else if (qName.equals("FirewallRule")) {
     this.inFirewallRule = false;
     this.firewallRules.add(
         new FirewallRule(
             firewallRuleEnabled,
             firewallRuleDescription,
             firewallPolicy,
             protocols,
             port,
             destinationIp));
     this.firewallRuleEnabled = false;
     this.firewallRuleDescription = null;
     this.firewallPolicy = null;
     this.protocols = null;
     this.port = -1;
     this.destinationIp = null;
   } else if (qName.equals("FirewallService")) {
     firewallService = new FirewallService(serviceEnabled, firewallRules);
     this.serviceEnabled = false;
     this.firewallRules = Lists.newArrayList();
   } else if (qName.equals("NatType")) {
     natType = NatType.fromValue(currentOrNull());
   } else if (qName.equals("MappingMode")) {
     mappingMode = MappingMode.fromValue(currentOrNull());
   } else if (qName.equalsIgnoreCase("ExternalIP")) {
     externalIP = currentOrNull();
   } else if (qName.equalsIgnoreCase("VAppScopedVmId")) {
     vAppScopedVmId = currentOrNull();
   } else if (qName.equalsIgnoreCase("VAppScopedLocalId")) {
     vAppScopedLocalId = currentOrNull();
   } else if (qName.equalsIgnoreCase("vmNicId")) {
     vmNicId = Integer.parseInt(currentOrNull());
   } else if (qName.equals("OneToOneVmRule")) {
     natRules.add(new OneToOneVmRule(mappingMode, externalIP, vAppScopedVmId, vmNicId));
     this.mappingMode = null;
     this.externalIP = null;
     this.vAppScopedVmId = null;
     this.vmNicId = -1;
   } else if (qName.equalsIgnoreCase("ExternalPort")) {
     externalPort = Integer.parseInt(currentOrNull());
   } else if (qName.equalsIgnoreCase("IxternalIP")) {
     internalIP = currentOrNull();
   } else if (qName.equalsIgnoreCase("InternalPort")) {
     internalPort = Integer.parseInt(currentOrNull());
   } else if (qName.equals("NatProtocol")) {
     natProtocol = NatProtocol.valueOf(currentOrNull());
   } else if (qName.equals("PortForwardingRule")) {
     natRules.add(
         new PortForwardingRule(externalIP, externalPort, internalIP, internalPort, natProtocol));
     this.externalIP = null;
     this.externalPort = -1;
     this.internalIP = null;
     this.internalPort = -1;
     this.natProtocol = null;
   } else if (qName.equals("VmRule")) {
     natRules.add(
         new VmRule(
             externalIP, externalPort, vAppScopedLocalId, vmNicId, internalPort, natProtocol));
     this.externalIP = null;
     this.externalPort = -1;
     this.vAppScopedLocalId = null;
     this.vmNicId = -1;
     this.internalPort = -1;
     this.natProtocol = null;
   } else if (qName.equals("NatService")) {
     this.natService = new NatService(serviceEnabled, natType, natPolicy, natRules);
     this.serviceEnabled = false;
     this.natType = null;
     this.natPolicy = null;
     this.natRules = Lists.newArrayList();
   } else if (qName.equals("Features")) {
     this.features = new Features(dhcpService, firewallService, natService);
     this.dhcpService = null;
     this.firewallService = null;
     this.natService = null;
   } else if (qName.equals("Configuration")) {
     configuration =
         new OrgNetworkImpl.ConfigurationImpl(ipScope, parentNetwork, fenceMode, features);
     this.ipScope = null;
     this.parentNetwork = null;
     this.fenceMode = null;
     this.features = null;
   } else if (qName.equals("AllowedExternalIpAddress")) {
     allowedExternalIpAddresses.add(currentOrNull());
   }
   currentText = new StringBuilder();
 }
  public void testInstantiateVAppFromTemplateWhenUsingOverriddenNetworkAndFenceMode()
      throws Exception {

    String name = "group-abcd";
    FenceMode fenceMode = FenceMode.NAT_ROUTED;
    URI parentNetwork = URI.create(ENDPOINT + "/v1.0/network/" + "foooooooo");

    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")
            .up()
            .e("InstantiationParams")
            .e("NetworkConfigSection")
            .e("ovf:Info")
            .t("Configuration parameters for logical networks")
            .up()
            .e("NetworkConfig")
            .a("networkName", "jclouds") // NOTE not "None"
            .e("Configuration")
            .e("ParentNetwork")
            .a("href", parentNetwork.toASCIIString())
            .up()
            .e("FenceMode")
            .t(fenceMode.toString())
            .up()
            .up()
            .up()
            .up()
            .up()
            .e("Source")
            .a("href", ENDPOINT + "/v1.0/vAppTemplate/" + templateId)
            .up()
            .e("AllEULAsAccepted")
            .t("true")
            .up()
            .asString(outputProperties);

    HttpRequest version1_0InstantiateWithCustomizedNetwork =
        HttpRequest.builder()
            .method("POST")
            .endpoint(ENDPOINT + "/v1.0/vdc/" + vdcId + "/action/instantiateVAppTemplate")
            .addHeader(HttpHeaders.ACCEPT, "application/vnd.vmware.vcloud.vApp+xml")
            .addHeader("x-vcloud-authorization", sessionToken)
            .addHeader(HttpHeaders.COOKIE, "vcloud-token=" + sessionToken)
            .payload(
                payloadFromStringWithContentType(
                    instantiateXML,
                    "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml"))
            .build();

    ComputeService compute =
        requestsSendResponses(
            ImmutableMap.<HttpRequest, HttpResponse>builder()
                .put(versionsRequest, versionsResponseFromVCD1_5)
                .put(
                    version1_0LoginRequest,
                    successfulVersion1_0LoginResponseFromVCD1_5WithSingleOrg)
                .put(
                    version1_0GetOrgRequest,
                    successfulVersion1_0GetOrgResponseFromVCD1_5WithSingleTasksListVDCAndNetwork)
                .put(
                    version1_0GetCatalogRequest,
                    successfulVersion1_0GetCatalogResponseFromVCD1_5WithSingleTemplate)
                .put(
                    version1_0GetCatalogItemRequest,
                    successfulVersion1_0GetCatalogItemResponseFromVCD1_5ForTemplate)
                .put(
                    version1_0GetVDCRequest,
                    successfulVersion1_0GetVDCResponseFromVCD1_5WithSingleTemplateAndNetwork)
                .put(
                    version1_0GetVAppTemplateRequest,
                    successfulVersion1_0GetVAppTemplateResponseFromVCD1_5WithSingleVMAndVDCParent)
                .put(
                    version1_0GetOVFForVAppTemplateRequest,
                    successfulVersion1_0GetOVFForVAppTemplateResponseFromVCD1_5WithSingleVM)
                .put(
                    version1_0InstantiateWithCustomizedNetwork,
                    successfulVersion1_0InstantiatedVApp)
                .build());

    InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn starter =
        compute
            .getContext()
            .utils()
            .injector()
            .getInstance(
                InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployAndPowerOn.class);

    Template template = compute.templateBuilder().build();
    template
        .getOptions()
        .as(VCloudTemplateOptions.class)
        .parentNetwork(parentNetwork)
        .fenceMode(fenceMode);
    starter.instantiateVAppFromTemplate(name, template);
  }