Print DNS commands when launching a node.

Still not automatic, but much less typing.

Change-Id: I348b866db3f2778ba08a516a00d258358c4a9129
Reviewed-on: https://review.openstack.org/22468
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Approved: Clark Boylan <clark.boylan@gmail.com>
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Tested-by: Jenkins
This commit is contained in:
James E. Blair 2013-01-16 19:11:44 +00:00 committed by Jenkins
parent 300826e6ad
commit 8b04d362b5
4 changed files with 106 additions and 29 deletions

View File

@ -46,29 +46,13 @@ above.
Add DNS Records
===============
There are no scripts to handle DNS at the moment due to a lack of
library support for the new Rackspace Cloud DNS (with IPv6). To
manually update DNS, you will need the hostname, v4 and v6 addresses
of the host, as well as the UUID (these can all be found by running
the ''nova list'' command). The environment variables used in the
URL should be satisfied by sourcing the "openstackci-rs-nova.sh"
script (or jenkins, as appropriate). Also the above launch script
should output some environment variable assignments for UUID, IPV4
and IPV6 you can cut and paste as needed, or you can fill them in
yourself::
There are no scripts to automatically handle DNS at the moment due to
a lack of library support for the new Rackspace Cloud DNS (with IPv6).
However, the launch-node script will print the commands needed to be
run to configure DNS for a newly launched server. To see the commands
for an existing server, run:
. ~root/rackdns-venv/bin/activate
UUID=01234567-89ab-cdef-fedc-ba9876543210
IPV4=123.45.67.89
IPV6=fedc:ba98:7654:3210:dead:beef:cafe:feed
rackdns rdns-create --name $FQDN --data "$IPV6" --server-href https://$os_region_name.servers.api.rackspacecloud.com/v2/$OS_TENANT_NAME/servers/"$UUID" --ttl 300
rackdns rdns-create --name $FQDN --data "$IPV4" --server-href https://$os_region_name.servers.api.rackspacecloud.com/v2/$OS_TENANT_NAME/servers/"$UUID" --ttl 300
. ~root/ci-launch/openstack-rs-nova.sh
rackdns record-create --name $FQDN --type AAAA --data "$IPV6" --ttl 300 openstack.org
rackdns record-create --name $FQDN --type A --data "$IPV4" --ttl 300 openstack.org
./dns.py $FQDN
Activate Puppet Agent
=====================

93
launch/dns.py Executable file
View File

@ -0,0 +1,93 @@
#!/usr/bin/env python
# Launch a new OpenStack project infrastructure node.
# Copyright (C) 2013 OpenStack Foundation
#
# 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.
import sys
import os
import commands
import time
import subprocess
import traceback
import socket
import argparse
import utils
NOVA_USERNAME=os.environ['OS_USERNAME']
NOVA_PASSWORD=os.environ['OS_PASSWORD']
NOVA_URL=os.environ['OS_AUTH_URL']
NOVA_PROJECT_ID=os.environ['OS_TENANT_NAME']
NOVA_REGION_NAME=os.environ['OS_REGION_NAME']
SCRIPT_DIR = os.path.dirname(sys.argv[0])
def get_client():
args = [NOVA_USERNAME, NOVA_PASSWORD, NOVA_PROJECT_ID, NOVA_URL]
kwargs = {}
kwargs['region_name'] = NOVA_REGION_NAME
kwargs['service_type'] = 'compute'
from novaclient.v1_1.client import Client
client = Client(*args, **kwargs)
return client
def print_dns(client, name):
for server in client.servers.list():
if server.name != name: continue
ip4 = utils.get_public_ip(server)
ip6 = utils.get_public_ip(server, 6)
href = utils.get_href(server)
print
print "Run the following commands to set up DNS:"
print
print ". ~root/rackdns-venv/bin/activate"
print
print ("rackdns rdns-create --name %s \\\n"
" --data %s \\\n"
" --server-href %s \\\n"
" --ttl 3600" % (
server.name, ip6, href))
print
print ("rackdns rdns-create --name %s \\\n"
" --data %s \\\n"
" --server-href %s \\\n"
" --ttl 3600" % (
server.name, ip4, href))
print
print ". ~root/ci-launch/openstack-rs-nova.sh"
print
print ("rackdns record-create --name %s \\\n"
" --type AAAA --data %s \\\n"
" --ttl 3600 openstack.org" % (
server.name, ip6))
print
print ("rackdns record-create --name %s \\\n"
" --type A --data %s \\\n"
" --ttl 3600 openstack.org" % (
server.name, ip4))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("name", help="server name")
options = parser.parse_args()
client = get_client()
print_dns(client, options.name)
if __name__ == '__main__':
main()

View File

@ -27,6 +27,7 @@ import traceback
import socket
import argparse
import utils
import dns
NOVA_USERNAME=os.environ['OS_USERNAME']
NOVA_PASSWORD=os.environ['OS_PASSWORD']
@ -142,7 +143,6 @@ def build_server(client, name, image, flavor, cert, environment):
# Raise the important exception that started this
raise
def main():
parser = argparse.ArgumentParser()
parser.add_argument("name", help="server name")
@ -196,6 +196,7 @@ def main():
print "Found image", image
build_server(client, options.name, image, flavor, cert, options.environment)
dns.print_dns(client, options.name)
if __name__ == '__main__':
main()

View File

@ -84,14 +84,9 @@ def get_flavor(client, min_ram):
def get_public_ip(server, version=4):
if 'os-floating-ips' in get_extensions(server.manager.api):
print 'using floating ips'
for addr in server.manager.api.floating_ips.list():
print 'checking addr', addr
if addr.instance_id == server.id:
print 'found addr', addr
return addr.ip
print 'no floating ip, addresses:'
print server.addresses
for addr in server.addresses.get('public', []):
if type(addr) == type(u''): # Rackspace/openstack 1.0
return addr
@ -102,9 +97,13 @@ def get_public_ip(server, version=4):
return addr['addr']
return None
def get_href(server):
for link in server.links:
if link['rel'] == 'self':
return link['href']
def add_public_ip(server):
ip = server.manager.api.floating_ips.create()
print "created floating ip", ip
server.add_floating_ip(ip)
for count in iterate_timeout(600, "ip to be added"):
try: