Beispiel #1
0
    def __init__(self,
                 token,
                 authURL='https://accounts.okeanos.grnet.gr/identity/v2.0'):
        """
        :type authURL: str
        :type token: str
        """
        from kamaki.clients.utils import https
        https.patch_ignore_ssl()

        self.authURL = authURL
        self.token = token
        self.cycladesServiceType = CycladesClient.service_type
        self.blockStorageServiceType = CycladesBlockStorageClient.service_type
        self.astakosClient = AstakosClient(self.authURL, self.token)
        endpointF = self.astakosClient.get_service_endpoints
        self.cycladesEndpoint = endpointF(
            self.cycladesServiceType)[u'publicURL']
        self.cycladesClient = CycladesClient(self.cycladesEndpoint, self.token)
        self.blockStorageEndpoint = endpointF(
            self.blockStorageServiceType)[u'publicURL']
        self.blockStorageClient = CycladesBlockStorageClient(
            self.blockStorageEndpoint, token)

        flavorsById = {}
        flavorsByName = {}
        for flavor in self.cycladesClient.list_flavors():
            _id = flavor[u'id']
            name = flavor[u'name']
            flavorsById[_id] = name
            flavorsByName[name] = _id
        self.flavorsById = flavorsById
        self.flavorsByName = flavorsByName
def ADD_VM(url, token, name, project):

    #  create a new vm

    astakos = AstakosClient(url, token, name)

    service_type = CycladesComputeClient.service_type
    endpoint = astakos.get_endpoint_url(service_type)
    compute = CycladesComputeClient(endpoint, token)

    vm_name = name
    flavor = '260'
    image = 'eca2f4ef-b428-4096-a47d-29ddf5ed68d9'

    # server = compute.create_server(name=vm_name, flavor_id=flavor, image_id=image)

    server = compute.create_server(name=vm_name,
                                   key_name='cluster key',
                                   flavor_id=flavor,
                                   image_id=image,
                                   project_id=project)
    print(server['status'])

    with open(vm_name + '.info', "w") as f:
        for s in server:
            f.write(s)

    active = compute.wait_server_until(server['id'], 'ACTIVE')
    if active != 'ACTIVE':
        print('Waiting for server to build...')
Beispiel #3
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
Beispiel #4
0
def get_user_id(token):
    """Check kamaki and returns user uuid from matching ~okeanos token"""
    auth = AstakosClient(auth_url, token)
    try:
        logging.info(' Get the uuid')
        uuid = auth.user_info['id']
        return uuid
    except ClientError:
        msg = 'Failed to get uuid from identity server'
        raise ClientError(msg)
    def create_account(url, token):
        """Given a valid (URL, tokens) pair this method returns an Astakos
        client instance
        """
        client = AstakosClient(url, token)
        try:
            client.authenticate()
        except ClientError:
            return None

        return client
Beispiel #6
0
def check_credentials(token, auth_url=auth_url):
    """Identity,Account/Astakos. Test authentication credentials"""
    logging.log(REPORT, ' Test the credentials')
    try:
        auth = AstakosClient(auth_url, token)
        auth.authenticate()
    except ClientError:
        msg = ' Authentication failed with url %s and token %s'\
            % (auth_url, token)
        raise ClientError(msg, error_authentication)
    return auth
Beispiel #7
0
def check_user_credentials(token, auth_url='https://accounts.okeanos.grnet.gr'
                      '/identity/v2.0'):
    """Identity,Account/Astakos. Test ~okeanos authentication credentials"""
    logging.info(' Test the credentials')
    try:
        auth = AstakosClient(auth_url, token)
        auth.authenticate()
        logging.info(' Authentication verified')
        return AUTHENTICATED
    except ClientError:
        logging.error('Authentication failed with url %s and token %s' % (
                      auth_url, token))
        return NOT_AUTHENTICATED
