示例#1
0
    def container_cdn_command(self, url, container, sfile=None):
        """Command your CDN enabled Container.

        :param url:
        :param container:
        """
        rty_count = ARGS.get('error_retry')
        for retry in basic.retryloop(attempts=rty_count, delay=2, obj=sfile):
            # Open Connection
            conn = http.open_connection(url=url)
            with meth.operation(retry, conn):
                cheaders = self.payload['headers']
                if sfile is not None:
                    rpath = http.quoter(url=url.path,
                                        cont=container,
                                        ufile=sfile)
                    # perform CDN Object DELETE
                    conn.request('DELETE', rpath, headers=cheaders)
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)
                else:
                    rpath = http.quoter(url=url.path, cont=container)
                    http.cdn_toggle(headers=cheaders)
                    # perform CDN Enable POST
                    conn.request('PUT', rpath, headers=cheaders)
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)

                report.reporter(
                    msg=('OBJECT %s MESSAGE %s %s %s' %
                         (rpath, resp.status, resp.reason, resp.msg)),
                    prt=False,
                    lvl='debug')
示例#2
0
    def container_cdn_command(self, url, container, sfile=None):
        """Command your CDN enabled Container.

        :param url:
        :param container:
        """
        rty_count = ARGS.get('error_retry')
        for retry in basic.retryloop(attempts=rty_count, delay=2, obj=sfile):
            # Open Connection
            conn = http.open_connection(url=url)
            with meth.operation(retry, conn):
                cheaders = self.payload['headers']
                if sfile is not None:
                    rpath = http.quoter(url=url.path,
                                        cont=container,
                                        ufile=sfile)
                    # perform CDN Object DELETE
                    conn.request('DELETE', rpath, headers=cheaders)
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)
                else:
                    rpath = http.quoter(url=url.path,
                                        cont=container)
                    http.cdn_toggle(headers=cheaders)
                    # perform CDN Enable POST
                    conn.request('PUT', rpath, headers=cheaders)
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)

                report.reporter(
                    msg=('OBJECT %s MESSAGE %s %s %s'
                         % (rpath, resp.status, resp.reason, resp.msg)),
                    prt=False,
                    lvl='debug'
                )
示例#3
0
    def _putter(self, conn, fpath, rpath, fheaders, retry, skip=False):
        """Place  object into the container.

        :param conn:
        :param fpath:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        if self._checker(conn, rpath, fpath, fheaders, retry, skip) is True:
            report.reporter(msg='OBJECT ORIGIN %s RPATH %s' % (fpath, rpath),
                            prt=False,
                            lvl='debug')

            if basic.file_exists(fpath) is False:
                return None
            else:
                with open(fpath, 'rb') as f_open:
                    conn.request('PUT', rpath, body=f_open, headers=fheaders)
                resp, read = http.response_get(conn=conn, retry=retry)
                self.resp_exception(resp=resp, rty=retry)

                report.reporter(msg=('MESSAGE %s %s %s' %
                                     (resp.status, resp.reason, resp.msg)),
                                prt=False,
                                lvl='debug')
示例#4
0
    def _putter(self, conn, fpath, rpath, fheaders, retry, skip=False):
        """Place  object into the container.

        :param conn:
        :param fpath:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        if self._checker(conn, rpath, fpath, fheaders, retry, skip) is True:
            report.reporter(
                msg='OBJECT ORIGIN %s RPATH %s' % (fpath, rpath),
                prt=False,
                lvl='debug'
            )

            if basic.file_exists(fpath) is False:
                return None
            else:
                with open(fpath, 'rb') as f_open:
                    conn.request('PUT', rpath, body=f_open, headers=fheaders)
                resp, read = http.response_get(conn=conn, retry=retry)
                self.resp_exception(resp=resp, rty=retry)

                report.reporter(
                    msg=('MESSAGE %s %s %s'
                         % (resp.status, resp.reason, resp.msg)),
                    prt=False,
                    lvl='debug'
                )
示例#5
0
    def _header_getter(self, conn, rpath, fheaders, retry):
        """perfrom HEAD request on a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object HEAD request
        conn.request('HEAD', rpath, headers=fheaders)
        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(msg='INFO: %s %s %s' %
                        (resp.status, resp.reason, resp.msg),
                        prt=False)

        return resp
示例#6
0
    def _deleter(self, conn, rpath, fheaders, retry):
        """Delete a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object Delete
        conn.request('DELETE', rpath, headers=fheaders)

        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(msg=('OBJECT %s MESSAGE %s %s %s' %
                             (rpath, resp.status, resp.reason, resp.msg)),
                        prt=False,
                        lvl='debug')
