Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of using openstack workflow workflows?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about the principle of the use of openstack workflow workflows, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Workflows

Workflows are complex forms (forms) and tabs, and each workflow must contain Workflow, Step and Action

Here is an example of the use of workflow:

The following example shows how data is passed from urls, views, workflows, and templates to each other.

In urls.py, a parameter is defined. For example. Resource_class_id.

RESOURCE_CLASS = r'^ (? P [^ /] +) /% s$'urlpatterns = patterns (', url (RESOURCE_CLASS% 'update', UpdateView.as_view (), name='update'))

In views.py, we can pass data to template (template) and action (form). (action can also pass data to get_context_data methods or template)

Class UpdateView (workflows.WorkflowView): workflow_class = UpdateResourceClassdef get_context_data (self, * * kwargs): context = super (UpdateView, self). Data in get_context_data (* * kwargs) # url is usually in self.kwargs, where we can pass the data to template.url

Context ["resource_class_id"] = self.kwargs ['resource_class_id'] # data comes from Workflow's Steps and is stored in the context [' workflow'] .context list. We can also use them in template.

Return contextdef _ get_object (self, * args, * * kwargs): the data in # url is usually in self.kwargs, where we can load the object of interest resource_class_id = self.kwargs ['resource_class_id'] # eg:my_objects = api.nova.get_by_id (resource_class_id)

Def get_initial (self): resource_class = self._get_object () # the data here can be used by the Action method and the Workflow's handle method, but the steps must depend on the value return {'resource_class_id': resource_class.id,'name': resource_class.name,'service_type': resource_class.service_type}

In workflows.py, where we deal with data, workflows is essentially a more complex django form (form).

Class ResourcesAction (workflows.Action): # the name field values defined below are available in all action methods # if we expect this value to be used in other steps or other workflow, it must be derived from the current step And establish depend on in other step name = forms.CharField (max_length=255, label=_ ("Testing Name"), help_text= ", required=True) def handle (self, request, data): if pass# wants to use the parameter values in url, the depend on relationship must be established in the step corresponding to the Action.

# you can get the value by self.initial ['resource_class_id'] or data [' resource_class_id'] # if we want to use data from other step, then the other step must contribute the data, and there is an ordered class UpdateResources (workflows.Step) between the two step: # here the data of Workflow is passed to the action method handle/clean, and the value you want to use in action Here depends_on must define the context data of # Workflow, including data from url and data from other step depends_on = ("resource_class_id",) # through the contributes parameter, the data here can be used by other workflow or other step. It is worth noting that object_ids key needs to be manually added to contributes.

Contributes = ("resources_object_ids", "name") def contribute (self, data, context): # http request data of workflow can be obtained here request = self.workflow.requestif data:# can only be obtained here if you want to get other values, you need to override the contribute method and manually add context ["resources_object_ids"] =\ to the dictionary.

Request.POST.getlist ("resources_object_ids") # merges the data passed above, or you can leave it to the parent class to merge

Context.update (data) return contextclass UpdateResourceClass (workflows.Workflow):

Default_steps = (UpdateResources,) def handle (self, request, data): pass# this method is executed last (after all Action's handle methods)

# all 'contributes=' and' depends_on=' data in step can be used here # complex business logic can be handled here # available values here: data ["resources_object_ids"], data ["name"] data ["resources_class_id"] after reading the above, do you have any further understanding of how openstack workflow workflows is used? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report