openstack API 创建虚拟机快照备份对应image

来源:互联网 发布:幻影粒子软件 编辑:程序博客网 时间:2024/06/06 02:22

附上笔者的部分代码:

def on_update_clicked(self):

        creds_1 = global_list.get_nova_creds()
        nova = nvclient.Client(**creds_1)      // 创建nova client
        creds = global_list.get_keystone_creds()
        keystone = ksclient.Client(**creds)    // 创建 keystone client
        #glance_endpoint=keystone.service_catalog.url_for(service_type='image',endpoint_type='publicURL')
        #glance=glanceclient.Client('1',glance_endpoint,token=keystone.auth_token)
        print demo1.whichdom   
        images = nova.images.list()   获取当前image 列表
        for x in images:    
            #print x.id
            x_str=str(x)
            img_lst=x_str.split(',')
            print img_lst
            for y in img_lst:
                y_lst=y.split(':')
                if y_lst[0] =="<Image":
                    z_lst=y_lst[1].split('>')
                    print z_lst[0]
                    if z_lst[0] ==' ' + demo1.whichdom:      // 以上for循环找到是否有相同的镜像名  并删除
                        print x.id
                        nova.images.delete(x.id)  删除相同名的镜像
        
        #flag = nova.images.delete('instance-0000000a')
        #print flag

        nova.servers.create_image(demo1.dom_id, demo1.whichdom) 创建虚拟机快照  并上传到glance上  

这段代码主要满足客户要求(用户使用完虚拟机以后,上传镜像文件,下次用该镜像创建虚拟机继续使用)

如果有朋友能想到更合理 安全的实现方法  还望指点  谢谢!!!

0 0