Ejemplo n.º 1
0
def gluster_create_ssh_setup_jobs(parameters, skip_current_node=False):
    node_list = copy.deepcopy(parameters['Node[]'])

    ssh_job_ids = []
    ssh_key, err = NS.gluster_provisioner.get_plugin().setup()
    if err != "":
        _msg = "Error generating ssh key on node %s" % NS.node_context.node_id
        logger.log("error",
                   NS.publisher_id, {"message": _msg},
                   job_id=parameters['job_id'],
                   flow_id=parameters['flow_id'])
        raise FlowExecutionFailedError(_msg)

    if not skip_current_node:
        ret_val, err = authorize_key.AuthorizeKey(ssh_key).run()
        if ret_val is not True or err != "":
            _msg = "Error adding authorized key for node %s" % \
                   NS.node_context.node_id
            logger.log("error",
                       NS.publisher_id, {"message": _msg},
                       job_id=parameters['job_id'],
                       flow_id=parameters['flow_id'])
            raise FlowExecutionFailedError(_msg)
        node_list.remove(NS.node_context.node_id)

    for node in node_list:
        if node == NS.node_context.node_id:
            continue
        new_params = parameters.copy()
        new_params['Node[]'] = [node]
        new_params['ssh_key'] = ssh_key
        # Create same flow for each node from list except this one
        payload = {
            "tags": ["tendrl/node_%s" % node],
            "run": "tendrl.flows.AuthorizeSshKey",
            "status": "new",
            "parameters": new_params,
            "parent": parameters['job_id'],
            "type": "node"
        }
        _job_id = str(uuid.uuid4())
        NS.tendrl.objects.Job(job_id=_job_id, status="new",
                              payload=payload).save()
        ssh_job_ids.append(_job_id)
        logger.log("info",
                   NS.publisher_id, {
                       "message":
                       "Created SSH setup job(jobID: %s) for %s" %
                       (_job_id, node)
                   },
                   job_id=parameters['job_id'],
                   flow_id=parameters['flow_id'])
    return ssh_job_ids
Ejemplo n.º 2
0
 def run(self):
     ssh_key = self.parameters['ssh_key']
     ret_val, err = authorize_key.AuthorizeKey(ssh_key).run()
     if ret_val is not True or err != "":
         raise FlowExecutionFailedError(err)
     return True