
The jenkins name was accidentally checked in with a test value and floating ips were not handled correctly. HPCS was previously running an older API and I didn't notice until they upgraded that it was not consistent with devstack. Change-Id: Ib858726f4ae86ba988bb8c91032b278e08a69c9f
103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""
|
|
Example Create a jenkins server
|
|
|
|
Create all the pieces parts to get a jenkins server up and running.
|
|
|
|
To run:
|
|
python examples/jenkins.py
|
|
"""
|
|
|
|
import base64
|
|
import sys
|
|
|
|
from examples import common
|
|
from examples import connection
|
|
from examples import network
|
|
|
|
|
|
def create_jenkins(conn, name, opts):
|
|
flavor = opts.data.pop('flavor', '103')
|
|
image = opts.data.pop('image', 'bec3cab5-4722-40b9-a78a-3489218e22fe')
|
|
|
|
ports = [9022, 443, 80, 8080, 422, 22]
|
|
net = network.create(conn, name, opts, ports_to_open=ports)
|
|
|
|
server = conn.compute.find_server(name)
|
|
if server is None:
|
|
f = open('examples/cloud-init.sh', 'r')
|
|
cmd = f.read()
|
|
f.close()
|
|
b64str = base64.b64encode(cmd)
|
|
args = {
|
|
"name": name,
|
|
"flavorRef": flavor,
|
|
"imageRef": image,
|
|
"imageRef": image,
|
|
"key_name": name,
|
|
"networks": [{"uuid": net.id}],
|
|
"user_data": b64str,
|
|
}
|
|
server = conn.compute.create_server(**args)
|
|
else:
|
|
server = conn.get(server)
|
|
print(str(server))
|
|
print('Waiting for the server to come up....')
|
|
conn.compute.wait_for_status(server)
|
|
print('Server is up.')
|
|
|
|
if len(server.get_floating_ips()) <= 0:
|
|
extnet = conn.network.find_network("Ext-Net")
|
|
ip = conn.network.find_available_ip()
|
|
if ip is None:
|
|
ip = conn.network.create_ip(floating_network_id=extnet.id)
|
|
port = next(conn.network.list_ports(device_id=server.id, fields='id'))
|
|
conn.network.add_ip_to_port(port, ip)
|
|
print(str(port))
|
|
ip = conn.get(ip)
|
|
print("ssh -i jenkins ubuntu@%s" % ip.floating_ip_address)
|
|
print("http://%s:8080" % ip.floating_ip_address)
|
|
|
|
return
|
|
|
|
|
|
def delete_jenkins(conn, name, opts):
|
|
server = conn.compute.find_server(name)
|
|
if server is not None:
|
|
server = conn.get(server)
|
|
print(str(server))
|
|
ips = server.get_floating_ips()
|
|
for ip in ips:
|
|
print(str(ip))
|
|
ip = conn.network.find_ip(ip)
|
|
conn.network.remove_ip_from_port(ip)
|
|
conn.delete(ip)
|
|
conn.delete(server)
|
|
|
|
network.delete(conn, name)
|
|
|
|
|
|
def run_jenkins(opts):
|
|
argument = opts.argument
|
|
conn = connection.make_connection(opts)
|
|
name = opts.data.pop('name', 'jenkins')
|
|
if argument == "delete":
|
|
return(delete_jenkins(conn, name, opts))
|
|
return(create_jenkins(conn, name, opts))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
opts = common.setup()
|
|
sys.exit(common.main(opts, run_jenkins))
|