Add support to launch node for attaching volumes
We are using cinder block devices more and more. Update launch node so that it can attach a preexisting cinder volume against a new nova server on first boot. This will allow puppet or other config management to format and mount that block device into the VMs filesystem. Change-Id: Ic121cdc06dcbea0e38e8d0ff8946e999af3d727e
This commit is contained in:
parent
71111e603b
commit
f490260de7
@ -52,8 +52,8 @@ def get_client():
|
||||
return client
|
||||
|
||||
|
||||
def bootstrap_server(
|
||||
server, admin_pass, key, cert, environment, name, puppetmaster):
|
||||
def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
||||
puppetmaster, volume):
|
||||
ip = utils.get_public_ip(server)
|
||||
if not ip:
|
||||
raise Exception("Unable to find public ip of server")
|
||||
@ -88,6 +88,11 @@ def bootstrap_server(
|
||||
'make_swap.sh')
|
||||
ssh_client.ssh('bash -x make_swap.sh')
|
||||
|
||||
if volume:
|
||||
ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'mount_volume.sh'),
|
||||
'mount_volume.sh')
|
||||
ssh_client.ssh('bash -x mount_volume.sh')
|
||||
|
||||
ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'),
|
||||
'install_puppet.sh')
|
||||
ssh_client.ssh('bash -x install_puppet.sh')
|
||||
@ -124,7 +129,7 @@ def bootstrap_server(
|
||||
|
||||
|
||||
def build_server(
|
||||
client, name, image, flavor, cert, environment, puppetmaster):
|
||||
client, name, image, flavor, cert, environment, puppetmaster, volume):
|
||||
key = None
|
||||
server = None
|
||||
|
||||
@ -148,8 +153,14 @@ def build_server(
|
||||
try:
|
||||
admin_pass = server.adminPass
|
||||
server = utils.wait_for_resource(server)
|
||||
if volume:
|
||||
vobj = client.volumes.create_server_volume(
|
||||
server.id, volume, None)
|
||||
if not vobj:
|
||||
raise Exception("Couldn't attach volume")
|
||||
|
||||
bootstrap_server(server, admin_pass, key, cert, environment, name,
|
||||
puppetmaster)
|
||||
puppetmaster, volume)
|
||||
print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
|
||||
server.accessIPv4,
|
||||
server.accessIPv6))
|
||||
@ -181,6 +192,9 @@ def main():
|
||||
"hostname.example.com.pem)")
|
||||
parser.add_argument("--server", dest="server", help="Puppetmaster to use.",
|
||||
default="ci-puppetmaster.openstack.org")
|
||||
parser.add_argument("--volume", dest="volume",
|
||||
help="UUID of volume to attach to the new server.",
|
||||
default=None)
|
||||
options = parser.parse_args()
|
||||
|
||||
client = get_client()
|
||||
@ -220,7 +234,7 @@ def main():
|
||||
print "Found image", image
|
||||
|
||||
build_server(client, options.name, image, flavor, cert,
|
||||
options.environment, options.server)
|
||||
options.environment, options.server, options.volume)
|
||||
dns.print_dns(client, options.name)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
36
mount_volume.sh
Normal file
36
mount_volume.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Sigh. nova volume-attach is not immediate, but there is no status to track
|
||||
sleep 120
|
||||
|
||||
if [ -b /dev/vdc ]; then
|
||||
DEV='/dev/vdc'
|
||||
elif [ -b /dev/xvdb ]; then
|
||||
DEV='/dev/xvdb'
|
||||
else
|
||||
echo "Could not mount volume"
|
||||
exit 1
|
||||
fi
|
||||
if ! blkid | grep $DEV | grep ext4 ; then
|
||||
mkfs.ext4 ${DEV}
|
||||
fi
|
||||
perl -nle "m,${DEV}, || print" -i /etc/fstab
|
||||
if [ ! -d /srv ] ; then
|
||||
mkdir -p /srv
|
||||
fi
|
||||
echo "${DEV} /srv ext4 errors=remount-ro,barrier=0 0 2" >> /etc/fstab
|
||||
mount -a
|
Loading…
Reference in New Issue
Block a user