def create_tf(self):
    name = ((('xception-' + str(self.task_id)) + '-') + str(self.rtimes))
    ns_body = TaskTemplate.NS
    ns_body['metadata']['name'] = name
    if (not check_ns(name)):
        self.v1.create_namespace(ns_body)
    train_dir = check_path(name)
    time.sleep(12)
    result = self.influx_client.query((('select * from ' + 'NODEMESSAGE') + ' group by nodes order by desc limit 3'))
    node_list = self.get_node_list()
    result_keys = result.keys()
    nodes = [i[(- 1)]['nodes'] for i in result_keys]
    node_mg = [list(result[i]) for i in result_keys]
    cpu_base = {}
    memory_base = {}
    point_base = {}
    point_base_list = []
    for i in range(len(node_mg)):
        cpu_base[nodes[i]] = 0
        memory_base[nodes[i]] = 0
        point_base[nodes[i]] = 0.0
        for j in range(len(node_mg[0])):
            cpu_base[nodes[i]] += node_mg[i][j]['cpu']
            memory_base[nodes[i]] += node_mg[i][j]['memory']
        cpu_base[nodes[i]] = ((cpu_base[nodes[i]] / len(node_mg[0])) / self.node_cpu[nodes[i]])
        memory_base[nodes[i]] = ((memory_base[nodes[i]] / len(node_mg[0])) / self.node_memory[nodes[i]])
        tmp = ((cpu_base[nodes[i]] * 0.6) + (memory_base[nodes[i]] * 0.4))
        point_base[nodes[i]] = tmp
        point_base_list.append(tmp)
    list.sort(point_base_list)
    for key in nodes:
        command = (('kubectl label nodes ' + key) + ' woksch-')
        os.system(command)
        command2 = (('kubectl label nodes ' + key) + ' wokpro-')
        os.system(command2)
        nod_prori = point_base_list.index(point_base[key])
        priori = (' wokpro=%d' % nod_prori)
        command3 = (('kubectl label nodes ' + key) + priori)
        os.system(command3)
        if ((cpu_base[key] <= 0.6) and (memory_base[key] <= 0.6)):
            command = (('kubectl label nodes ' + key) + ' woksch=true')
            os.system(command)
        else:
            command = (('kubectl label nodes ' + key) + ' woksch=false')
            os.system(command)
    self.template['metadata']['name'] = name
    self.template['metadata']['namespace'] = name
    self.template['spec']['tfReplicaSpecs']['PS']['replicas'] = self.ps_replicas
    self.template['spec']['tfReplicaSpecs']['Worker']['replicas'] = self.worker_replicas
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['volumes'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['volumes'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['volumes'][0]['hostPath']['path'] = train_dir
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['volumes'][0]['hostPath']['path'] = train_dir
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['containers'][0]['volumeMounts'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['containers'][0]['volumeMounts'][0]['name'] = name
    self.make_args()
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['containers'][0]['args'] = self.args[:]
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['containers'][0]['args'] = self.args[:]
    log_dir = '/tfdata/tfcnn/expjob/'
    f = open(((log_dir + str(name)) + '.yaml'), 'w')
    yaml.dump(self.template, f)
    f.close()
    response = os.system(((('kubectl create -f ' + log_dir) + str(name)) + '.yaml'))
    if (response == 0):
        print('create task sucess')
    else:
        print(('Error code:' + str(response)))
def create_tf(self):
    name = ((('xception-' + str(self.task_id)) + '-') + str(self.rtimes))
    ns_body = TaskTemplate.NS
    ns_body['metadata']['name'] = name
    if (not check_ns(name)):
        self.v1.create_namespace(ns_body)
    train_dir = check_path(name)
    time.sleep(12)
    result = self.influx_client.query((('select * from ' + 'NODEMESSAGE') + ' group by nodes order by desc limit 3'))
    node_list = self.get_node_list()
    result_keys = result.keys()
    nodes = [i[(- 1)]['nodes'] for i in result_keys]
    node_mg = [list(result[i]) for i in result_keys]
    cpu_base = {}
    memory_base = {}
    point_base = {}
    point_base_list = []
    for i in range(len(node_mg)):
        cpu_base[nodes[i]] = 0
        memory_base[nodes[i]] = 0
        point_base[nodes[i]] = 0.0
        for j in range(len(node_mg[0])):
            cpu_base[nodes[i]] += node_mg[i][j]['cpu']
            memory_base[nodes[i]] += node_mg[i][j]['memory']
        cpu_base[nodes[i]] = ((cpu_base[nodes[i]] / len(node_mg[0])) / self.node_cpu[nodes[i]])
        memory_base[nodes[i]] = ((memory_base[nodes[i]] / len(node_mg[0])) / self.node_memory[nodes[i]])
        tmp = ((cpu_base[nodes[i]] * 0.6) + (memory_base[nodes[i]] * 0.4))
        point_base[nodes[i]] = tmp
        point_base_list.append(tmp)
    list.sort(point_base_list)
    for key in nodes:
        command = (('kubectl label nodes ' + key) + ' woksch-')
        os.system(command)
        command2 = (('kubectl label nodes ' + key) + ' wokpro-')
        os.system(command2)
        nod_prori = point_base_list.index(point_base[key])
        priori = (' wokpro=%d' % nod_prori)
        command3 = (('kubectl label nodes ' + key) + priori)
        os.system(command3)
        if ((cpu_base[key] <= 0.6) and (memory_base[key] <= 0.6)):
            command = (('kubectl label nodes ' + key) + ' woksch=true')
            os.system(command)
        else:
            command = (('kubectl label nodes ' + key) + ' woksch=false')
            os.system(command)
    self.template['metadata']['name'] = name
    self.template['metadata']['namespace'] = name
    self.template['spec']['tfReplicaSpecs']['PS']['replicas'] = self.ps_replicas
    self.template['spec']['tfReplicaSpecs']['Worker']['replicas'] = self.worker_replicas
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['volumes'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['volumes'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['volumes'][0]['hostPath']['path'] = train_dir
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['volumes'][0]['hostPath']['path'] = train_dir
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['containers'][0]['volumeMounts'][0]['name'] = name
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['containers'][0]['volumeMounts'][0]['name'] = name
    self.make_args()
    self.template['spec']['tfReplicaSpecs']['PS']['template']['spec']['containers'][0]['args'] = self.args[:]
    self.template['spec']['tfReplicaSpecs']['Worker']['template']['spec']['containers'][0]['args'] = self.args[:]
    log_dir = '/tfdata/tfcnn/expjob/'
    f = open(((log_dir + str(name)) + '.yaml'), 'w')
    yaml.dump(self.template, f)
    f.close()
    response = os.system(((('kubectl create -f ' + log_dir) + str(name)) + '.yaml'))
    if (response == 0):
        print('create task sucess')
    else:
        print(('Error code:' + str(response)))