Skip to content

Commit

Permalink
Merge branch 'm-cmp:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsej108 authored Oct 8, 2024
2 parents 7dc3d60 + 423082c commit 2191380
Show file tree
Hide file tree
Showing 72 changed files with 424 additions and 747 deletions.
3 changes: 1 addition & 2 deletions bin/main/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ aes:
key: fb1755281b0ca6184a0ee644e6477ee7

cbtumblebug:
#url: 192.168.189.128
url: 13.125.199.35
url: 52.78.129.10
port: 1323
id: default
pass: default
Expand Down
2 changes: 1 addition & 1 deletion bin/main/jenkins/kubernetes_helm_uninstall_pipeline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@1254.v3f64639b_11dd">
<flow-definition plugin="workflow-job@1254.v3f64639b_11dd" name="helm_application_uninstall">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
Expand Down
148 changes: 78 additions & 70 deletions bin/main/jenkins/vm_application_install_pipeline.xml
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow-definition plugin="workflow-job@1316.vd2290d3341a_f" name="vm_application_install">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>NAMESPACE</name>
<description>Namespace</description>
<defaultValue>ns01</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>MCI_ID</name>
<description>MCI ID</description>
<defaultValue>mci01</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>CB_TUMBLEBUG_URI</name>
<description>Tumblebug URI</description>
<defaultValue>http://13.125.199.35:1323/tumblebug</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>TUMBLEBUG_USER</name>
<description>Tumblebug User</description>
<defaultValue>default</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.PasswordParameterDefinition>
<name>TUMBLEBUG_PASSWORD</name>
<description>Tumblebug Password</description>
<defaultValue>default</defaultValue>
</hudson.model.PasswordParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>APPLICATIONS</name>
<description>Applications to install (comma-separated)</description>
<defaultValue>nginx,tomcat9,mariadb-server,redis-server,grafana,prometheus</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@3731.ve4b_5b_857b_a_d3">
<script>
<flow-definition plugin="workflow-job@1254.v3f64639b_11dd" name="vm_application_install">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>NAMESPACE</name>
<description>Please enter namespace</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>MCI_ID</name>
<description>Please enter MCI ID</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>VM_ID</name>
<description>Please enter VM ID for software installation</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>APPLICATIONS</name>
<description>Please enter applications to install (comma-separated)</description>
<defaultValue>nginx,tomcat,mariadb-server,redis,grafana,prometheus</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>TUMBLEBUG_USER</name>
<description>Please enter Tumblebug user</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>TUMBLEBUG_PASSWORD</name>
<description>Please enter Tumblebug password</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>CB_TUMBLEBUG_URI</name>
<description>Please enter CB Tumblebug URI</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@3659.v582dc37621d8">
<script>
<![CDATA[
import groovy.json.JsonSlurper
Expand All @@ -56,10 +63,13 @@ def getSSHKey(jsonInput) {
} ?: ''
}
def getPublicInfoList(jsonInput) {
def getVMInfoList(jsonInput) {
def json = new JsonSlurper().parseText(jsonInput)
return json.findAll { it.key == 'MciSubGroupAccessInfo' }
.collectMany { it.value.MciVmAccessInfo*.publicIP }
return json.MciSubGroupAccessInfo.collectMany { subGroup ->
subGroup.MciVmAccessInfo.collect { vm ->
[id: vm.vmId, name: vm.vmId, ip: vm.publicIP] // vmId를 name으로 사용
}
}
}
pipeline {
Expand All @@ -74,7 +84,7 @@ pipeline {
if (response.contains('Http_Status_code:200')) {
echo "GET API call successful."
callData = response.replace('- Http_Status_code:200', '')
echo(callData)
echo "API Response: ${callData}"
} else {
error "GET API call failed with status code: ${response}"
}
Expand All @@ -83,15 +93,12 @@ pipeline {
def response2 = sh(script: """curl -X 'GET' --user '${TUMBLEBUG_USER}:${TUMBLEBUG_PASSWORD}' '${tb_sw_url}' -H 'accept: application/json' """, returnStdout: true).trim()
def pemkey = getSSHKey(response2)
if (pemkey) {
// 임시 디렉토리 사용
def tempDir = sh(script: "mktemp -d", returnStdout: true).trim()
def pemFile = "${tempDir}/${MCI_ID}.pem"
// 파일 쓰기 및 권한 설정
writeFile file: pemFile, text: pemkey
sh "chmod 600 ${pemFile}"
// 환경 변수로 PEM 파일 경로 저장
env.PEM_FILE_PATH = pemFile
echo "PEM file created at: ${pemFile}"
Expand All @@ -106,16 +113,16 @@ pipeline {
steps {
echo '>>>>>STAGE: Install Software'
script {
def publicIPs = getPublicInfoList(callData)
echo publicIPs.toString()
publicIPs[0].each{ ip-> echo "ip view : " + ip }
def vmInfoList = getVMInfoList(callData)
echo "VM Info: ${vmInfoList}"
echo "Target VM ID: ${VM_ID}"
def apps = APPLICATIONS.split(',')
publicIPs.each { ip ->
ip.each { inip ->
def cleanIp = inip.toString().replaceAll(/[\[\]]/, '')
println ">>test SSH to MCI VMs : ${cleanIp}"
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${env.PEM_FILE_PATH} cb-user@${cleanIp} '
def targetVM = vmInfoList.find { it.id == VM_ID }
if (targetVM) {
echo "Installing software on VM: ${targetVM.name} (ID: ${targetVM.id}, IP: ${targetVM.ip})"
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${env.PEM_FILE_PATH} cb-user@${targetVM.ip} '
#!/bin/bash
echo ==========================================================================
Expand Down Expand Up @@ -249,18 +256,19 @@ fi
echo ==========================================================================
'
"""
}
"""
} else {
echo "VM with ID ${VM_ID} not found in the list of available VMs."
}
}
}
}
}
}
]]>
</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
<disabled>false</disabled>
</flow-definition>
40 changes: 25 additions & 15 deletions bin/main/jenkins/vm_application_uninstall_pipeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<defaultValue>mci01</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>VM_ID</name>
<description>VM ID for software uninstallation</description>
<defaultValue></defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>CB_TUMBLEBUG_URI</name>
<description>Tumblebug URI</description>
Expand Down Expand Up @@ -56,10 +62,13 @@ def getSSHKey(jsonInput) {
} ?: ''
}
def getPublicInfoList(jsonInput) {
def getVMInfoList(jsonInput) {
def json = new JsonSlurper().parseText(jsonInput)
return json.findAll { it.key == 'MciSubGroupAccessInfo' }
.collectMany { it.value.MciVmAccessInfo*.publicIP }
return json.MciSubGroupAccessInfo.collectMany { subGroup ->
subGroup.MciVmAccessInfo.collect { vm ->
[id: vm.vmId, name: vm.vmId, ip: vm.publicIP]
}
}
}
pipeline {
Expand All @@ -74,7 +83,7 @@ pipeline {
if (response.contains('Http_Status_code:200')) {
echo "GET API call successful."
callData = response.replace('- Http_Status_code:200', '')
echo(callData)
echo "API Response: ${callData}"
} else {
error "GET API call failed with status code: ${response}"
}
Expand All @@ -100,16 +109,16 @@ pipeline {
steps {
echo '>>>>>STAGE: Uninstall Software'
script {
def publicIPs = getPublicInfoList(callData)
echo publicIPs.toString()
publicIPs[0].each{ ip-> echo "ip view : " + ip }
def vmInfoList = getVMInfoList(callData)
echo "VM Info: ${vmInfoList}"
echo "Target VM ID: ${VM_ID}"
def apps = APPLICATIONS.split(',')
publicIPs.each { ip ->
ip.each { inip ->
def cleanIp = inip.toString().replaceAll(/[\[\]]/, '')
println ">>test SSH to MCI VMs : ${cleanIp}"
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${env.PEM_FILE_PATH} cb-user@${cleanIp} '
def targetVM = vmInfoList.find { it.id == VM_ID }
if (targetVM) {
echo "Uninstalling software on VM: ${targetVM.name} (ID: ${targetVM.id}, IP: ${targetVM.ip})"
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${env.PEM_FILE_PATH} cb-user@${targetVM.ip} '
#!/bin/bash
echo ==========================================================================
Expand Down Expand Up @@ -163,8 +172,9 @@ fi
echo ==========================================================================
'
"""
}
"""
} else {
echo "VM with ID ${VM_ID} not found in the list of available VMs."
}
}
}
Expand Down
Loading

0 comments on commit 2191380

Please sign in to comment.