def customwf(nodes_to_runon, operations_to_execute, **kwargs): ctx = workflow_ctx ctx.logger.info("Starting Custom Workflow") try: nodes = json.loads(nodes_to_runon) except TypeError: ctx.logger.info("Nodes not in Jsaon trying directly") nodes = nodes_to_runon try: operations = json.loads(operations_to_execute) except TypeError: ctx.logger.info("operations not in Jsaon trying directly") operations = operations_to_execute ctx.logger.info("Nodes {} on Operations {}".format(nodes, operations)) # update interface on the config node graph = ctx.graph_mode() sequence = graph.sequence() for opnode in nodes: for node in ctx.nodes: if node.id == opnode: for instance in node.instances: for operation in operations: ctx.logger.info( "Running operation {} on instance {} of node {}". format(operation, instance.id, node.id)) operation_task = instance.execute_operation(operation) sequence.add(operation_task) graph.execute()
def deploy_alternate(ctx, **kwargs): graph = ctx.graph_mode() for node in ctx.nodes: for instance in node.instances: if node.type == 'datagrid_type': graph.add_task(instance.execute_operation( 'cloudify.interfaces.lifecycle.deploy_alternate')) return graph.execute()
def update(params, configuration_node_type, node_types_to_update, **kwargs): ctx = workflow_ctx ctx.logger.info("Starting Update Workflow") restcli = manager.get_rest_client() node_types = set(node_types_to_update) ## update interface on the config node graph = ctx.graph_mode() sequence = graph.sequence() for node in ctx.nodes: if configuration_node_type in node.type_hierarchy: for instance in node.instances: load_config_task = instance.execute_operation( 'cloudify.interfaces.lifecycle.configure', allow_kwargs_override=True, kwargs={'parameters': params}) sequence.add(load_config_task) for node in ctx.nodes: if node_types.intersection(set(node.type_hierarchy)): for instance in node.instances: for relationship in instance.relationships: operation_task = relationship.execute_target_operation( 'cloudify.interfaces.relationship_lifecycle.preconfigure' ) sequence.add(operation_task) graph.execute() sequence = graph.sequence() for node in ctx.nodes: if node_types.intersection(set(node.type_hierarchy)): for instance in node.instances: currentinstance = restcli.node_instances.get(instance.id) if len(currentinstance.runtime_properties['params'] ['diff_params']) > 0: ctx.logger.info( "Updating instance ID: {} with diff_params {} ".format( instance.id, currentinstance.runtime_properties['params'] ['diff_params'])) operation_task = instance.execute_operation( 'cloudify.interfaces.lifecycle.update') sequence.add(operation_task) return graph.execute()
def bounce_gridservice(ctx, **kwargs): graph = ctx.graph_mode() for node in ctx.nodes: for instance in node.instances: if node.type == 'gridservice_type': sequence = graph.sequence() sequence.add( instance.execute_operation( 'cloudify.interfaces.lifecycle.stop'), instance.execute_operation( 'cloudify.interfaces.lifecycle.start'), ) return graph.execute()
def config_dns(ctx, endpoint, **kwargs): # setting node instance runtime property ctx.logger.info('workflow parameter: {0}'.format(endpoint["ip_address"])) nodes = ['bono_app', 'ellis_app', 'homer_app', 'homestead_app', 'ralf_app', 'sprout_app'] graph = ctx.graph_mode() for node in ctx.nodes: ctx.logger.info('In node: {0}'.format(node.id)) if node.id in nodes: ctx.logger.info('In node: {0}'.format(node.id)) for instance in node.instances: sequence = graph.sequence() sequence.add( instance.send_event('Starting to run operation'), instance.execute_operation('cloudify.interfaces.lifecycle.configure-dns', \ {'dns_ip': endpoint["ip_address"]}), instance.send_event('Done running operation') ) return graph.execute()
def update(params, configuration_node_id, node_types_to_update, merge_dict, **kwargs): ctx = workflow_ctx ctx.logger.info("Starting Update Workflow") restcli = manager.get_rest_client() node_types = set(node_types_to_update) # update interface on the config node graph = ctx.graph_mode() params = _handle_parameters(params) perform_availability_check(graph, node_types, configuration_node_id, params, ctx) configure_and_preconfigure(graph, configuration_node_id, params, merge_dict, node_types, ctx) return update_on_nodes(graph, node_types, configuration_node_id, params, restcli, ctx)
def customwf(nodes_to_runon, operations_to_execute, **kwargs): ctx = workflow_ctx ctx.logger.info("Starting Custom Workflow") try: nodes = json.loads(nodes_to_runon) except TypeError: ctx.logger.info("Nodes not in Json trying directly") nodes = nodes_to_runon try: operations = json.loads(operations_to_execute) except TypeError: ctx.logger.info("operations not in Json trying directly") operations = operations_to_execute ctx.logger.info("Nodes {} on Operations {}".format(nodes, operations)) # update interface on the config node graph = ctx.graph_mode() # If ctx is left in the kwargs it will cause exceptions # It will be injected for the operation being executed anyway kwargs.pop('ctx') sequence = graph.sequence() for opnode in nodes: for node in ctx.nodes: if node.id == opnode: for instance in node.instances: for operation in operations: # add to run operation sequence.add( instance.send_event( 'Starting to {} on instance {} of node {}' .format(operation, instance.id, node.id)), instance.execute_operation(operation, kwargs=kwargs), instance.send_event('Done {}'.format(operation))) graph.execute()