Ejemplo n.º 1
0
    def rebundle(self):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(self._role_name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = self._role_name[0:16] + '--' + now
        else:
            image_name = self._role_name + "-" + now

        pl = bus.platform
        conn = pl.new_cloudstack_conn()

        try:
            root_vol = filter(lambda x: x.type == 'ROOT',
                    conn.listVolumes(virtualMachineId=pl.get_instance_id()))[0]
        except IndexError:
            raise HandlerError(
                            "Can't find root volume for virtual machine %s" % pl.get_instance_id())

        instance = conn.listVirtualMachines(id=pl.get_instance_id())[0]
        try:
            tpl = conn.listTemplates('self', id=instance.templateid)[0]
            tpl_details = tpl.details
        except:
            # We can have a situation when 'self' filter returns empty resultset.
            tpl_details = None

        # if tpl_details:
        #     # Filter
        #     details_keys = tpl_details.keys()
        #     details_keys = filter(lambda k: not k.startswith('Message.'), details_keys)
        #     tpl_details = dict((k, tpl_details[k]) for k in details_keys)

        try:
            # Create snapshot
            LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
            snap = voltool.create_snapshot(conn, root_vol.id, wait_completion=True, logger=LOG)
            LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

            LOG.info('Creating image')
            try:
                image = conn.process_async('createTemplate', {
                    'name': image_name, 
                    'displaytext': image_name, 
                    'ostypeid': self.get_os_type_id(conn),
                    'passwordenabled': instance.passwordenabled,
                    'snapshotid': snap.id,
                    'details': tpl_details}, # clone details like 'hypervisortoolsversion' etc.
                    DataObject)
            except CloudException, e:
                if re.search(r'invalid value .* for parameter details', str(e)):
                    LOG.warn('Got error: %s. Executing createTemplate without details parameter', e)
                    image = conn.createTemplate(
                                image_name, image_name, self.get_os_type_id(conn),
                                snapshotId=snap.id,
                                passwordEnabled=instance.passwordenabled) 
                else:
                    raise
            LOG.info('Image created (template: %s)', image.id)

            return image.id
Ejemplo n.º 2
0
    def rebundle(self):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(self._role_name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = self._role_name[0:16] + '--' + now
        else:
            image_name = self._role_name + "-" + now

        pl = bus.platform
        conn = pl.new_cloudstack_conn()

        try:
            root_vol = filter(
                lambda x: x.type == 'ROOT',
                conn.listVolumes(virtualMachineId=pl.get_instance_id()))[0]
        except IndexError:
            raise HandlerError(
                "Can't find root volume for virtual machine %s" %
                pl.get_instance_id())

        instance = conn.listVirtualMachines(id=pl.get_instance_id())[0]

        try:
            # Create snapshot
            LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
            snap = voltool.create_snapshot(conn,
                                           root_vol.id,
                                           wait_completion=True,
                                           logger=LOG)
            LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

            LOG.info('Creating image')
            image = conn.createTemplate(
                image_name,
                image_name,
                self.get_os_type_id(conn),
                snapshotId=snap.id,
                passwordEnabled=instance.passwordenabled)
            LOG.info('Image created (template: %s)', image.id)

            return image.id
        finally:
            pass
Ejemplo n.º 3
0
    def snapshot(self, op, name):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = name[0:len(now) + 2] + '--' + now
        else:
            image_name = name + "-" + now

        pl = __node__['platform']
        conn = pl.new_cloudstack_conn()

        root_vol = None
        instance_id = pl.get_instance_id()
        for vol in conn.listVolumes(virtualMachineId=instance_id):
            if vol.type == 'ROOT':
                root_vol = vol
                break
        else:
            raise ImageAPIError(
                "Can't find root volume for virtual machine %s" % instance_id)

        instance = conn.listVirtualMachines(id=instance_id)[0]

        LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
        snap = voltool.create_snapshot(conn,
                                       root_vol.id,
                                       wait_completion=True,
                                       logger=LOG)
        LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

        LOG.info('Creating image')
        image = conn.createTemplate(image_name,
                                    image_name,
                                    self.get_os_type_id(conn, instance_id),
                                    snapshotId=snap.id,
                                    passwordEnabled=instance.passwordenabled)
        LOG.info('Image created (template: %s)', image.id)

        return image.id
Ejemplo n.º 4
0
    def snapshot(self, op, name):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = name[0:len(now)+2] + '--' + now
        else:
            image_name = name + "-" + now

        pl = __node__['platform']
        conn = pl.new_cloudstack_conn()

        root_vol = None
        instance_id = pl.get_instance_id()
        for vol in conn.listVolumes(virtualMachineId=instance_id):
            if vol.type == 'ROOT':
                root_vol = vol
                break
        else:
            raise ImageAPIError("Can't find root volume for virtual machine %s" % 
                instance_id)

        instance = conn.listVirtualMachines(id=instance_id)[0]

        LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
        snap = voltool.create_snapshot(conn,
            root_vol.id,
            wait_completion=True,
            logger=LOG)
        LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

        LOG.info('Creating image')
        image = conn.createTemplate(image_name, 
            image_name,
            self.get_os_type_id(conn, instance_id),
            snapshotId=snap.id,
            passwordEnabled=instance.passwordenabled)
        LOG.info('Image created (template: %s)', image.id)

        return image.id
Ejemplo n.º 5
0
    def rebundle(self):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(self._role_name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = self._role_name[0:16] + '--' + now
        else:
            image_name = self._role_name + "-" + now

        pl = bus.platform
        conn = pl.new_cloudstack_conn()

        try:
            root_vol = filter(lambda x: x.type == 'ROOT',
                    conn.listVolumes(virtualMachineId=pl.get_instance_id()))[0]
        except IndexError:
            raise HandlerError(
                            "Can't find root volume for virtual machine %s" % pl.get_instance_id())

        instance = conn.listVirtualMachines(id=pl.get_instance_id())[0]

        try:
            # Create snapshot
            LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
            snap = voltool.create_snapshot(conn, root_vol.id,
                                                                                    wait_completion=True, logger=LOG)
            LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

            LOG.info('Creating image')
            image = conn.createTemplate(image_name, image_name,
                                            self.get_os_type_id(conn),
                                            snapshotId=snap.id,
                                            passwordEnabled=instance.passwordenabled)
            LOG.info('Image created (template: %s)', image.id)

            return image.id
        finally:
            pass
Ejemplo n.º 6
0
    def rebundle(self):
        now = time.strftime('%Y%m%d%H%M%S')
        if len(self._role_name) > self.IMAGE_NAME_MAXLEN - len(now) - 1:
            image_name = self._role_name[0:16] + '--' + now
        else:
            image_name = self._role_name + "-" + now

        pl = bus.platform
        conn = pl.new_cloudstack_conn()

        try:
            root_vol = filter(
                lambda x: x.type == 'ROOT',
                conn.listVolumes(virtualMachineId=pl.get_instance_id()))[0]
        except IndexError:
            raise HandlerError(
                "Can't find root volume for virtual machine %s" %
                pl.get_instance_id())

        instance = conn.listVirtualMachines(id=pl.get_instance_id())[0]
        try:
            tpl = conn.listTemplates('self', id=instance.templateid)[0]
            tpl_details = tpl.details
        except:
            # We can have a situation when 'self' filter returns empty resultset.
            tpl_details = None

        # if tpl_details:
        #     # Filter
        #     details_keys = tpl_details.keys()
        #     details_keys = filter(lambda k: not k.startswith('Message.'), details_keys)
        #     tpl_details = dict((k, tpl_details[k]) for k in details_keys)

        try:
            # Create snapshot
            LOG.info('Creating ROOT volume snapshot (volume: %s)', root_vol.id)
            snap = voltool.create_snapshot(conn,
                                           root_vol.id,
                                           wait_completion=True,
                                           logger=LOG)
            LOG.info('ROOT volume snapshot created (snapshot: %s)', snap.id)

            LOG.info('Creating image')
            try:
                image = conn.process_async(
                    'createTemplate',
                    {
                        'name': image_name,
                        'displaytext': image_name,
                        'ostypeid': self.get_os_type_id(conn),
                        'passwordenabled': instance.passwordenabled,
                        'snapshotid': snap.id,
                        'details': tpl_details
                    },  # clone details like 'hypervisortoolsversion' etc.
                    DataObject)
            except CloudException, e:
                if re.search(r'invalid value .* for parameter details',
                             str(e)):
                    LOG.warn(
                        'Got error: %s. Executing createTemplate without details parameter',
                        e)
                    image = conn.createTemplate(
                        image_name,
                        image_name,
                        self.get_os_type_id(conn),
                        snapshotId=snap.id,
                        passwordEnabled=instance.passwordenabled)
                else:
                    raise
            LOG.info('Image created (template: %s)', image.id)

            return image.id