1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 03:08:14 +00:00

Syntax cleanup

This commit is contained in:
Jerry Seutter 2014-06-26 14:35:19 +00:00
parent 868935f5e8
commit ff0201bb4f

View File

@ -12,7 +12,7 @@ from novaclient.v1_1 import client
from string import Template from string import Template
from time import sleep from time import sleep
POLL_SEC = 30 POLL_SEC = 20
GNS3_REPO = 'gns3/gns3-server' GNS3_REPO = 'gns3/gns3-server'
PLANC_REPO = 'planctechnologies/gns3-server' PLANC_REPO = 'planctechnologies/gns3-server'
OS_AUTH_URL = 'https://identity.api.rackspacecloud.com/v2.0/' OS_AUTH_URL = 'https://identity.api.rackspacecloud.com/v2.0/'
@ -25,10 +25,9 @@ def main():
Creates a new instance, installs the required software, creates an image Creates a new instance, installs the required software, creates an image
from the instance, and then deletes the instance. from the instance, and then deletes the instance.
""" """
g = Github() github = Github()
args = get_cli_args() args = get_cli_args()
if args.username: if args.username:
@ -65,17 +64,16 @@ def main():
if args.source == 'release': if args.source == 'release':
# get the list of releases, present them to the user, save the url # get the list of releases, present them to the user, save the url
repo = g.get_repo('gns3/gns3-server') repo = github.get_repo(GNS3_REPO)
keyword = "tag" keyword = "tag"
i = 1 i = 1
branch_opts = {} branch_opts = {}
for tag in repo.get_tags(): for tag in repo.get_tags():
branch_opts[i] = tag.name branch_opts[i] = tag.name
i += 1 i += 1
elif args.source == 'dev': elif args.source == 'dev':
# get the list of dev branches, present them to the user, save the url # get the list of dev branches, present them to the user, save the url
repo = g.get_repo('planctechnologies/gns3-server') repo = github.get_repo(PLANC_REPO)
keyword = "branch" keyword = "branch"
i = 1 i = 1
branch_opts = {} branch_opts = {}
@ -104,7 +102,7 @@ def main():
passwd = uuid.uuid4().hex passwd = uuid.uuid4().hex
instance.change_password(passwd) instance.change_password(passwd)
# wait for the password change to be processed # wait for the password change to be processed
sleep(10) sleep(POLL_SEC)
env.host_string = str(instance.accessIPv4) env.host_string = str(instance.accessIPv4)
env.user = "root" env.user = "root"
@ -113,11 +111,11 @@ def main():
sys.stdout.write("Installing software...") sys.stdout.write("Installing software...")
sys.stdout.flush() sys.stdout.flush()
while 1: while True:
if exists('/tmp/gns-install-complete'): if exists('/tmp/gns-install-complete'):
break break
sleep(20) sleep(POLL_SEC)
sys.stdout.write(".") sys.stdout.write(".")
sys.stdout.flush() sys.stdout.flush()
@ -136,7 +134,7 @@ def prompt_user_select(opts, text="Please select"):
for o in opts: for o in opts:
print("(%s)\t%s" % (o, opts[o])) print("(%s)\t%s" % (o, opts[o]))
while 1: while True:
selected = raw_input("Select: ") selected = raw_input("Select: ")
try: try:
return opts[int(selected)] return opts[int(selected)]
@ -155,18 +153,17 @@ def create_instance(username, password, tenant, region, server_name, script,
region_name=region) region_name=region)
server = nc.servers.create(server_name, UBUNTU_BASE_ID, 2, server = nc.servers.create(server_name, UBUNTU_BASE_ID, 2,
config_drive=True, userdata=script) config_drive=True, userdata=script)
server_id = server.id
while 1: while True:
server = nc.servers.get(server_id) server = nc.servers.get(server.id)
if server.status == 'ACTIVE': if server.status == 'ACTIVE':
break break
sleep(20) sleep(POLL_SEC)
sys.stdout.write(".") sys.stdout.write(".")
sys.stdout.flush() sys.stdout.flush()
print "Done." print("Done.")
return server return server
@ -196,12 +193,12 @@ def create_image(username, password, tenant, region, server,
image_id = server.create_image(image_name) image_id = server.create_image(image_name)
while 1: while True:
server = nc.servers.get(server.id) server = nc.servers.get(server.id)
if getattr(server, 'OS-EXT-STS:task_state') is None: if getattr(server, 'OS-EXT-STS:task_state') is None:
break break
sleep(20) sleep(POLL_SEC)
sys.stdout.write(".") sys.stdout.write(".")
sys.stdout.flush() sys.stdout.flush()
@ -215,29 +212,27 @@ def get_cli_args():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Create a new GNS3 image', description='Create a new GNS3 image',
formatter_class=argparse.ArgumentDefaultsHelpFormatter formatter_class=argparse.ArgumentDefaultsHelpFormatter)
)
parser.add_argument( parser.add_argument(
'--rackspace_username', dest='username', action='store' '--rackspace_username', dest='username', action='store')
)
parser.add_argument( parser.add_argument(
'--rackspace_password', dest='password', action='store' '--rackspace_password', dest='password', action='store')
)
parser.add_argument( parser.add_argument(
'--rackspace_tenant', dest='tenant', action='store' '--rackspace_tenant', dest='tenant', action='store')
)
parser.add_argument( parser.add_argument(
'--rackspace_region', dest='region', action='store' '--rackspace_region', dest='region', action='store')
) parser.add_argument(
parser.add_argument('--source', dest='source', action='store', '--source', dest='source', action='store', choices=['release', 'dev'],
choices=['release', 'dev'], default='release', default='release', help='specify the gns3-server source location')
help='specify the gns3-server source location') parser.add_argument(
parser.add_argument('--branch', dest='branch', action='store', '--branch', dest='branch', action='store',
help='specify the branch/tag') help='specify the branch/tag')
parser.add_argument('--start-on-boot', dest='on_boot', action='store_true', parser.add_argument(
help='start the GNS3-server when the image boots', '--start-on-boot', dest='on_boot', action='store_true',
default=False) default=False, help='start the GNS3-server when the image boots')
parser.add_argument('--image-name', dest='image_name', action='store', parser.add_argument(
'--image-name', dest='image_name', action='store',
help='the name of the image to be created') help='the name of the image to be created')
return parser.parse_args() return parser.parse_args()