简体   繁体   English

如何利用luigi进行Openstack任务

[英]How can I leverage luigi for Openstack tasks

I want to use Luigi to manage workflows in Openstack. 我想使用Luigi来管理Openstack中的工作流程。 I am new to Luigi. 我是Luigi的新手。 For the starter, I just want to authenticate myself to Openstack and then fetch image list, flavor list etc using Luigi. 对于初学者,我只想对Openstack进行身份验证,然后使用Luigi获取图像列表,风味列表等。 Any help will be appreciable. 任何帮助都会很明显。

I am not good with python but I tried below code. 我对python不好,但我尝试了下面的代码。 I am also not able to list images. 我也无法列出图像。 Error: glanceclient.exc.HTTPNotFound: The resource could not be found. 错误:glanceclient.exc.HTTPNotFound:找不到资源。 (HTTP 404) (HTTP 404)

import luigi
import os_client_config
import glanceclient.v2.client as glclient
from luigi.mock import MockFile
import sys
import os

def get_credentials():
    d = {}
    d['username'] = 'X'
    d['password'] = 'X'
    d['auth_url'] = 'X'
    d['tenant_name'] = 'X'
    d['endpoint'] = 'X'
    return d

class LookupOpenstack(luigi.Task):
    d =[]

    def requires(self):
        pass
    def output(self):
        gc = glclient.Client(**get_credentials())
        images = gc.images.list()
        print("images", images)
        for i in images:
            print(i)

        return MockFile("images", mirror_on_stderr=True)

    def run(self):
        pass

if __name__ == '__main__':
    luigi.run(["--local-scheduler"], LookupOpenstack())

The general approach to this is just write python code to perform the tasks you want using the OpenStack API. 对此的一般方法是编写python代码以使用OpenStack API执行您想要的任务。 https://docs.openstack.org/user-guide/sdk.html It looks like the error you are getting is addressed on the OpenStack site. https://docs.openstack.org/user-guide/sdk.html看起来你得到的错误是在OpenStack网站上解决的。 https://ask.openstack.org/en/question/90071/glanceclientexchttpnotfound-the-resource-could-not-be-found-http-404/ https://ask.openstack.org/en/question/90071/glanceclientexchttpnotfound-the-resource-could-not-be-found-http-404/

You would then just wrap this code in luigi Tasks as appropriate- there's nothing special about doing with this OpenStack, except that you must define the output() of your luigi tasks to match up with an output that indicates the task is done. 然后,您可以根据需要将此代码包装在luigi Tasks中 - 除了您必须定义luigi任务的output()以匹配指示任务已完成的output()之外,使用此OpenStack没有什么特别之处。 Right now it looks like the work is being done in the output() method, which should be in the run() method, the output method should just be what to look for to indicate that the run() method is complete so it doesn't run() when required by another task if it is already done. 现在看起来工作是在output()方法中完成的,它应该在run()方法中,输出方法应该只是寻找指示run()方法完成所以它不会如果已经完成,则在另一个任务需要时运行()。

It's really impossible to say more without understanding more details of your workflow. 如果不了解工作流程的更多细节,真的不可能多说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM