@Override public CloudResource build( OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) throws Exception { try { OSClient osClient = createOSClient(auth); NeutronNetworkView networkView = new NeutronNetworkView(network); Router router = Builders.router() .name(resource.getName()) .adminStateUp(true) .tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)) .externalGateway(networkView.getPublicNetId()) .build(); router = osClient.networking().router().create(router); osClient .networking() .router() .attachInterface( router.getId(), AttachInterfaceType.SUBNET, context.getStringParameter(OpenStackConstants.SUBNET_ID)); return createPersistedResource(resource, router.getId()); } catch (OS4JException ex) { throw new OpenStackResourceException( "Router creation failed", resourceType(), resource.getName(), ex); } }
@SuppressWarnings("unchecked") @Override public List<CloudResourceStatus> launch( AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) { String stackName = authenticatedContext.getCloudContext().getName(); boolean existingNetwork = isExistingNetwork(stack); boolean assignFloatingIp = assignFloatingIp(stack); String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack); String heatTemplate = heatTemplateBuilder.build( stackName, stack.getGroups(), stack.getSecurity(), stack.getImage(), existingNetwork, existingSubnetCidr != null, assignFloatingIp); Map<String, String> parameters = heatTemplateBuilder.buildParameters( authenticatedContext, stack.getNetwork(), stack.getImage(), existingNetwork, existingSubnetCidr); OSClient client = openStackClient.createOSClient(authenticatedContext); Stack heatStack = client .heat() .stacks() .create( Builders.stack() .name(stackName) .template(heatTemplate) .disableRollback(false) .parameters(parameters) .timeoutMins(OPERATION_TIMEOUT) .build()); CloudResource cloudResource = new CloudResource.Builder().type(ResourceType.HEAT_STACK).name(heatStack.getId()).build(); try { notifier.notifyAllocation(cloudResource, authenticatedContext.getCloudContext()); } catch (Exception e) { // Rollback terminate(authenticatedContext, stack, Lists.newArrayList(cloudResource)); } List<CloudResourceStatus> resources = check(authenticatedContext, Lists.newArrayList(cloudResource)); LOGGER.debug("Launched resources: {}", resources); return resources; }
@Test(enabled = false) public void testAssociateHealthMonitor() { String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a"; String healthId = "8767284a-b542-4db6-8393-0a404a959c1d"; HealthMonitorAssociate associate = Builders.lbPoolAssociateHealthMonitor().id(healthId).build(); HealthMonitor result = osv3().networking().loadbalancers().lbPool().associateHealthMonitor(poolId, associate); assertTrue(result != null); }
public void testUpdatePool() throws IOException { respondWith(LBPOOL_UPDATE_JSON); String poolId = "db083bf7-c455-4758-b1ad-203cf441a73a"; String name = "update"; LbPoolUpdate update = Builders.lbPoolUpdate() .adminStateUp(false) .description("update") .lbMethod(LbMethod.LEAST_CONNECTIONS) .name(name) .build(); LbPool result = osv3().networking().loadbalancers().lbPool().update(poolId, update); assertEquals(name, result.getName()); assertEquals(LbMethod.LEAST_CONNECTIONS, result.getLbMethod()); assertFalse(result.isAdminStateUp()); }
@Override public Stack create( String name, String template, Map<String, String> parameters, boolean disableRollback, Long timeoutMins) { checkNotNull(name); checkNotNull(template); checkNotNull(parameters); checkNotNull(timeoutMins); return create( Builders.stack() .name(name) .template(template) .parameters(parameters) .timeoutMins(timeoutMins) .build()); }
public void testCreatePool() throws IOException { respondWith(LBPOOL_JSON); String name = "pool1"; Protocol protocol = Protocol.HTTP; LbPool create = Builders.lbPool() .adminStateUp(true) .description("pool") .lbMethod(LbMethod.ROUND_ROBIN) .name(name) .provider("haproxy") .subnetId("7d1dab60-cf8a-4f75-af5c-44aab98b0c42") .tenantId("d7fd03242ffa4933863bc528ed884fb6") .protocol(protocol) .build(); LbPool result = osv3().networking().loadbalancers().lbPool().create(create); assertEquals(name, result.getName()); assertEquals(result.getLbMethod(), LbMethod.ROUND_ROBIN); assertEquals(protocol, result.getProtocol()); }
private List<CloudResourceStatus> updateHeatStack( AuthenticatedContext authenticatedContext, List<CloudResource> resources, String heatTemplate, Map<String, String> parameters) { CloudResource resource = utils.getHeatResource(resources); String stackName = authenticatedContext.getCloudContext().getName(); String heatStackId = resource.getName(); OSClient client = openStackClient.createOSClient(authenticatedContext); StackUpdate updateRequest = Builders.stackUpdate() .template(heatTemplate) .parameters(parameters) .timeoutMins(OPERATION_TIMEOUT) .build(); client.heat().stacks().update(stackName, heatStackId, updateRequest); LOGGER.info( "Heat stack update request sent with stack name: '{}' for Heat stack: '{}'", stackName, heatStackId); return check(authenticatedContext, resources); }
public Server provision(JCloudsCloud cloud) { final ServerCreateBuilder builder = Builders.server(); final String nodeName = name + "-" + System.currentTimeMillis() % 1000; LOGGER.info("Provisioning new openstack node " + nodeName); // Ensure predictable node name so we can inject it into user data builder.name(nodeName); if (!Strings.isNullOrEmpty(imageId)) { LOGGER.info("Setting image id to " + imageId); builder.image(imageId); } if (!Strings.isNullOrEmpty((hardwareId))) { LOGGER.info("Setting hardware Id to " + hardwareId); builder.flavor(hardwareId); } if (!Strings.isNullOrEmpty(networkId)) { LOGGER.info("Setting network to " + networkId); builder.networks(Arrays.asList(networkId)); } if (!Strings.isNullOrEmpty(securityGroups)) { LOGGER.info("Setting security groups to " + securityGroups); for (String sg: csvToArray(securityGroups)) { builder.addSecurityGroup(sg); } } if (!Strings.isNullOrEmpty(keyPairName)) { LOGGER.info("Setting keyPairName to " + keyPairName); builder.keypairName(keyPairName); } if (!Strings.isNullOrEmpty(availabilityZone)) { LOGGER.info("Setting availabilityZone to " + availabilityZone); builder.availabilityZone(availabilityZone); } ExtensionList<ConfigProvider> providers = ConfigProvider.all(); UserDataConfig.UserDataConfigProvider myProvider = providers.get(UserDataConfig.UserDataConfigProvider.class); Config userData = myProvider.getConfigById(userDataId); if (userData != null && !userData.content.isEmpty()) { HashMap<String, String> vars = new HashMap<String, String>(); String rootUrl = Jenkins.getInstance().getRootUrl(); vars.put("JENKINS_URL", rootUrl); vars.put("SLAVE_JAR_URL", rootUrl + "jnlpJars/slave.jar"); vars.put("SLAVE_JNLP_URL", rootUrl + "computer/" + nodeName + "/slave-agent.jnlp"); vars.put("SLAVE_LABELS", labelString); String content = Util.replaceMacro(userData.content, vars); LOGGER.info("Sending user-data:\n" + content); builder.userData(Base64.encode(content.getBytes())); } final Openstack openstack = cloud.getOpenstack(); final Server server = openstack.bootAndWaitActive(builder, cloud.startTimeout); LOGGER.info("Provisioned: " + server.toString()); if (cloud.isFloatingIps()) { LOGGER.info("Assiging floating IP to " + nodeName); openstack.assignFloatingIp(server); } // Make sure address information is propagated return openstack.updateInfo(server); }