Exemplo n.º 1
0
 def resize(self):
     """
     :param task:
          {
             "command": "resize",
             "handler": "TemplateHandler",
             "data": {
                 # size is the add size, not disk size
                 "images": [
                     {
                         "disk_file": "",
                         "size": 50
                     },
                     {
                         "disk_file": "",
                         "size": 50
                     },
                     ...
                 ]
             }
         }
     """
     logging.info("TemplateHandler, resize task begin, data:%s", self.task['data'])
     images = self.task['data']['images']
     ImageService().resize_disk(images)
Exemplo n.º 2
0
 def sync(self):
     """
     :param task:
          {
             "command": "sync",
             "handler": "TemplateHandler",
             "data": {
                 "image_version": 1,
                 "task_id": "3r451518-2b92-11ea-a62d-000c29b3ddb9",
                 "endpoint": "http://controller:2222",
                 "url": "/api/v1/file",
                 "image":
                     {
                         "image_id": "1d07aaa0-2b92-11ea-a62d-000c29b3ddb9",
                         "disk_file": "",
                         "backing_file": "",
                         "dest_path": "",
                         "md5_sum": ""
                     }
             }
         }
     """
     logging.info("TemplateHandler, sync task begin, data:%s", self.task['data'])
     image = self.task['data']['image']
     image_version = self.task['data']['image_version']
     endpoint = self.task['data']['endpoint']
     url = self.task['data']['url']
     task_id = self.task['data'].get('task_id', None)
     return ImageService(endpoint=endpoint).sync(url, image, image_version, task_id)
Exemplo n.º 3
0
 def create_file(self):
     """
     :param task:
          {
             "command": "create_file",
             "handler": "TemplateHandler",
             "data": {
                 "file": "/opt/slow/version_1_fdafdsa",
                 "size": "50G"
             }
         }
     """
     logging.info("TemplateHandler, create file task begin, data:%s", self.task['data'])
     file = self.task['data']['file']
     size = self.task['data']['size']
     ImageService().create_qcow2_file(file, size)
Exemplo n.º 4
0
 def delete_base(self):
     """
     删除基础镜像
     :param task:
          {
             "command": "delete_base",
             "handler": "TemplateHandler",
             "data": {
                 "image":
                 {
                     "disk_file": ""
                 }
             }
         }
     """
     logging.info("TemplateHandler, delete image base, data:%s", self.task['data'])
     image = self.task['data']['image']
     return ImageService().delete_image(image)
Exemplo n.º 5
0
 def write_header(self):
     """
     write head to image file, contain vcpu, ram, md5 sum, the allocated system disk size
     :param task:
          {
             "command": "write_header",
             "handler": "TemplateHandler",
             "data": {
                     "image_path": "",
                     "vcpu": 2,
                     "ram": 1.8,
                     "disk_size": 50
                 }
             }
         }
     """
     logging.info("TemplateHandler, write head task begin, data:%s", self.task)
     data = self.task['data']
     return ImageService().write_header(data)
Exemplo n.º 6
0
 def convert(self):
     """
     when copy a template, first generate a new base image(copy or merge the diff disk file)
     :param task:
          {
             "command": "convert",
             "handler": "TemplateHandler",
             "data": {
                 "template": {
                     "uuid": "dfcd91e8-30ed-11ea-9764-111c2902e179",
                     "backing_file": "/opt/ssd"
                     "dest_file": "dfcd91e8-30ed-11ea-9764-000c2902e179"
                     "need_convert": 0
                 }
             }
         }
     """
     logging.info("TemplateHandler, convert task begin, data:%s", self.task)
     template = self.task['data']['template']
     return ImageService().convert(template)
Exemplo n.º 7
0
 def copy(self):
     """
     复制模板时,将模板的系统盘和数据盘复制一份,基础镜像不变
     :param task:
          {
             "command": "copy",
             "handler": "TemplateHandler",
             "data": {
                 "image":
                 {
                     "image_id": "1d07aaa0-2b92-11ea-a62d-000c29b3ddb9",
                     "backing_file": "",
                     "dest_file": ""
                 }
             }
         }
     """
     logging.info("TemplateHandler, copy task begin, data:%s", self.task['data'])
     image = self.task['data']['image']
     return ImageService().copy_images(image)
Exemplo n.º 8
0
 def recreate_disk(self):
     """
     :param task:
          {
             "command": "save",
             "handler": "TemplateHandler",
             "data": {
                 "disks": [
                     {
                         "disk_file": "",
                         "backing_file": ""
                     },
                     ...
                 ]
             }
         }
     """
     logging.info("TemplateHandler, recreate task begin, data:%s", self.task['data'])
     disks = self.task['data']['disks']
     ImageService().recreate_disks(disks)