def _imagecopy(self, context, instance, container_name, action_excution):

        backup_rec = {}
        action_excution.set_status(context, 'uploaded to swift')
        swift_conn = Clients(context).swift()
        headers = {'X-Container-Meta-dr_state': 'processing'}
        image = self.clients.glance().images.get(self._image_id)

        # take the checksum as unique id
        global_container_image_id = image._info['checksum']
        image_response = image.data()
        image_response_data = StringIO.StringIO()
        for chunk in image_response:
            image_response_data.write(chunk)
        image_response_data.seek(0, os.SEEK_SET)

        chunks = 0
        while True:
            data = image_response_data.read(self.data_block_size_bytes)
            data_offset = image_response_data.tell()
            LOG.debug("uploading image offset %s chunks %s"
                      % (data_offset, chunks))
            if data == '':
                break
            try:
                swift_conn.put_object(container_name,
                                      global_container_image_id + "_" +
                                      str(chunks),
                                      data,
                                      content_length=len(data))
                chunks += 1
            except socket.error as err:
                dr_state = 'DR image backup failed'
                action_excution.set_status(context, dr_state)
                raise exception.SwiftConnectionFailed(reason=str(err))

        dr_state = 'Protected'

        backup_rec["metadata"] = instance.metadata
        backup_rec["image_id"] = global_container_image_id
        backup_rec["instance_name"] = self._name
        backup_rec["meta"] = image.to_dict()
        backup_rec["chunks"] = chunks

        action_excution.set_status(context, dr_state)
        return dr_state, backup_rec
    def _imagecopy(self, context, instance, container_name, action_excution):

        backup_rec = {}
        action_excution.set_status(context, 'uploaded to swift')
        swift_conn = Clients(context).swift()
        headers = {'X-Container-Meta-dr_state': 'processing'}
        image = self.clients.glance().images.get(self._image_id)

        # take the checksum as unique id
        global_container_image_id = image._info['checksum']
        image_response = image.data()
        image_response_data = StringIO.StringIO()
        for chunk in image_response:
            image_response_data.write(chunk)
        image_response_data.seek(0, os.SEEK_SET)

        chunks = 0
        while True:
            data = image_response_data.read(self.data_block_size_bytes)
            data_offset = image_response_data.tell()
            LOG.debug("uploading image offset %s chunks %s" %
                      (data_offset, chunks))
            if data == '':
                break
            try:
                swift_conn.put_object(container_name,
                                      global_container_image_id + "_" +
                                      str(chunks),
                                      data,
                                      content_length=len(data))
                chunks += 1
            except socket.error as err:
                dr_state = 'DR image backup failed'
                action_excution.set_status(context, dr_state)
                raise exception.SwiftConnectionFailed(reason=str(err))

        dr_state = 'Protected'

        backup_rec["metadata"] = instance.metadata
        backup_rec["image_id"] = global_container_image_id
        backup_rec["instance_name"] = self._name
        backup_rec["meta"] = image.to_dict()
        backup_rec["chunks"] = chunks

        action_excution.set_status(context, dr_state)
        return dr_state, backup_rec
    def _snapshot(self, context, instance, container_name, action_excution):
        # metadata = instance.metadata
        n_client = self.clients.nova()
        snapshot_name = instance.name + "_snapshot"
        snapshot_metadata = instance.metadata

        instance_snapshot = instance.create_image(snapshot_name,
                                                  instance.metadata)
        self._snap_id = instance_snapshot
        action_excution.set_status(context, 'taking snapshot')
        local_snapshot = n_client.images.get(instance_snapshot)
        LOG.debug("checking instance snapshot %s %s "
                  % (local_snapshot.status, local_snapshot.progress))
        while (local_snapshot.status == "SAVING"):
            greenthread.sleep(1)
            local_snapshot = n_client.images.get(instance_snapshot)
        backup_rec = {}
        if local_snapshot.status == "ACTIVE":
            action_excution.set_status(context, 'uploading to swift')

            swift_conn = Clients(context).swift()
            headers = {'X-Container-Meta-dr_state': 'processing'}
            image = self.clients.glance().images.get(instance_snapshot)

            image_response = image.data()
            image_response_data = StringIO.StringIO()
            for chunk in image_response:
                image_response_data.write(chunk)
            image_response_data.seek(0, os.SEEK_SET)

            chunks = 0
            while True:
                data = image_response_data.read(self.data_block_size_bytes)
                data_offset = image_response_data.tell()
                LOG.debug("uploading offset %s chunks %s"
                          % (data_offset, chunks))
                if data == '':
                    break
                try:
                    swift_conn.put_object(container_name,
                                          instance_snapshot + "_" +
                                          str(chunks),
                                          data,
                                          content_length=len(data))
                    chunks += 1
                except socket.error as err:
                    raise exception.SwiftConnectionFailed(reason=str(err))

            dr_state = 'Protected'

            backup_rec["metadata"] = instance.metadata
            backup_rec["snap_id"] = self._snap_id
            backup_rec["instance_name"] = self._name
            backup_rec["meta"] = image.to_dict()
            backup_rec["chunks"] = chunks

            self._cleanup(context, n_client, self._snap_id)
        else:
            dr_state = 'DR clone backup failed'

        action_excution.set_status(context, dr_state)

        return dr_state, backup_rec
コード例 #4
0
    def _snapshot(self, context, instance, container_name, action_excution):
        # metadata = instance.metadata
        n_client = self.clients.nova()
        snapshot_name = instance.name + "_snapshot"
        snapshot_metadata = instance.metadata

        instance_snapshot = instance.create_image(snapshot_name,
                                                  instance.metadata)
        self._snap_id = instance_snapshot
        action_excution.set_status(context, 'taking snapshot')
        local_snapshot = n_client.images.get(instance_snapshot)
        LOG.debug("checking instance snapshot %s %s " %
                  (local_snapshot.status, local_snapshot.progress))
        while (local_snapshot.status == "SAVING"):
            greenthread.sleep(1)
            local_snapshot = n_client.images.get(instance_snapshot)
        backup_rec = {}
        if local_snapshot.status == "ACTIVE":
            action_excution.set_status(context, 'uploading to swift')

            swift_conn = Clients(context).swift()
            headers = {'X-Container-Meta-dr_state': 'processing'}
            image = self.clients.glance().images.get(instance_snapshot)

            image_response = image.data()
            image_response_data = StringIO.StringIO()
            for chunk in image_response:
                image_response_data.write(chunk)
            image_response_data.seek(0, os.SEEK_SET)

            chunks = 0
            while True:
                data = image_response_data.read(self.data_block_size_bytes)
                data_offset = image_response_data.tell()
                LOG.debug("uploading offset %s chunks %s" %
                          (data_offset, chunks))
                if data == '':
                    break
                try:
                    swift_conn.put_object(container_name,
                                          instance_snapshot + "_" +
                                          str(chunks),
                                          data,
                                          content_length=len(data))
                    chunks += 1
                except socket.error as err:
                    raise exception.SwiftConnectionFailed(reason=str(err))

            dr_state = 'Protected'

            backup_rec["metadata"] = instance.metadata
            backup_rec["snap_id"] = self._snap_id
            backup_rec["instance_name"] = self._name
            backup_rec["meta"] = image.to_dict()
            backup_rec["chunks"] = chunks

            self._cleanup(context, n_client, self._snap_id)
        else:
            dr_state = 'DR clone backup failed'

        action_excution.set_status(context, dr_state)

        return dr_state, backup_rec