예제 #1
0
def build_server(
        client, name, image, flavor, cert, environment, puppetmaster, volume,
        keep, net_label, floating_ip_pool):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    if net_label:
        nics = []
        for net in client.networks.list():
            if net.label == net_label:
                nics.append({'net-id': net.id})
        create_kwargs['nics'] = nics

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception:
        try:
            kp.delete()
        except Exception:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
        raise

    try:
        admin_pass = server.adminPass
        server = utils.wait_for_resource(server)
        if volume:
            vobj = client.volumes.create_server_volume(
                server.id, volume, None)
            if not vobj:
                raise Exception("Couldn't attach volume")

        bootstrap_server(server, admin_pass, key, cert, environment, name,
                         puppetmaster, volume, floating_ip_pool)
        print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
                                               server.accessIPv4,
                                               server.accessIPv6))
        if key:
            kp.delete()
    except Exception:
        try:
            if keep:
                print "Server failed to build, keeping as requested."
            else:
                utils.delete_server(server)
        except Exception:
            print "Exception encountered deleting server:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise
예제 #2
0
def build_server(
        client, name, image, flavor, cert, environment, puppetmaster, volume,
        keep, net_label, floating_ip_pool):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    if net_label:
        nics = []
        for net in client.networks.list():
            if net.label == net_label:
                nics.append({'net-id': net.id})
        create_kwargs['nics'] = nics

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception:
        try:
            kp.delete()
        except Exception:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
        raise

    try:
        admin_pass = server.adminPass
        server = utils.wait_for_resource(server)
        if volume:
            vobj = client.volumes.create_server_volume(
                server.id, volume, None)
            if not vobj:
                raise Exception("Couldn't attach volume")

        bootstrap_server(server, admin_pass, key, cert, environment, name,
                         puppetmaster, volume, floating_ip_pool)
        print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
                                               server.accessIPv4,
                                               server.accessIPv6))
        if key:
            kp.delete()
    except Exception:
        try:
            if keep:
                print "Server failed to build, keeping as requested."
            else:
                utils.delete_server(server)
        except Exception:
            print "Exception encountered deleting server:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise
예제 #3
0
def build_server(
        client, name, image, flavor, cert, environment, puppetmaster, volume,
        keep):
    key = None
    server = None

    # BH: HARDCODE
    nics = [{'net-id': u'b25625cc-2f6b-48c2-b740-08e2b0503a19'}]
    create_kwargs = dict(image=image, flavor=flavor, name=name, nics=nics)

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception:
        try:
            kp.delete()
        except Exception:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
        raise

    try:
        admin_pass = server.adminPass
        server = utils.wait_for_resource(server)
        if volume:
            vobj = client.volumes.create_server_volume(
                server.id, volume, None)
            if not vobj:
                raise Exception("Couldn't attach volume")

        bootstrap_server(server, admin_pass, key, cert, environment, name,
                         puppetmaster, volume)
        print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
                                               server.accessIPv4,
                                               server.accessIPv6))
        if key:
            kp.delete()
    except Exception:
        try:
            if keep:
                print "Server failed to build, keeping as requested."
            else:
                utils.delete_server(server)
        except Exception:
            print "Exception encountered deleting server:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise
def build_image(provider, client, base_image, image, flavor, name, branches,
                timestamp):
    print "Building image %s" % name

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key = None
    key_name = '%sdevstack-%i' % (DEVSTACK_GATE_PREFIX, time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name

    server = client.servers.create(**create_kwargs)
    snap_image = base_image.newSnapshotImage(name=name,
                                             version=timestamp,
                                             external_id=None,
                                             server_external_id=server.id)
    admin_pass = server.adminPass
    try:
        print "Waiting for server ID %s" % server.id
        server = utils.wait_for_resource(server)
        bootstrap_server(provider, server, admin_pass, key)
        configure_server(server, branches)
        remote_snap_image = snapshot_server(client, server, name)
        snap_image.external_id = remote_snap_image.id
        snap_image.state = vmdatabase.READY
        # We made the snapshot, try deleting the server, but it's okay
        # if we fail.  The reap script will find it and try again.
        try:
            utils.delete_server(server)
        except:
            print "Exception encountered deleting server:"
            traceback.print_exc()
    except Exception:
        # Something went wrong, try our best to mark the server in error
        # then delete the server, then delete the db record for it.
        # If any of this fails, the reap script should catch it.  But
        # having correct info in the DB will help it do its job faster.
        try:
            snap_image.state = vmdatabase.ERROR
            try:
                utils.delete_server(server)
                snap_image.delete()
            except Exception:
                print "Exception encountered deleting server:"
                traceback.print_exc()
        except Exception:
            print "Exception encountered marking server in error:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise
def build_image(provider, client, base_image, image,
                flavor, name, branches, timestamp):
    print "Building image %s" % name

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key = None
    key_name = '%sdevstack-%i' % (DEVSTACK_GATE_PREFIX, time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name

    server = client.servers.create(**create_kwargs)
    snap_image = base_image.newSnapshotImage(name=name,
                                             version=timestamp,
                                             external_id=None,
                                             server_external_id=server.id)
    admin_pass = server.adminPass
    try:
        print "Waiting for server ID %s" % server.id
        server = utils.wait_for_resource(server)
        bootstrap_server(provider, server, admin_pass, key)
        configure_server(server, branches)
        remote_snap_image = snapshot_server(client, server, name)
        snap_image.external_id = remote_snap_image.id
        snap_image.state = vmdatabase.READY
        # We made the snapshot, try deleting the server, but it's okay
        # if we fail.  The reap script will find it and try again.
        try:
            pass  # XXX
            # utils.delete_server(server)
        except:
            print "Exception encountered deleting server:"
            traceback.print_exc()
    except Exception, real_error:
        # Something went wrong, try our best to mark the server in error
        # then delete the server, then delete the db record for it.
        # If any of this fails, the reap script should catch it.  But
        # having correct info in the DB will help it do its job faster.
        try:
            snap_image.state = vmdatabase.ERROR
            try:
                utils.delete_server(server)
                snap_image.delete()
            except Exception, delete_error:
                print "Exception encountered deleting server:"
                traceback.print_exc()
        except Execption, database_error:
            print "Exception encountered marking server in error:"
            traceback.print_exc()
예제 #6
0
def build_server(
        client, name, image, flavor, cert, environment, salt, puppetmaster):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception:
        try:
            kp.delete()
        except Exception:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
        raise

    salt_priv, salt_pub = (None, None)
    if salt:
        salt_priv, salt_pub = utils.add_salt_keypair(
            SALT_MASTER_PKI, name, 2048)
    try:
        admin_pass = server.adminPass
        server = utils.wait_for_resource(server)
        bootstrap_server(server, admin_pass, key, cert, environment, name,
                         salt_priv, salt_pub, puppetmaster)
        print('UUID=%s\nIPV4=%s\nIPV6=%s\n' % (server.id,
                                               server.accessIPv4,
                                               server.accessIPv6))
        if key:
            kp.delete()
    except Exception:
        try:
            utils.delete_server(server)
        except Exception:
            print "Exception encountered deleting server:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise
예제 #7
0
파일: launch-node.py 프로젝트: kiall/config
def build_server(client, name, image, flavor, cert, environment):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception, real_error:
        try:
            kp.delete()
        except Exception, delete_error:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
예제 #8
0
파일: launch-node.py 프로젝트: ody/config
def build_server(client, name, image, flavor, cert, environment):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception, real_error:
        try:
            kp.delete()
        except Exception, delete_error:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
예제 #9
0
def build_server(client, name, image, flavor, cert, environment, salt,
                 puppetmaster):
    key = None
    server = None

    create_kwargs = dict(image=image, flavor=flavor, name=name)

    key_name = 'launch-%i' % (time.time())
    if 'os-keypairs' in utils.get_extensions(client):
        print "Adding keypair"
        key, kp = utils.add_keypair(client, key_name)
        create_kwargs['key_name'] = key_name
    try:
        server = client.servers.create(**create_kwargs)
    except Exception:
        try:
            kp.delete()
        except Exception:
            print "Exception encountered deleting keypair:"
            traceback.print_exc()
        raise

    salt_priv, salt_pub = (None, None)
    if salt:
        salt_priv, salt_pub = utils.add_salt_keypair(SALT_MASTER_PKI, name,
                                                     2048)
    try:
        admin_pass = server.adminPass
        server = utils.wait_for_resource(server)
        bootstrap_server(server, admin_pass, key, cert, environment, name,
                         salt_priv, salt_pub, puppetmaster)
        print('UUID=%s\nIPV4=%s\nIPV6=%s\n' %
              (server.id, server.accessIPv4, server.accessIPv6))
        if key:
            kp.delete()
    except Exception:
        try:
            utils.delete_server(server)
        except Exception:
            print "Exception encountered deleting server:"
            traceback.print_exc()
        # Raise the important exception that started this
        raise