示例#7
0
    def _header_poster(self, conn, rpath, fheaders, retry):
        """POST Headers on a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object POST request for header update.
        conn.request('POST', rpath, headers=fheaders)
        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(msg=('STATUS: %s MESSAGE: %s REASON: %s' %
                             (resp.status, resp.msg, resp.reason)),
                        prt=False,
                        lvl='debug')

        return dict(resp.getheaders())
示例#8
0
    def _header_getter(self, conn, rpath, fheaders, retry):
        """perfrom HEAD request on a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object HEAD request
        conn.request('HEAD', rpath, headers=fheaders)
        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(
            msg='INFO: %s %s %s' % (resp.status, resp.reason, resp.msg),
            prt=False
        )

        return resp
示例#9
0
        def _obj_index(b_path, m_path, l_obj, f_list):
            conn.request('GET', m_path, headers=fheaders)
            resp, read = http.response_get(conn=conn, retry=retry)
            self.resp_exception(resp=resp, rty=retry)
            return_list = basic.json_encode(read)

            for obj in return_list:
                time_offset = ARGS.get('time_offset')
                if time_offset is not None:
                    # Get the last_modified data from the Object.
                    if cloud.time_delta(lmobj=time_offset) is True:
                        f_list.append(obj)
                else:
                    f_list.append(obj)

            last_obj_in_list = f_list[-1].get('name')
            if l_obj is last_obj_in_list:
                return f_list
            else:
                marker = _marker_type(base=b_path, last=last_obj_in_list)
                _obj_index(b_path, marker, last_obj_in_list, f_list)
示例#10
0
    def _deleter(self, conn, rpath, fheaders, retry):
        """Delete a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object Delete
        conn.request('DELETE', rpath, headers=fheaders)

        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(
            msg=('OBJECT %s MESSAGE %s %s %s'
                 % (rpath, resp.status, resp.reason, resp.msg)),
            prt=False,
            lvl='debug'
        )
示例#11
0
    def container_create(self, url, container):
        """Create a container if it is not Found.

        :param url:
        :param container:
        """

        rty_count = ARGS.get('error_retry')
        for retry in basic.retryloop(attempts=rty_count,
                                     delay=5,
                                     obj=container):
            conn = http.open_connection(url=url)

            rpath = http.quoter(url=url.path,
                                cont=container)

            # Open connection and perform operation
            with meth.operation(retry, conn):

                resp = self._header_getter(conn=conn,
                                           rpath=rpath,
                                           fheaders=self.payload['headers'],
                                           retry=retry)

                # Check that the status was a good one
                if resp.status == 404:
                    report.reporter(
                        msg='Creating Container ==> %s' % container
                    )

                    conn.request('PUT', rpath, headers=self.payload['headers'])
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)

                    report.reporter(msg='Container "%s" Created' % container)
                    return True
                else:
                    report.reporter(msg='Container "%s" Found' % container)
                    return False
示例#12
0
    def _header_poster(self, conn, rpath, fheaders, retry):
        """POST Headers on a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param retry:
        """

        # perform Object POST request for header update.
        conn.request('POST', rpath, headers=fheaders)
        resp, read = http.response_get(conn=conn, retry=retry)
        self.resp_exception(resp=resp, rty=retry)

        report.reporter(
            msg=('STATUS: %s MESSAGE: %s REASON: %s'
                 % (resp.status, resp.msg, resp.reason)),
            prt=False,
            lvl='debug'
        )

        return dict(resp.getheaders())
示例#13
0
        def _obj_index(b_path, m_path, l_obj, f_list):
            conn.request('GET', m_path, headers=fheaders)
            resp, read = http.response_get(conn=conn, retry=retry)
            self.resp_exception(resp=resp, rty=retry)
            return_list = basic.json_encode(read)

            for obj in return_list:
                time_offset = ARGS.get('time_offset')
                if time_offset is not None:
                    # Get the last_modified data from the Object.
                    if cloud.time_delta(lmobj=time_offset) is True:
                        f_list.append(obj)
                else:
                    f_list.append(obj)

            last_obj_in_list = f_list[-1].get('name')
            if l_obj is last_obj_in_list:
                return f_list
            else:
                marker = _marker_type(base=b_path, last=last_obj_in_list)
                _obj_index(
                    b_path, marker, last_obj_in_list, f_list
                )
示例#14
0
    def container_create(self, url, container):
        """Create a container if it is not Found.

        :param url:
        :param container:
        """

        rty_count = ARGS.get('error_retry')
        for retry in basic.retryloop(attempts=rty_count,
                                     delay=5,
                                     obj=container):
            conn = http.open_connection(url=url)

            rpath = http.quoter(url=url.path, cont=container)

            # Open connection and perform operation
            with meth.operation(retry, conn):

                resp = self._header_getter(conn=conn,
                                           rpath=rpath,
                                           fheaders=self.payload['headers'],
                                           retry=retry)

                # Check that the status was a good one
                if resp.status == 404:
                    report.reporter(msg='Creating Container ==> %s' %
                                    container)

                    conn.request('PUT', rpath, headers=self.payload['headers'])
                    resp, read = http.response_get(conn=conn, retry=retry)
                    self.resp_exception(resp=resp, rty=retry)

                    report.reporter(msg='Container "%s" Created' % container)
                    return True
                else:
                    report.reporter(msg='Container "%s" Found' % container)
                    return False
示例#15
0
    def _downloader(self,
                    conn,
                    rpath,
                    fheaders,
                    lfile,
                    source,
                    retry,
                    skip=False):
        """Download a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param retry:
        :param skip:
        """

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(conn, rpath, local_f, fheaders, retry, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            conn.request('GET', rpath, headers=fheaders)
            # Open our source file and write it
            with open(local_f, 'ab') as f_name:
                resp = http.response_get(conn=conn,
                                         retry=retry,
                                         resp_only=True)
                self.resp_exception(resp=resp, rty=retry)
                if resp is None:
                    report.reporter(msg='API Response Was NONE. resp was: %s' %
                                    resp.msg,
                                    prt=True,
                                    lvl='error',
                                    log=True)
                    retry()
                else:
                    while True:
                        chunk = resp.read(2048)
                        if not chunk:
                            break
                        else:
                            f_name.write(chunk)

            report.reporter(msg=('OBJECT %s MESSAGE %s %s %s' %
                                 (rpath, resp.status, resp.reason, resp.msg)),
                            prt=False,
                            lvl='debug')

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            resp = self._header_getter(conn=conn,
                                       rpath=rpath,
                                       fheaders=fheaders,
                                       retry=retry)
            all_headers = dict(resp.getheaders())
            if all([
                    'x-object-meta-group' in all_headers, 'x-object-meta-owner'
                    in all_headers, 'x-object-meta-perms' in all_headers
            ]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True)
示例#16
0
    def _downloader(self, conn, rpath, fheaders, lfile, source, retry,
                    skip=False):
        """Download a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param retry:
        :param skip:
        """

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(conn, rpath, local_f, fheaders, retry, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            conn.request('GET', rpath, headers=fheaders)
            local_f = basic.collision_rename(file_name=local_f)

            # Open our source file and write it
            with open(local_f, 'ab') as f_name:
                resp = http.response_get(conn=conn,
                                         retry=retry,
                                         resp_only=True)
                self.resp_exception(resp=resp, rty=retry)
                if resp is None:
                    report.reporter(
                        msg='API Response Was NONE. resp was: %s' % resp.msg,
                        prt=True,
                        lvl='error',
                        log=True
                    )
                    retry()
                else:
                    while True:
                        chunk = resp.read(2048)
                        if not chunk:
                            break
                        else:
                            f_name.write(chunk)

            report.reporter(
                msg=('OBJECT %s MESSAGE %s %s %s'
                     % (rpath, resp.status, resp.reason, resp.msg)),
                prt=False,
                lvl='debug'
            )

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            resp = self._header_getter(conn=conn,
                                       rpath=rpath,
                                       fheaders=fheaders,
                                       retry=retry)
            all_headers = dict(resp.getheaders())
            if all(['x-object-meta-group' in all_headers,
                    'x-object-meta-owner' in all_headers,
                    'x-object-meta-perms' in all_headers]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True
                )