def REMOVE_VM(url, token, server):

    astakos = AstakosClient(url, token)
    service_type = CycladesComputeClient.service_type
    endpoint = astakos.get_endpoint_url(service_type)
    compute = CycladesComputeClient(endpoint, token)

    # find server id
    s = compute.list_servers(name=server)
    for i in s:
        if i['name'] == server:
            id = i['id']
            print(id)
            compute.delete_server(id)
Beispiel #9
0
    def setup_kamaki(self):
        """Initialize kamaki

        Setup cyclades_client, image_client and compute_client
        """

        # Patch kamaki for SSL verification
        _kamaki_ssl(ignore_ssl=IGNORE_SSL)

        config = kamaki_config.Config()
        if self.kamaki_cloud is None:
            try:
                self.kamaki_cloud = config.get("global", "default_cloud")
            except AttributeError:
                # Compatibility with kamaki version <=0.10
                self.kamaki_cloud = config.get("global", "default_cloud")

        self.logger.info("Setup kamaki client, using cloud '%s'.." %
                         self.kamaki_cloud)
        auth_url = config.get_cloud(self.kamaki_cloud, "url")
        self.logger.debug("Authentication URL is %s" % _green(auth_url))
        token = config.get_cloud(self.kamaki_cloud, "token")
        # self.logger.debug("Token is %s" % _green(token))

        self.astakos_client = AstakosClient(auth_url, token)
        endpoints = self.astakos_client.authenticate()

        cyclades_url = get_endpoint_url(endpoints, "compute")
        self.logger.debug("Cyclades API url is %s" % _green(cyclades_url))
        self.cyclades_client = CycladesClient(cyclades_url, token)
        self.cyclades_client.CONNECTION_RETRY_LIMIT = 2

        network_url = get_endpoint_url(endpoints, "network")
        self.logger.debug("Network API url is %s" % _green(network_url))
        self.network_client = CycladesNetworkClient(network_url, token)
        self.network_client.CONNECTION_RETRY_LIMIT = 2

        image_url = get_endpoint_url(endpoints, "image")
        self.logger.debug("Images API url is %s" % _green(image_url))
        self.image_client = ImageClient(cyclades_url, token)
        self.image_client.CONNECTION_RETRY_LIMIT = 2

        compute_url = get_endpoint_url(endpoints, "compute")
        self.logger.debug("Compute API url is %s" % _green(compute_url))
        self.compute_client = ComputeClient(compute_url, token)
        self.compute_client.CONNECTION_RETRY_LIMIT = 2
Beispiel #10
0
 def _get_pithos_client(self, auth_url, token, container):
     try:
         astakos = AstakosClient(auth_url, token)
     except ClientError:
         logger.error("Failed to authenticate user token")
         raise
     try:
         PITHOS_URL = astakos.get_endpoint_url(
             AgkyraPithosClient.service_type)
     except ClientError:
         logger.error("Failed to get endpoints for Pithos")
         raise
     try:
         account = astakos.user_info['id']
         return AgkyraPithosClient(PITHOS_URL, token, account, container)
     except ClientError:
         logger.error("Failed to initialize Pithos client")
         raise
Beispiel #11
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
Beispiel #12
0
    def authenticate(self, authentication=None):
        """

        :param authentication:
        :return:
        """
        if self.__cyclades is not None:
            return True
        try:
            authcl = AstakosClient(authentication['URL'],
                                   authentication['TOKEN'])
            authcl.authenticate()
            self.__cyclades = CycladesClient(
                authcl.get_service_endpoints('compute')['publicURL'],
                authentication['TOKEN'])
            self.__network_client = CycladesNetworkClient(
                authcl.get_service_endpoints('network')['publicURL'],
                authentication['TOKEN'])
        except ClientError:
            stderr.write('Connector initialization failed')
            return False
        return True
Beispiel #13
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'])
Beispiel #14
0
 def set_astakos_client(cls, auth_url, token):
     """Foo"""
     cls.astakos_client = AstakosClient(auth_url, token)
Beispiel #15
0
# 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.image import ImageClient

