Ejemplo n.º 1
0
def start_server(auth_parms, server_data):
    """Function to start server, uuid in server_data"""
    server_uuid = server_data[0]
    server_state = get_server_state(auth_parms, server_uuid)
    if server_state == 'STOPPED':
        rc = change_server_status(auth_parms=auth_parms, server_uuid=server_uuid, state='RUNNING')
        # change_server_status() waits on the server getting to the requested state, so we don't
        # need to call wait_for_server() here. However, we do (1) need to check the status and (2)
        # wait on the server actually being accessible (as opposed to having a RUNNING state in
        # FCO, which really just means that the underlying kvm process has started).
        #
        # 1. Check rc (0 is good)
        if (rc != 0):
            raise Exception("Failed to put server " + server_uuid + " in to running state")

    server_resultset = list_resource_by_uuid(auth_parms, uuid=server_uuid, res_type='SERVER')
    print("Server result set is:")
    print server_resultset

    server_ip = server_resultset['list'][0]['nics'][0]['ipAddresses'][0]['ipAddress']  # yuk
    print("server IP=" + server_ip)

    # Step 2. Wait on it being accessible. It is possible that the server doesn't have ssh installed,
    # or it is firewalled, so don't fail here if we can't connect, just carry on and let
    # the caller deal with any potential issue. The alternative is a hard-coded sleep, or
    # trying a ping (platform specific and/or root privs needed).
    is_ssh_port_open(server_ip, 30)

    server_data.append(server_ip)
    return server_data
Ejemplo n.º 2
0
def start_server(auth_parms, server_uuid):
    """Function to start server, uuid in server_data"""
    server_state = get_server_state(auth_parms, server_uuid)
    if server_state == 'STOPPED':
        rc = change_server_status(auth_parms=auth_parms, server_uuid=server_uuid, state='RUNNING')
        if (rc != 0):
            raise Exception("Failed to put server " + server_uuid + " in to running state")

    server_resultset = list_resource_by_uuid(auth_parms, uuid=server_uuid, res_type='SERVER')
    server_ip = server_resultset['list'][0]['nics'][0]['ipAddresses'][0]['ipAddress']
    is_ssh_port_open(server_ip, 30)
Ejemplo n.º 3
0
def wait_for_vm_deletion(auth_client, serverUUID, state):
    result = change_server_status(auth_client, serverUUID, state)
    if (result != 0):
        print "Could not delete the VM"
    else:
        print "The VM is deleting ..."
        count = 0
        # Maximum amount of time we would wait - 2 minutes. Check every 30 seconds
        if (count < 4):
            # 30 seconds should be enough for the VM to be destroyed
            time.sleep(WAIT_TIME)
            server = list_resource_by_uuid(auth_client, serverUUID, "SERVER")
            if(server['totalCount'] == 0):
                print "======================================================"
                print "The VM has been deleted"
                return
            count = count + 1
Ejemplo n.º 4
0
def build_server(auth_parms, customer_uuid, image_uuid, vdc_uuid, server_po_uuid, boot_disk_po_uuid,
                server_name, ram_amount, cpu_count, networkType, cluster_uuid, public_key, context_script):
   
    create_server_job = rest_create_server(auth_parms, server_name, server_po_uuid, image_uuid,
                                             cluster_uuid, vdc_uuid, cpu_count,
                                             ram_amount, boot_disk_po_uuid, context_script)

    server_uuid = create_server_job['itemUUID']
    print "--- createServer done with UUID " + server_uuid + " -----"
    
    # The public_key arg might be a list of public keys, separated by cr/lf. So split
    # the list and process each key individually
    for single_key in public_key.splitlines():
        print("Processing key: " + single_key)
        add_ret = AddKey(auth_parms, server_uuid, customer_uuid, single_key)
        print("== AddKey Result ==")
        print add_ret
        print("====")

    wait_for_install(auth_parms, server_uuid=server_uuid)

    # Add NIC to server
    print "Calling create_nic for network " + networkType
    nic_uuid = create_nic(auth_parms=auth_parms, nic_count='0', network_type=networkType,
                          cluster_uuid=cluster_uuid, vdc_uuid=vdc_uuid)
    print "create_nic returned nic_uuid: " + nic_uuid
    wait_for_resource(auth_parms=auth_parms, res_uuid=nic_uuid, state='ACTIVE', res_type='nic')
    print "nic uuid: " + nic_uuid

    add_nic_response = add_nic_to_server(auth_parms=auth_parms, server_uuid=server_uuid, nic_uuid=nic_uuid, index='1')

    # Wait on the addNic job completing
    status = wait_for_job(auth_parms, add_nic_response['resourceUUID'], "SUCCESSFUL", 90)
    if (status != 0):
        raise Exception("Failed to add NIC to server")

    # Lookup server properties to get UUID, and password, that have been assigned to it
    server_resultset = list_resource_by_uuid(auth_parms, uuid=server_uuid, res_type='SERVER')
    server = server_resultset['list'][0]
    server_uuid = server['resourceUUID']
    server_pw = server['initialPassword']
    server_user = server['initialUser']
    server_data = [server_uuid, server_pw, server_user]
    return server_data