Monty Taylor e14471dcc6 Update for ansible and puppet apply
Shade supports all of the TODO items in here now, so use it. Also,
we have ansible playbooks that do the work of running puppet - and since
we're on puppet apply now, we can use them.

Change-Id: I6f57e9a31bf835ef2e22db1f5531d92e99806cf4
2016-03-09 14:23:54 -06:00

145 lines
4.1 KiB
Python
Executable File

#!/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 os
import argparse
import utils
def get_client():
#TODO use shade
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']
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 get_href(server):
if not hasattr(server, 'links'):
return None
for link in server.links:
if link['rel'] == 'self':
return link['href']
def shade_print_dns(cloud, server):
ip4 = server.public_v4
ip6 = server.public_v6
for raw_server in cloud.nova_client.servers.list():
if raw_server.id == server.id:
href = get_href(raw_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()