AUTHENTICATION_URL = "https://astakos.example.com/identity/v2.0"
TOKEN = "User-Token"
astakos = AstakosClient(AUTHENTICATION_URL, TOKEN)
user = astakos.authenticate()
uuid = user["access"]["user"]["id"]

service_type = ImageClient.service_type
endpoint = astakos.get_endpoint_url(service_type)
image = ImageClient(endpoint, TOKEN)

#  Get all images owned/registered by me
images = filter(lambda img: img["owner"] == uuid, image.list_public())

print "My images:\n"
for i in images:
    print "\t{name} ({location})".format(name=i["name"],
                                         location=i["location"])
Beispiel #16
0
from kamaki.clients.astakos import AstakosClient
from kamaki.clients.astakos import getLogger
from kamaki.clients.cyclades import CycladesClient, CycladesNetworkClient
#http://www.synnefo.org/docs/kamaki/latest/developers/code.html#the-client-api-ref
from sys import stderr
from os.path import abspath
from base64 import b64encode
from lib.persistance_module import *
from logging import ERROR

USER = "******"

#retrieve the credentials for the specified users
AUTHENTICATION_URL, TOKEN = get_credentials(USER)

synnefo_user = AstakosClient(AUTHENTICATION_URL, TOKEN)
synnefo_user.logger.setLevel(ERROR)
getLogger().setLevel(ERROR)

cyclades_endpoints = synnefo_user.get_service_endpoints("compute")
CYCLADES_URL = cyclades_endpoints['publicURL']
cyclades_client = CycladesClient(CYCLADES_URL, TOKEN)
cyclades_net_client = CycladesNetworkClient(CYCLADES_URL, TOKEN)


pub_keys_path = 'keys/just_a_key.pub'
priv_keys_path = 'keys/just_a_key'


#creates a "personality"
def personality(username):
from slipstream_okeanos import OkeanosNativeClient
from slipstream_okeanos import runCommandOnHost

https.patch_ignore_ssl()

authURL = "https://accounts.okeanos.grnet.gr/identity/v2.0"
X_AUTH_TOKEN_NAME = 'X_AUTH_TOKEN'
token = ENV[X_AUTH_TOKEN_NAME]

projectId = '464eb0e7-b556-4fc7-8afb-d590feebaad8'
serverId = '660580'

cycladesServiceType = CycladesClient.service_type
blockStorageServiceType = CycladesBlockStorageClient.service_type

ac = AstakosClient(authURL, token)

cycladesURL = ac.get_endpoint_url(cycladesServiceType)
cc = CycladesClient(cycladesURL, token)

blockStorageURL = ac.get_endpoint_url(blockStorageServiceType)
bsc = CycladesBlockStorageClient(blockStorageURL, token)

onc = OkeanosNativeClient(token, authURL)

print "cycladesURL = %s" % cycladesURL
print "blockStorageURL = %s" % blockStorageURL
print "ac = %s" % ac
print "cc = %s" % cc
print "bsc = %s" % bsc
print "onc = %s" % onc
Beispiel #18
0
from kamaki.clients.utils import https
from soi.config import AUTH_URL, CA_CERTS

https.patch_with_certs(CA_CERTS)
try:
    from soi.config import IGNORE_SSL
    if IGNORE_SSL:
        https.patch_ignore_ssl()
except ImportError:
    pass

import webob.exc

#  endpoints are offered auth-free, so no need for an admin token
ADMIN_TOKEN = ''
auth = AstakosClient(AUTH_URL, ADMIN_TOKEN)

endpoints = {'identity': AUTH_URL}
client_classes = {'identity': AstakosClient}

for cls in (CycladesComputeClient, CycladesNetworkClient,
            CycladesBlockStorageClient):
    service_type = cls.service_type
    endpoints[service_type] = auth.get_endpoint_url(service_type)
    client_classes[service_type] = cls


def handle_exceptions(f):
    """Run a method, raise Synnefo errors as snf-occi exceptions"""
    def wrapper(*args, **kwargs):
        try: