def removeKey(hostname, node_id, region): print "Start to remove key in master." salt_server = settings.C2_STATIC["Salt"] try: LOG = c2_ssh.conn2(salt_server, CMD_NO_KEY % hostname) except Exception, ex: print Exception, "removeKey:", ex LOG = "remove key exception:%s" % str(ex) ComputeNodeMana().updateMinionState("RMKEY_ERR", node_id, region)
def syncModules2Minion(minionName, node_id, region): salt_server = settings.C2_STATIC["Salt"] try: LOG = c2_ssh.conn2(salt_server, CMD_SYNC_MASTER % minionName) if "_error_" in LOG: state = "ERROR" except Exception, ex: print Exception, "syncModules2Minion:", ex LOG = "syncModules2Minion exception:%s" % str(ex) ComputeNodeMana().updateMinionState("SYNC_ERROR", node_id, region)
def masterAcceptKey(hostname, node_id, region): salt_server = settings.C2_STATIC["Salt"] try: LOG = c2_ssh.conn2(salt_server, CMD_MASTER_PASS % hostname) if "_error_" in LOG: state = "ERROR" except Exception, ex: print Exception, "masterAcceptKey:", ex LOG = "masterAcceptKey exception:%s" % str(ex) ComputeNodeMana().updateMinionState("KEY_ERROR", node_id, region)
def masterSync(hostname): salt_server = settings.C2_STATIC["Salt"] print salt_server try: LOG = c2_ssh.conn2(salt_server, CMD_MASTER_SYNC.format(hostname, hostname)) if "_error_" in LOG: state = "ERROR" except Exception, ex: print Exception, "masterSync:", ex LOG = "masterSync exception:%s" % str(ex) state = "SYNC_ERROR"
def install_new_minion(node, region): print "ADD MINION TO DB" ComputeNodeMana().addMinion(node, region) salt_master = settings.C2_STATIC["Salt_master"] state = "INSTALLED" rets = [] removeKey(node.hypervisor_hostname, node.id, region) print "------------start to remove minion ------------------" try: LOG = c2_ssh.conn2(getConnIp(node.host_ip), CMD_REMOVE_MINION) print "REMOVE_MINION log:%s" % LOG except Exception, ex: LOG = "REMOVE_MINION exception:%s" % str(ex) ComputeNodeMana().addSaltLog("(%s)_REMOVE_MINION_ERROR:%s" % (node.hypervisor_hostname, LOG), "INSTALL_ERROR") print Exception, "REMOVE_MINION:", ex
rets = [] removeKey(node.hypervisor_hostname, node.id, region) print "------------start to remove minion ------------------" try: LOG = c2_ssh.conn2(getConnIp(node.host_ip), CMD_REMOVE_MINION) print "REMOVE_MINION log:%s" % LOG except Exception, ex: LOG = "REMOVE_MINION exception:%s" % str(ex) ComputeNodeMana().addSaltLog("(%s)_REMOVE_MINION_ERROR:%s" % (node.hypervisor_hostname, LOG), "INSTALL_ERROR") print Exception, "REMOVE_MINION:", ex print "----------------finish remove minion --------------------------" print "------------start to clear minion config------------------" try: LOG = c2_ssh.conn2(getConnIp(node.host_ip), CMD_CLEAR_MINION_CONF) print "CLEAR_MINION_CONF log:%s" % LOG except Exception, ex: LOG = "CLEAR_MINION_CONF exception:%s" % str(ex) print Exception, "CLEAR_MINION_CONF:", ex print "----------------finish clear minion config --------------------------" # CMD_CLEAR_MODULE_CONF print "------------start to clear MODULE config------------------" try: LOG = c2_ssh.conn2(getConnIp(node.host_ip), CMD_CLEAR_MODULE_CONF) print "CLEAR_MODULE_CONF log:%s" % LOG except Exception, ex: LOG = "CLEAR_MODULE_CONF exception:%s" % str(ex) print Exception, "CLEAR_MODULE_CONF:", ex