David Moreau Simard 213975b930
Update launch-node's dns.py to work with openstacksdk
Shade no longer uses novaclient. shade also strips links dicts from the
resources it returns. shade also now depends on openstacksdk, which does
not strip links dicts.

Change-Id: Ifb6a8280e548cb55932cae4a2bba8e1fa5b34c3c
2018-03-23 13:01:40 -05:00

90 lines
2.5 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 argparse
def get_href(server):
if not hasattr(server, 'links'):
return None
for link in server.links:
if link['rel'] == 'self':
return link['href']
def print_dns(cloud, server):
ip4 = server.public_v4
ip6 = server.public_v6
# Get the server object from the sdk layer so that we can pull the
# href data out of the links dict.
raw_server = cloud.compute.get_server(server.id)
href = get_href(raw_server)
print
print "Run the following commands to set up DNS:"
print
print ". ~root/ci-launch/openstackci-rs-nova.sh"
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()
import openstack
cloud = openstack.connect()
# Get the server using the shade layer so that we have server.public_v4
# and server.public_v6
server = cloud.get_server(options.name)
print_dns(cloud, server)
if __name__ == '__main__':
main()