system-config/launch/utils.py
Clark Boylan 9da01bfbeb Change launch scripts to python3 shebangs
As part of our audit to find out what needs to be ported from python2 to
python3 I've discovered that launch-node is already all python3 (because
it runs on bridge) but the shebangs still pointed to `python`. Update
them to reduce confusion while we do the audit and potentially
uplift/port things.

Change-Id: I9a4c9397a1bc9a8b39c60b92ce58c77c0cb3f7f0
2020-06-08 16:05:11 -07:00

55 lines
1.6 KiB
Python

#!/usr/bin/env python3
# Update the base image that is used for devstack VMs.
# Copyright (C) 2011-2012 OpenStack LLC.
#
# 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 time
import socket
import paramiko
from sshclient import SSHClient
def iterate_timeout(max_seconds, purpose):
start = time.time()
count = 0
while (time.time() < start + max_seconds):
count += 1
yield count
time.sleep(2)
raise Exception("Timeout waiting for %s" % purpose)
def ssh_connect(ip, username, connect_kwargs={}, timeout=60):
# HPcloud may return errno 111 for about 30 seconds after adding the IP
for count in iterate_timeout(timeout, "ssh access"):
try:
client = SSHClient(ip, username, **connect_kwargs)
break
except socket.error as e:
print("While testing ssh access:", e)
time.sleep(5)
except paramiko.ssh_exception.AuthenticationException:
return None
ret, out = client.ssh("echo access okay")
if "access okay" in out:
return client
return None