153 lines
5.3 KiB
YAML
153 lines
5.3 KiB
YAML
Namespaces:
|
|
=: org.openstack.ci_cd_pipeline_murano_app
|
|
std: io.murano
|
|
res: io.murano.resources
|
|
sys: io.murano.system
|
|
ci_cd_pipeline_murano_app: org.openstack.ci_cd_pipeline_murano_app
|
|
puppet: org.openstack.ci_cd_pipeline_murano_app.puppet
|
|
conf: io.murano.configuration
|
|
|
|
Name: Nodepool
|
|
|
|
Extends: std:Application
|
|
|
|
Properties:
|
|
instance:
|
|
Contract: $.class(puppet:PuppetInstance).notNull()
|
|
name:
|
|
Contract: $.string().notNull()
|
|
jenkins:
|
|
Contract: $.class(ci_cd_pipeline_murano_app:Jenkins).notNull()
|
|
zuul:
|
|
Contract: $.class(ci_cd_pipeline_murano_app:Zuul).notNull()
|
|
# Openstack credentials.
|
|
authUrl:
|
|
Contract: $.string().notNull()
|
|
username:
|
|
Contract: $.string().notNull()
|
|
tenant:
|
|
Contract: $.string().notNull()
|
|
password:
|
|
Contract: $.string().notNull()
|
|
systemConfigRepo:
|
|
Contract: $.class(puppet:SystemConfig)
|
|
|
|
Methods:
|
|
.init:
|
|
Body:
|
|
- $._environment: $.find(std:Environment).require()
|
|
|
|
deploy:
|
|
Body:
|
|
- super($this, $.deploy())
|
|
- If: $.getAttr(deployed, false)
|
|
Then:
|
|
Return:
|
|
|
|
- $securityGroupIngress:
|
|
- ToPort: 80
|
|
FromPort: 80
|
|
IpProtocol: tcp
|
|
External: true
|
|
- $._environment.securityGroupManager.addGroupIngress($securityGroupIngress)
|
|
- $._environment.reporter.report($this, 'Creating instance for Nodepool "{0}"'.format($.instance.name))
|
|
- $.instance.deploy()
|
|
- $._environment.reporter.report($this, 'Nodepool instance "{0}" with id {1} created.'.format($.instance.name, $.instance.openstackId))
|
|
|
|
- $._environment.reporter.report($this, 'Installing needed puppets for Nodepool...')
|
|
|
|
# initialize System Config
|
|
- If: $.systemConfigRepo = null
|
|
Then:
|
|
- $this.systemConfig: new(puppet:SystemConfig)
|
|
Else:
|
|
- $this.systemConfig: $.systemConfigRepo
|
|
- $this.systemConfig.installOnTheNode($this.instance)
|
|
|
|
- $._environment.reporter.report($this, 'Waiting while Jenkins is being deployed...')
|
|
- $.jenkins.deploy()
|
|
|
|
- $._environment.reporter.report($this, 'Configure Jenkins gearman plugin...')
|
|
- $.jenkins.configureGearmanPlugin($.detectPrimaryIP($.zuul.instance))
|
|
- $._environment.reporter.report($this, 'Gearman plugin is configured.')
|
|
|
|
- $._environment.reporter.report($this, 'Waiting while Zuul is being deployed...')
|
|
- $.zuul.deploy()
|
|
- $._environment.reporter.report($this, 'Loading configuration data for nodepool...')
|
|
- $.createConfiguration()
|
|
|
|
- $resources: new(sys:Resources)
|
|
- $template: $resources.yaml('DeployNodepool.template')
|
|
- $._environment.reporter.report($this, 'Installing Nodepool...')
|
|
- $.instance.agent.call($template, $resources)
|
|
- $._environment.reporter.report($this, 'Nodepool is installed.')
|
|
- $host: $.detectPrimaryIP($.instance)
|
|
- $._environment.reporter.report($this, 'Nodepool is available at host {}.'.format($host))
|
|
- $.setAttr(deployed, true)
|
|
|
|
createConfiguration:
|
|
Body:
|
|
- $jenkinsKey: $.jenkins.instance.getHieraValue('jenkins_ssh_private_key_contents')
|
|
- $jenkinsPubKey: $.jenkins.instance.getHieraValue('jenkins_ssh_pubkey_contents')
|
|
# Extract only the key itself without 'ssh-rsa' and 'username@fqdn'.
|
|
- $jenkinsPubKey: $jenkinsPubKey.split(' ')[1]
|
|
- $jenkinsHost: $.detectPrimaryIP($.jenkins.instance)
|
|
- $netInfo: $._environment.defaultNetworks.environment.describe()
|
|
|
|
# Command to retrieve Jenkins API Token.
|
|
- $linux: new(conf:Linux)
|
|
- $resource: new(sys:Resources)
|
|
- $replacements:
|
|
"%USERNAME%": $.jenkins.ldap.ldapRootUser
|
|
"%PASSWORD%": $.jenkins.ldap.ldapRootPass
|
|
"%JENKINS_HOST%": $jenkinsHost
|
|
- $script: $resource.string('scripts/get_api_token.sh').replace($replacements)
|
|
- $apiKey: $linux.runCommand($.instance.agent, $script).stdout
|
|
- $credentialsId: $.jenkins.configureCredentials()
|
|
|
|
- $config:
|
|
jenkins_api_key: $apiKey
|
|
jenkins_api_user: $.jenkins.ldap.ldapRootUser
|
|
jenkins_credentials_id: $credentialsId
|
|
jenkins_host: $jenkinsHost
|
|
nodepool_mysql_password: 'nodepool'
|
|
nodepool_mysql_root_password: 'root'
|
|
nodepool_network_uuid: $netInfo.netId
|
|
nodepool_ssh_private_key: $jenkinsKey
|
|
nodepool_ssh_pubkey: $jenkinsPubKey
|
|
os_auth_url: $.authUrl
|
|
os_password: $.password
|
|
os_tenant_name: $.tenant
|
|
os_username: $.username
|
|
zuul_host: $.detectPrimaryIP($.zuul.instance)
|
|
|
|
- $.instance.putHieraData($config)
|
|
|
|
detectPrimaryIP:
|
|
Arguments:
|
|
- instance:
|
|
Contract: $.class(res:Instance).notNull()
|
|
Body:
|
|
- If: $instance.assignFloatingIp
|
|
Then:
|
|
- $host: $instance.floatingIpAddress
|
|
Else:
|
|
- $host: $instance.ipAddresses[0]
|
|
- Return: $host
|
|
|
|
releaseResources:
|
|
Body:
|
|
# Release resources.
|
|
- $resources: new(sys:Resources)
|
|
- $template: $resources.yaml('ReleaseResources.template')
|
|
- $._environment.reporter.report($this, 'Deleting nodepool-related VMs and Images from tenant...')
|
|
- $.instance.agent.call($template, $resources)
|
|
- $.instance.releaseResources()
|
|
- $._environment.reporter.report($this, 'Done.')
|
|
- $.reportDestroyed()
|
|
- $.setAttr(deployed, false)
|
|
|
|
destroy:
|
|
Body:
|
|
- $.releaseResources()
|