--- mcore-src/trunk/mcore-tools/src/include/register.global.class.in 2015/09/03 13:30:46 2443 +++ mcore-src/trunk/mcore-tools/src/include/register.global.class.in 2016/02/17 10:49:12 2787 @@ -6,7 +6,11 @@ local ip_address="$2" local serial local mtime - local cmd + local serial_id + local os + local tools + local netboot + local location if [[ -z ${mac_address} ]] then @@ -21,14 +25,16 @@ fi decho "registering mac_address='${mac_address}'" + decho "registering ip_address='${ip_address}'" # first check if mac is registered serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") + # current mtime + mtime=$(date +%s) + if [[ -z ${serial} ]] then - mtime=$(date +%s) - # request a new serial; one command now (cause must be done in the same session) serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") fi @@ -40,11 +46,59 @@ decho "serial='${serial}'" rvecho "${serial}" - cmd+="quiet" - cmd+="register '${serial}'" - SSLSAY_IP="${IP}" + SSLSAY_IP="${ip_address}" SSLSAY_PORT="6666" - nsslsay_fingerprint ${cmd} + nsslsay_fingerprint "register '${serial}'" + + # register the client as online + serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") + if [[ -n ${serial_id} ]] + then + mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}' where serial=${serial};" + else + mysqldo "insert into state_connected(serial,ip,mac,mtime) values('${serial}','${ip_address}','${mac_address}','${mtime}');" + fi + + # get netboot state + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.netboot" + netboot=$(control_client "${serial}" run-queue) + # update netboot state + serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") + if [[ -n ${serial_id} ]] + then + mysqldo "update state_connected set netboot='${netboot}' where serial=${serial};" + fi + + # get location from cmdline and update the client_serials.location entry + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get system.cmdline MCORE_LOCATION=" + location=$(control_client "${serial}" run-queue) + # update location + if [[ -n ${location} ]] + then + mysqldo "update client_serials set location='${location}' where serial=${serial};" + fi + + # update tools and os version info + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.os" + os=$(control_client "${serial}" run-queue) + import_resource client_version "${serial}" os "${os}" + nsslsay_queue_init + nsslsay_queue_add "nocolors" + nsslsay_queue_add "get version.tools" + tools=$(control_client "${serial}" run-queue) + import_resource client_version "${serial}" utils "${tools}" + + # run hardware detection + if is_provided hardware + then + run_hardware_detect "${serial}" + fi return 0 fi @@ -52,27 +106,51 @@ register_client() { + local control_server local control_server_ip local iface_ip local iface local mac_address - local cmd - control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) + control_server=$(mcore-controlserver) + if [[ $? != 0 ]] + then + decho "Could not communicate with the controlserver" + return 1 + fi + + control_server_ip=$(dns_to_ip ${control_server}) + if [[ -z ${control_server_ip} ]] + then + decho "Could not resolve control server ip, dns_to_ip(${control_server}) failed" + return 1 + fi iface_ip=$(iface_for_remote_addr ${control_server_ip}) + if [[ -z ${iface_ip} ]] + then + decho "Could not resolve interface ip, iface_ip(${control_server_ip}) failed" + return 1 + fi iface=$(iface_for_ip ${iface_ip}) + if [[ -z ${iface} ]] + then + decho "Could not resolve interface for referencing ip address, iface_for_ip(${iface_ip}) failed" + return 1 + fi mac_address=$(mac_for_iface ${iface}) + if [[ -z ${mac_address} ]] + then + decho "Could not resolve mac address, mac_for_iface(${iface}) failed" + return 1 + fi - decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" + decho "control_server='${control_server}'" decho "iface_ip='${iface_ip}'" decho "iface='${iface}'" decho "mac_address='${mac_address}'" - decho "register '${mac_address}'" - - cmd+="quiet" - cmd+="register '${mac_address}' '${iface_ip}'" - nsslsay_fingerprint ${cmd} + decho "register '${mac_address}' '${iface_ip}'" + nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" } register_client_local() @@ -85,6 +163,7 @@ return 1 fi + install -d "${MCORE_CONFIG_PATH}" CONFIG="${MCORE_CONFIG_PATH}/serial" clearconfig addconfig "CLIENT_SERIAL=\"${serial}\""