@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey()); SecurityGroups.deleteByName(cloudStackClient, securityGroupName); } }
@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey()); LOG.info("Deleting Admin Access Key pair {}", keyName); cloudStackClient.getSSHKeyPairClient().deleteSSHKeyPair(keyName); } }
@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { Network network = checkNotNull(pool.getNetwork(), "Please configure a network for the pool"); String securityGroupName = SecurityGroups.formatNameFromBusinessKey(execution.getProcessBusinessKey()); SecurityGroup securityGroup; try { LOG.info("Creating SecurityGroup {}", securityGroupName); securityGroup = SecurityGroups.createSecurityGroup(cloudStackClient, securityGroupName); } catch (IllegalStateException e) { LOG.info("Failed creating SecurityGroup {} - checking if it exists", securityGroupName); securityGroup = SecurityGroups.getByName(cloudStackClient, securityGroupName); LOG.info("Delete old SecurityGroup rules for {}", securityGroupName); SecurityGroups.deleteNetworkRules(cloudStackClient, securityGroup); } if (securityGroup != null) { LOG.info("Applying network rules on SecurityGroup {}", securityGroupName); SecurityGroups.applyNetworkRules(cloudStackClient, securityGroup, network); } } }
@Override public void notify(DelegateExecution exec) throws Exception { if (LOG.isLoggable(Level.FINE)){ LOG.fine("name = "+name); LOG.fine("exec.getEventName() -> "+exec.getEventName()); LOG.fine("exec.getId() -> "+exec.getId()); LOG.fine("exec.getProcessBusinessKey() -> "+exec.getProcessBusinessKey()); LOG.fine("exec.getProcessInstanceId() -> "+exec.getProcessInstanceId()); LOG.fine("jenkow_build_parent = "+exec.getVariable("jenkow_build_parent")); LOG.fine("jenkow_build_number = "+exec.getVariable("jenkow_build_number")); } PrintStream log = BuildLoggerMap.get(exec.getVariable("jenkow_build_parent"),exec.getVariable("jenkow_build_number")); if (log != null){ String ev = exec.getEventName(); if (ev != null) ev += "ed"; log.println(Consts.UI_PREFIX+": "+name+" "+ev); } } }
for (Machine machine : machines) { final String perMachineProcessBusinessKey = String.format("%s-%s-%s", execution.getProcessBusinessKey(), type, machine.getExternalId());
@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey()); LOG.info("Creating admin access key pair as {}", keyName); SSHKeyPairClient sshKeyPairClient = cloudStackClient.getSSHKeyPairClient(); try { SshKeyPair sshKeyPair = sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey()); LOG.info("Registered remote key with fingerprint {}", sshKeyPair.getFingerprint()); } catch (IllegalStateException e) { LOG.warn("Key with name {} already exists", keyName); SshKeyPair key = sshKeyPairClient.getSSHKeyPair(keyName); if (key.getFingerprint().equals(SshKeys.fingerprintPublicKey(pool.getAdminAccess().getPublicKey()))) { LOG.info("Fingerprints match. Not updating admin access key pair."); } else { LOG.info("Fingerprint do not match. Replacing admin access key pair."); sshKeyPairClient.deleteSSHKeyPair(keyName); sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey()); } } } }
@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { if (execution.getVariable(ProcessVariables.NETWORK_ID) != null) { LOG.warn("Network process variable ({}) will be overwritten!", ProcessVariables.NETWORK_ID); } Network network; final String existingNetwork = pool.getNetwork().getOption(NetworkOptions.EXISTING_NETWORK_ID); if (existingNetwork != null) { network = checkNotNull(cloudStackClient.getNetworkClient().getNetwork(existingNetwork), "Network with id " + existingNetwork + " does not exist"); } else { final String networkName = Networks.formatNameFromBusinessKey(execution.getProcessBusinessKey()); final String zoneId = pool.getProvider().getOption(ProviderOptions.ZONE_ID); final String networkOfferingId = pool.getProvider().getOption(ProviderOptions.NETWORK_OFFERING_ID); try { network = Networks.getByName(cloudStackClient, networkName); LOG.info("Network with name {} exists.", networkName); } catch (NoSuchElementException e) { LOG.info(String.format("Creating network %s in zone %s with offering %s", networkName, zoneId, networkOfferingId)); network = cloudStackClient.getNetworkClient().createNetworkInZone(zoneId, networkOfferingId, networkName, networkName, CreateNetworkOptions.NONE); } } LOG.info("Storing network id {} in process variable {}", network.getId(), ProcessVariables.NETWORK_ID); execution.setVariable(ProcessVariables.NETWORK_ID, network.getId()); } }
@Override public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) { final String businessKey = execution.getProcessBusinessKey(); final String keyPairName = KeyPairs.formatNameFromBusinessKey(businessKey); final String zoneId = pool.getOptions().get(ProviderOptions.ZONE_ID); final String templateId = pool.getSoftware().getImageId(); final String serviceOffering = pool.getHardware().getType(); LOG.info("Starting instances!"); AsyncCreateResponse asyncCreateResponse = cloudStackClient.getVirtualMachineClient() .deployVirtualMachineInZone(zoneId, serviceOffering, templateId, DeployVirtualMachineOptions.Builder .displayName(businessKey) .group(businessKey) .networkId(Networks.formatNameFromBusinessKey(businessKey)) .keyPair(keyPairName) .name(businessKey)); VirtualMachines.waitForVMtoStart(cloudStackClient, businessKey); } }