Esempio n. 1
0
    def setUp(self):
        # set up useful settings variables

        self.url = os.getenv('PITHOS_URL',
                             'https://pithos.okeanos.grnet.gr/v1')
        self.token = os.getenv('ASTAKOS_TOKEN', '')

        if self.token == '':
            print('\n\nUnable to run test suite.')
            print('Did you export the ASTAKOS_TOKEN environmental variable?')
            print('You can do this by running:')
            print('ASTAKOS_TOKEN="your_token_here" python runtests.py\n')
            sys.exit(0)

        self.account = 'd8e6f8bb-619b-4ce6-8903-89fabdca024d'
        self.container = 'pithos'
        self.syncer = pithossync.Syncer(self.url, self.token, self.account,
                                        self.container)

        self.client = PithosClient(self.url, self.token, self.account,
                                   self.container)

        # the local folder used by the tests, unavailable to the code being tested
        workspace_path = 'localworkspace'
        # the name of the remote folder within the pithos container
        remote_path = 'sync-test'

        self.workspace = self.Workspace(self, workspace_path)
        self.remote = self.Remote(self, remote_path)

        # clean up from previous test runs that may have crashed
        self.workspace.delete()
        self.remote.recursive_delete(self.remote.path)
Esempio n. 2
0
    def initialize_clients(self):
        """Initialize all the Kamaki Clients"""
        self.astakos = AstakosClient(self.auth_url, self.token)
        self.astakos.CONNECTION_RETRY_LIMIT = self.retry

        endpoints = self.astakos.authenticate()

        self.compute_url = _get_endpoint_url(endpoints, "compute")
        self.compute = ComputeClient(self.compute_url, self.token)
        self.compute.CONNECTION_RETRY_LIMIT = self.retry

        self.cyclades = CycladesClient(self.compute_url, self.token)
        self.cyclades.CONNECTION_RETRY_LIMIT = self.retry

        self.network_url = _get_endpoint_url(endpoints, "network")
        self.network = CycladesNetworkClient(self.network_url, self.token)
        self.network.CONNECTION_RETRY_LIMIT = self.retry

        self.pithos_url = _get_endpoint_url(endpoints, "object-store")
        self.pithos = PithosClient(self.pithos_url, self.token)
        self.pithos.CONNECTION_RETRY_LIMIT = self.retry

        self.image_url = _get_endpoint_url(endpoints, "image")
        self.image = ImageClient(self.image_url, self.token)
        self.image.CONNECTION_RETRY_LIMIT = self.retry
    def __init__(self, account, output):
        """Create a Kamaki instance"""
        self.account = account
        self.out = output

        self.pithos = PithosClient(
            self.account.get_service_endpoints('object-store')['publicURL'],
            self.account.token,
            self.account.user_info()['id'], CONTAINER)

        self.image = ImageClient(
            self.account.get_service_endpoints('image')['publicURL'],
            self.account.token)
Esempio n. 4
0
    def __init__(self, syncer, local, folder=None):
        self.syncer = syncer
        self.local = local
        self.meta_file = meta.LocalMetaFile(self.local)
        self.lock = lock.Lock(self)

        self.client = PithosClient(syncer.url, syncer.token, syncer.account,
                                   syncer.container)

        if folder is None:
            # working copy already init'ed
            self.meta_file.load()
            self.folder = self.meta_file.remote_dir
        else:
            # working copy not init'ed
            # the caller must call .init() or .clone() on it
            self.folder = folder
Esempio n. 5
0
    def initialize_clients(self, ignore_ssl=False):
        """Initialize all the Kamaki Clients"""

        # Path kamaki for SSL verification
        self._kamaki_ssl(ignore_ssl=ignore_ssl)

        # Initialize kamaki Clients
        self.astakos = AstakosClient(self.auth_url, self.token)
        self.astakos.CONNECTION_RETRY_LIMIT = self.retry

        self.compute_url = self.astakos.get_endpoint_url(
            ComputeClient.service_type)
        self.compute = ComputeClient(self.compute_url, self.token)
        self.compute.CONNECTION_RETRY_LIMIT = self.retry

        self.cyclades_url = self.astakos.get_endpoint_url(
            CycladesClient.service_type)
        self.cyclades = CycladesClient(self.cyclades_url, self.token)
        self.cyclades.CONNECTION_RETRY_LIMIT = self.retry

        self.block_storage_url = self.astakos.get_endpoint_url(
            CycladesBlockStorageClient.service_type)
        self.block_storage = CycladesBlockStorageClient(
            self.block_storage_url, self.token)
        self.block_storage.CONNECTION_RETRY_LIMIT = self.retry

        self.network_url = self.astakos.get_endpoint_url(
            CycladesNetworkClient.service_type)
        self.network = CycladesNetworkClient(self.network_url, self.token)
        self.network.CONNECTION_RETRY_LIMIT = self.retry

        self.pithos_url = self.astakos.get_endpoint_url(
            PithosClient.service_type)
        self.pithos = PithosClient(self.pithos_url, self.token)
        self.pithos.CONNECTION_RETRY_LIMIT = self.retry

        self.image_url = self.astakos.get_endpoint_url(
            ImageClient.service_type)
        self.image = ImageClient(self.image_url, self.token)
        self.image.CONNECTION_RETRY_LIMIT = self.retry
Esempio n. 6
0
 def list_pithos_files(self):
     """ Method for listing pithos+ files available to the user """
     auth_url = self.opts['auth_url']
     token = self.opts['token']
     try:
         auth = AstakosClient(auth_url, token)
         auth.authenticate()
     except ClientError:
         msg = 'Authentication error: Invalid Token'
         logging.error(msg)
         exit(error_fatal)
     pithos_endpoint = auth.get_endpoint_url('object-store')
     pithos_container = self.opts.get('pithos_container','pithos')
     user_id = auth.user_info['id']
     pithos_client = PithosClient(pithos_endpoint,self.opts['token'], user_id, pithos_container)
     objects = pithos_client.list_objects()
     for object in objects:
         is_dir = 'application/directory' in object.get('content_type', object.get('content-type', ''))
         is_dir = 'application/folder' in object.get('content_type', object.get('content-type', ''))
         if not is_dir:
             print u"{:>12s} \"pithos:/{:s}/{:s}\"".format(bytes_to_shorthand(object['bytes']),
                                                           pithos_container,object['name'])
Esempio n. 7
0
from kamaki.clients.pithos import PithosClient, ClientError
import logging
import os

logging.basicConfig(level=logging.DEBUG)

url = 'https://pithos.okeanos.io/v1'
account = 'd8e6f8bb-619b-4ce6-8903-89fabdca024d'
container = 'pithos'
token = os.getenv('ASTAKOS_TOKEN', '')

client = PithosClient(url, token, account, container)

client.create_directory('break-pithos')

for i in range(0, 100):
    client.object_delete('break-pithos')
    client.create_directory('break-pithos')
Esempio n. 8
0
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

from kamaki.clients.astakos import AstakosClient
from kamaki.clients.pithos import PithosClient

#  Initliaze astakos client
AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Initliaze pithos
service_type = PithosClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
pithos = PithosClient(endpoint, TOKEN)

#  Set user UUID and Container (optional)
user = astakos.authenticate()
uuid = user["access"]["user"]["id"]

pithos.account = uuid
pithos.container = "pithos"
Esempio n. 9
0
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.pithos import PithosClient

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)

#  Our data
container_name = "course_container"
user = astakos.authenticate()
uuid = user["access"]["user"]["id"]

#  Initialize a Pithos client
service_type = PithosClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
pithos = PithosClient(endpoint, TOKEN, uuid, container_name)

#  To what project is this container assigned to?
container = pithos.get_container_info(container_name)
container_project = container["x-container-policy-project"]

#  Get quota info
quotas = astakos.get_quotas()
container_quotas = quotas[container_project]["pithos.diskspace"]
usage, limit = container_quotas["usage"], container_quotas["limit"]

if usage < limit:
    print "Quotas for container {0} are OK".format(container_name)
else:
    #  We need to reassign to another project
    new_project = "a9f87654-3af2-1e09-8765-43a2df1098765"