provider.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:kozinaki 作者: compunova 项目源码 文件源码
def create_node(self, instance, image_meta, *args, **kwargs):
        config = self.load_config()

        # Get info
        image_id = getattr(image_meta.properties, 'os_distro')
        flavor_name = instance.flavor['name']

        node_config = {'name': instance.uuid}

        # Find image
        for image in self.driver.list_images():
            if image.id == image_id:
                node_config['image'] = image
                break
        else:
            Exception('Image with id "{}" not found'.format(image_id))

        # Find size
        for size in self.driver.list_sizes():
            if size.id == flavor_name:
                node_config['size'] = size
                break
        else:
            Exception('Flavor with id "{}" not found'.format(flavor_name))

        # Find location
        for location in self.driver.list_locations():
            if location.id == config['location']:
                node_config['location'] = location
                break
        else:
            Exception('Location with id "{}" not found'.format(config['location']))

        # Root password
        try:
            if config.get('root_password'):
                node_config['auth'] = NodeAuthPassword(config.get('root_password'))
        except cfg.NoSuchOptError:
            pass

        instance = self.driver.create_node(**node_config)
        return instance
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号