当前位置: 首页>>代码示例>>Python>>正文


Python AstakosClient.authenticate方法代码示例

本文整理汇总了Python中kamaki.clients.astakos.AstakosClient.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python AstakosClient.authenticate方法的具体用法?Python AstakosClient.authenticate怎么用?Python AstakosClient.authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kamaki.clients.astakos.AstakosClient的用法示例。


在下文中一共展示了AstakosClient.authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: authenticate_clients

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def authenticate_clients():
    """
    function to instantiate Clients (astakos, cyclades, compute)
    """
    try:
        astakos_client = AstakosClient(AUTHENTICATION_URL,
                                       TOKEN)
        astakos_client.authenticate()
        logging.info('Successful authentication')
    except ClientError:
        logging.info('\n Failed to authenticate user token')
        print 'Failed to authenticate user token'
    try:
        endpoints = astakos_client.get_endpoints()
        cyclades_base_url = parse_astakos_endpoints(endpoints,
                                                  'cyclades_compute')
        cyclades_network_base_url = parse_astakos_endpoints(endpoints,
                                                          'cyclades_network')

    except ClientError:
        print('Failed to get endpoints for cyclades')
    try:
        cyclades_client = CycladesClient(cyclades_base_url, TOKEN)
        compute_client = ComputeClient(cyclades_base_url, TOKEN)
        network_client = CycladesNetworkClient(cyclades_network_base_url,
                                               TOKEN)
        return cyclades_client, compute_client, network_client, astakos_client
    except ClientError:
        print 'Failed to initialize Cyclades client'
开发者ID:themiszamani,项目名称:kamaki-examples,代码行数:31,代码来源:createvm.py

示例2: check_credentials

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
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
开发者ID:themiszamani,项目名称:e-science,代码行数:13,代码来源:okeanos_utils.py

示例3: check_credentials

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def check_credentials(auth_url, token):

    print(' Test the credentials')
    try:
        auth = AstakosClient(auth_url, token)
        auth.authenticate()
    except ClientError:
        print('Authentication failed with url %s and token %s' % (
              auth_url, token))
        raise
    print 'Authentication verified'
    return auth
开发者ID:TheoniPetropoulou,项目名称:e-science-1,代码行数:14,代码来源:create_cluster.py

示例4: check_user_credentials

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
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
开发者ID:nvrionis,项目名称:e-science,代码行数:15,代码来源:authenticate_user.py

示例5: check_credentials

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def check_credentials(token, auth_url='https://accounts.okeanos.grnet.gr'
                      '/identity/v2.0'):
    '''Identity,Account/Astakos. Test authentication credentials'''
    logging.log(REPORT, ' Test the credentials')
    try:
        auth = AstakosClient(auth_url, token)
        auth.authenticate()
    except ClientError:
        logging.error('Authentication failed with url %s and token %s' % (
                      auth_url, token))
        sys.exit(error_authentication)
    logging.log(REPORT, ' Authentication verified')
    return auth
开发者ID:MariosLogothetis,项目名称:e-science,代码行数:15,代码来源:ansible_create_yarn_cluster.py

示例6: authenticate

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
    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
开发者ID:vpapaioannou,项目名称:IReS-Platform,代码行数:21,代码来源:okeanos.py

示例7: list_pithos_files

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
 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', ''))
         if not is_dir:
             print u"{:>12s} \"pithos:/{:s}/{:s}\"".format(bytes_to_shorthand(object['bytes']),
                                                           pithos_container,object['name'])
开发者ID:themiszamani,项目名称:e-science,代码行数:23,代码来源:orka.py

示例8: Clients

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
class Clients(object):
    """Our kamaki clients"""
    auth_url = None
    token = None
    # Astakos
    astakos = None
    retry = CONNECTION_RETRY_LIMIT
    # Compute
    compute = None
    compute_url = None
    # Cyclades
    cyclades = None
    # Network
    network = None
    network_url = None
    # Pithos
    pithos = None
    pithos_url = None
    # Image
    image = None
    image_url = None

    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
开发者ID:antonis-m,项目名称:synnefo,代码行数:49,代码来源:common.py

示例9: check_auth_token

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def check_auth_token(auth_token, auth_url=None):
    """
    Checks the validity of a user authentication token.

    :param auth_token: User authentication token
    :param auth_url: Authentication url
    :return: tuple(Success status, details)
    """

    if not auth_url:
        auth_url = "https://accounts.okeanos.grnet.gr/identity/v2.0"
    patch_certs()
    cl = AstakosClient(auth_url, auth_token)
    try:
        user_info = cl.authenticate()
    except ClientError as ex:
        if ex.message == 'UNAUTHORIZED':
            return False, ex.details
        else:
            raise
    return True, user_info
开发者ID:grnet,项目名称:okeanos-LoD,代码行数:23,代码来源:utils.py

示例10: SynnefoCI

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
class SynnefoCI(object):
    """SynnefoCI python class"""

    def __init__(self, config_file=None, build_id=None, cloud=None):
        """ Initialize SynnefoCI python class

        Setup logger, local_dir, config and kamaki
        """
        # Setup logger
        self.logger = logging.getLogger('synnefo-ci')
        self.logger.setLevel(logging.DEBUG)

        handler1 = logging.StreamHandler(sys.stdout)
        handler1.setLevel(logging.DEBUG)
        handler1.addFilter(_InfoFilter())
        handler1.setFormatter(_MyFormatter())
        handler2 = logging.StreamHandler(sys.stderr)
        handler2.setLevel(logging.WARNING)
        handler2.setFormatter(_MyFormatter())

        self.logger.addHandler(handler1)
        self.logger.addHandler(handler2)

        # Get our local dir
        self.ci_dir = os.path.dirname(os.path.abspath(__file__))
        self.repo_dir = os.path.dirname(self.ci_dir)

        # Read config file
        if config_file is None:
            config_file = os.path.join(self.ci_dir, DEFAULT_CONFIG_FILE)
        config_file = os.path.abspath(config_file)
        self.config = ConfigParser()
        self.config.optionxform = str
        self.config.read(config_file)

        # Read temporary_config file
        self.temp_config_file = \
            os.path.expanduser(self.config.get('Global', 'temporary_config'))
        self.temp_config = ConfigParser()
        self.temp_config.optionxform = str
        self.temp_config.read(self.temp_config_file)
        self.build_id = build_id
        if build_id is not None:
            self.logger.info("Will use \"%s\" as build id" %
                             _green(self.build_id))

        # Set kamaki cloud
        if cloud is not None:
            self.kamaki_cloud = cloud
        elif self.config.has_option("Deployment", "kamaki_cloud"):
            kamaki_cloud = self.config.get("Deployment", "kamaki_cloud")
            if kamaki_cloud == "":
                self.kamaki_cloud = None
        else:
            self.kamaki_cloud = None

        # Initialize variables
        self.fabric_installed = False
        self.kamaki_installed = False
        self.cyclades_client = None
        self.network_client = None
        self.compute_client = None
        self.image_client = None
        self.astakos_client = None

    def setup_kamaki(self):
        """Initialize kamaki

        Setup cyclades_client, image_client and compute_client
        """

        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")
#.........这里部分代码省略.........
开发者ID:apyrgio,项目名称:synnefo,代码行数:103,代码来源:utils.py

示例11: main

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def main():
    """Parse arguments, use kamaki to create cluster, setup using ansible playbooks"""

    (opts, args) = parse_arguments(sys.argv[1:])

    global CYCLADES, TOKEN, my_vnat_network, my_network_client

    AUTHENTICATION_URL = opts.cyclades
    TOKEN = opts.token

    # Cleanup stale servers from previous runs
    if opts.show_stale:
        cleanup_servers(prefix=opts.prefix, delete_stale=opts.delete_stale)
        return 0

    # Initialize a kamaki instance, get endpoints
    user = AstakosClient(AUTHENTICATION_URL, TOKEN)
    my_accountData = user.authenticate()
    endpoints = user.get_endpoints() 
    cyclades_endpoints = user.get_endpoints('compute')
    cyclades_base_url = parseAstakosEndpoints(endpoints, 'cyclades_compute')
    cyclades_network_base_url = parseAstakosEndpoints(endpoints, 'cyclades_network')
    my_cyclades_client = CycladesClient(cyclades_base_url, TOKEN)
    my_compute_client = ComputeClient(cyclades_base_url, TOKEN)
    my_network_client = CycladesNetworkClient(cyclades_network_base_url, TOKEN) 

    my_vnat_network = {}

    # check if 'Hadoop' vnat is created...
    hadoop_vnat_created = False
    my_network_dict = my_network_client.list_networks()
    for n in my_network_dict:
        if n['name'] == 'Hadoop': 
            hadoop_vnat_created = True
            my_vnat_network = n

    # ...else create it
    if hadoop_vnat_created == False:
        log.info("Creating vNAT")
        my_vnat_network = my_network_client.create_network(type='MAC_FILTERED', name='Hadoop');
        my_subnet = my_network_client.create_subnet(network_id=my_vnat_network['id'], cidr='192.168.0.0/24');

    cnt = int(opts.clustersize)	# calculate size of cluster into 'cnt'
    # Initialize
    nodes = []
    masterName = ''

    # Create a file to store the root password for later use
    if not os.path.exists(opts.hadoop_dir+'/bak'):
        os.makedirs(opts.hadoop_dir+'/bak')
    pass_fname = opts.hadoop_dir+'/bak/adminPass'+str(datetime.now())[:19].replace(' ', '')
    adminPass_f = open(pass_fname, 'w')

    initialClusterSize = 0
    server = {}
    if opts.extend == False:
        # Create master node (0th node)
        server = create_machine(opts, my_cyclades_client, 0)
        if server == {}:
            return
    else:
        servers = my_cyclades_client.list_servers(detail=True)
        cluster = [s for s in servers if s["name"].startswith(opts.prefix)]
        initialClusterSize = len(cluster)
        if initialClusterSize==0:
            log.info("Cluster cannot be expanded: it does not exist.")
            return

    servername = "%s-0" % (opts.prefix)
    masterName = servername
    nodes.append(server)

    # Create slave (worker) nodes
    if cnt>1 or opts.extend:
        startingOffset = 1
        if opts.extend: startingOffset = initialClusterSize
        for i in xrange(startingOffset, initialClusterSize+cnt):
            server = {}
            server = create_machine(opts, my_cyclades_client, i)
            if server == {}:
                return;
            nodes.append(server)
            servername = "%s-%d" % (opts.prefix, i)
            # Write the root password to a file
            adminPass_f.write('machine = %s, password = %s\n' % (servername, server['adminPass']))

    adminPass_f.close()

    # Setup Hadoop files and settings on all cluster nodes
    # Create the 'cluster' dictionary out of servers, with only Hadoop-relevant keys (name, ip, integer key)
    servers = my_cyclades_client.list_servers(detail=True)
    cluster = [s for s in my_cyclades_client.list_servers(detail=True) if s["name"].startswith(opts.prefix)]
    cluster0 = [(s["name"], s["attachments"], int(s["name"][s["name"].find('-')+1:])) for s in cluster]
    cluster0 = sorted(cluster0, key=lambda cluster0: cluster0[2])
    cluster = [(cluster0[0][0], cluster0[0][1][2]["ipv4"], cluster0[0][2])]	# master IP, different index 
    cluster2 = [(s[0], s[1][1]['ipv4'], int(s[2])) for s in cluster0[1:]]	# slave IPs
    cluster += cluster2

    # Prepare Ansible-Hadoop config files (hosts, conf/slaves. vnat/etchosts)
    hosts = open(opts.hadoop_dir+'/hosts', 'w')
#.........这里部分代码省略.........
开发者ID:themiszamani,项目名称:hadoop,代码行数:103,代码来源:hadoop_cluster_vnat.py

示例12: Astakos

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
class Astakos(livetest.Generic):
    def setUp(self):
        self.cloud = 'cloud.%s' % self['testcloud']
        self.client = AstakosClient(
            self[self.cloud, 'url'], self[self.cloud, 'token'])
        with open(self['astakos', 'details']) as f:
            self._astakos_details = eval(f.read())

    def test_authenticate(self):
        self._test_0010_authenticate()

    def _test_0010_authenticate(self):
        r = self.client.authenticate()
        self.assert_dicts_are_equal(r, self._astakos_details)

    def test_get_services(self):
        self._test_0020_get_services()

    def _test_0020_get_services(self):
        for args in (tuple(), (self[self.cloud, 'token'],)):
            r = self.client.get_services(*args)
            services = self._astakos_details['access']['serviceCatalog']
            self.assertEqual(len(services), len(r))
            for i, service in enumerate(services):
                self.assert_dicts_are_equal(r[i], service)
        self.assertRaises(ClientError, self.client.get_services, 'wrong_token')

    def test_get_service_details(self):
        self._test_0020_get_service_details()

    def _test_0020_get_service_details(self):
        parsed_services = dict()
        for args in product(
                self._astakos_details['access']['serviceCatalog'],
                ([tuple(), (self[self.cloud, 'token'],)])):
            service = args[0]
            if service['type'] in parsed_services:
                continue
            r = self.client.get_service_details(service['type'], *args[1])
            self.assert_dicts_are_equal(r, service)
            parsed_services[service['type']] = True
        self.assertRaises(
            ClientError, self.client.get_service_details, 'wrong_token')

    def test_get_service_endpoints(self):
        self._test_0020_get_service_endpoints()

    def _test_0020_get_service_endpoints(self):
        parsed_services = dict()
        for args in product(
                self._astakos_details['access']['serviceCatalog'],
                ([], [self[self.cloud, 'token']])):
            service = args[0]
            if service['type'] in parsed_services:
                continue
            for endpoint, with_id in product(
                    service['endpoints'], (True, False)):
                vid = endpoint['versionId'] if (
                    with_id and endpoint['versionId']) else None
                end_args = [service['type'], vid] + args[1]
                r = self.client.get_service_endpoints(*end_args)
                self.assert_dicts_are_equal(r, endpoint)
            parsed_services[service['type']] = True
        self.assertRaises(
            ClientError, self.client.get_service_endpoints, 'wrong_token')

    def test_user_info(self):
        self._test_0020_user_info()

    def _test_0020_user_info(self):
        self.assertTrue(set([
            'roles',
            'name',
            'id']).issubset(self.client.user_info().keys()))

    def test_get(self):
        self._test_0020_get()

    def _test_0020_get(self):
        for term in ('id', 'name'):
            self.assertEqual(
                self.client.term(term, self[self.cloud, 'token']),
                self['astakos', term] or '')

    def test_list_users(self):
        self.client.authenticate()
        self._test_0020_list_users()

    def _test_0020_list_users(self):
        terms = set(['name', 'id'])
        uuid = 0
        for r in self.client.list_users():
            self.assertTrue(terms.issubset(r.keys()))
            self.assertTrue(uuid != r['id'] if uuid else True)
            uuid = r['id']
开发者ID:Erethon,项目名称:kamaki,代码行数:97,代码来源:astakos.py

示例13: CloudClient

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
class CloudClient(object):

    clients_map_override = {
        'cyclades': {'endpoint': 'compute'}
    }

    clients_override = {
        'network': 'cyclades_network'
    }

    def __init__(self, config, cloud=None, debug=False):
        _setup_logging(debug, debug)

        self.config = kamaki_config.Config(config)
        self.cloud = cloud

        if not self.cloud:
            self.cloud = self.config.get("global", "default_cloud")

        self.ignore_ssl = \
            self.config.get("global", "ignore_ssl").lower() == "on"
        self.ca_certs = \
            self.config.get("global", "ca_certs")
        https.patch_ignore_ssl(self.ignore_ssl)
        if self.ca_certs is not None:
            https.patch_with_certs(self.ca_certs)
        self.auth_url = self.config.get_cloud(self.cloud, "url")
        self.token = self.config.get_cloud(self.cloud, "token")
        self.auth_client = AstakosClient(self.auth_url, self.token)
        self.endpoints = None  # lazyness

    def fill_endpoints(self):
        self.endpoints = self.auth_client.authenticate()

    def get_cli(self, name):
        name = self.clients_override.get(name, name)
        if not self.endpoints:
            self.fill_endpoints()

        ns = name.split("_")[0].lower()
        normalized = name.replace("_", " ").title().replace(" ", "")
        import_path = self.clients_map_override.get(name, {}).get('module',
                                                                  None)
        if not import_path:
            import_path = 'kamaki.clients.%s.%s' % (ns, normalized + 'Client')

        module_name = ".".join(import_path.split(".")[:-1])
        cli_name = import_path.split(".")[-1]
        module = importlib.import_module(module_name)

        endpoint_type = self.clients_map_override.get(
            name, {}).get('endpoint', ns)
        try:
            catalog = parse_endpoints(self.endpoints, ep_type=endpoint_type)
        except NoEndpoints as e:
            if "_" not in name:
                raise e
            endpoint_type = name.split("_")[1]
            catalog = parse_endpoints(self.endpoints, ep_type=endpoint_type)

        endpoint = catalog[0]['endpoints'][0]['publicURL']
        return module.__dict__[cli_name](endpoint, self.token)

    def __getattr__(self, name):
        if name not in self.__dict__:
            return self.get_cli(name)
        return object.__getattribute__(self, name)
开发者ID:vinilios,项目名称:snfinv,代码行数:69,代码来源:snfinv.py

示例14: main

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def main():
    #authenticate to Astakos
    print"---------------------------------------------------"
    print"******* Authenticating to Astakos******************"
    print"---------------------------------------------------"
    try:
        my_astakos_client = AstakosClient(AUTHENTICATION_URL,
                                          TOKEN)
        my_accountData = my_astakos_client.authenticate()
        ACCOUNT_UUID = my_accountData['access']['user']['id']
        print "Status: Authenticated"
    except ClientError:
        print"Failed to authenticate user token"

    print"\n"
    print"---------------------------------------------------"
    print"**********Getting Endpoints for pithos*************"
    print"---------------------------------------------------"
    #get endpoint url
    try:
        endpoints = my_astakos_client.get_service_endpoints('object-store')
        PITHOS_URL = endpoints['publicURL']
        print "The public URL:", PITHOS_URL
    except ClientError:
        print "Failed to get endpoints for pithos"

    print"\n"
    print"---------------------------------------------------"
    print"**********Authenticating to Pithos*****************"
    print"---------------------------------------------------"
    #Initialize pithos client
    try:
        pithos = PithosClient(PITHOS_URL, TOKEN)
        pithos.account = ACCOUNT_UUID
        pithos.container = ''
    except ClientError:
        print "Failed to initialize Pithos+ client"

    print"\n"
    print"---------------------------------------------------"
    print"**********LIST ALL CONTAINERS IN YOUR ACCOUNT******"
    print"---------------------------------------------------"
    #list all containers
    try:
        container_list = pithos.list_containers()
        containers = parse_containers(container_list)
        ContNums = len(containers)
        print "The number of Containers in your account:", ContNums
        print "The containers are"
        print ','.join(containers)
    except ClientError:
        print"Error in container list"

    print"\n"
    print"---------------------------------------------------"
    print"******LIST OBJECTS OF A FOLDER IN A CONTAINER******"
    print"---------------------------------------------------"
    #list all containers
    try:
        print_container_objects(pithos, YOUR_CONTAINER,
                              prefixName=YOUR_FOLDER_PATH)
    except ClientError:
        print"Error in listing folder objects"

    print"\n"
    print"---------------------------------------------------"
    print"**********Print objects for all containers*********"
    print"---------------------------------------------------"

    try:
        for i in range(len(containers)):
            print_container_objects(pithos, containers[i])
    except ClientError as e:
        print('Error: %s' % e)
        if e.status:
            print('- error code: %s' % e.status)
        if e.details:
            for detail in e.details:
                print('- %s' % detail)

    #  Create and set a different container than pithos
    print "Create a new container - my container"
    CONTAINER = 'my container'
    pithos.create_container(CONTAINER)
    pithos.container = CONTAINER

    print"\n"
    print"---------------------------------------------------"
    print"**********UPLOAD AND DOWNLOAD**********************"
    print"---------------------------------------------------"
    """
    B. UPLOAD AND DOWNLOAD
    """
    print "Upload a small file to pithos"
    #  Upload a small file
    print './test/'+SMALLFILE
    with open('./test/'+SMALLFILE) as f:
        pithos.upload_object(SMALLFILE, f)

    print "Download a small file from pithos and store to string"
#.........这里部分代码省略.........
开发者ID:themiszamani,项目名称:kamaki-examples,代码行数:103,代码来源:pithos.py

示例15: main

# 需要导入模块: from kamaki.clients.astakos import AstakosClient [as 别名]
# 或者: from kamaki.clients.astakos.AstakosClient import authenticate [as 别名]
def main():
    """Parse arguments, use kamaki to create cluster, setup using ssh"""

    (opts, args) = parse_arguments(sys.argv[1:])

    global CYCLADES, TOKEN

    AUTHENTICATION_URL = opts.cyclades
    TOKEN = opts.token

    # Cleanup stale servers from previous runs
    if opts.show_stale:
        cleanup_servers(prefix=opts.prefix, delete_stale=opts.delete_stale)
        return 0

    # Initialize a kamaki instance, get endpoints
    user = AstakosClient(AUTHENTICATION_URL, TOKEN)
    my_accountData = user.authenticate()
    endpoints = user.get_endpoints() 
    cyclades_endpoints = user.get_endpoints('compute')
    cyclades_base_url = parseAstakosEndpoints(endpoints,'cyclades_compute')
    cyclades_network_base_url = parseAstakosEndpoints(endpoints,'cyclades_network')
    my_cyclades_client = CycladesClient(cyclades_base_url, TOKEN)
    my_compute_client = ComputeClient(cyclades_base_url, TOKEN)
    my_network_client = CycladesNetworkClient(cyclades_network_base_url, TOKEN) 

    cnt = int(opts.clustersize)	# calculate size of cluster into 'cnt'
    # Initialize
    nodes = []
    masterName = ''
    # Create a file to store the root password for later use
    pass_fname = opts.hadoop_dir+'/bak/adminPass'+str(datetime.now())[:19].replace(' ', '')
    adminPass_f = open(pass_fname, 'w')

    myNetworks = my_network_client.list_networks();  
    NetWork_free = parseNetwork(myNetworks,'public');
    myIp = my_network_client.create_floatingip(NetWork_free);  
    LastIp = myIp.get("floating_ip_address")

    initialClusterSize = 0
    server = {}
    if opts.extend == False:
        # Create master node (0th node)
        server = create_machine(opts, my_cyclades_client, 0)
        if server == {}:
            return
    else:
        servers = my_cyclades_client.list_servers(detail=True)
        cluster = [s for s in servers if s["name"].startswith(opts.prefix)]
        initialClusterSize = len(cluster)
        if initialClusterSize==0:
            log.info("Cluster cannot be expanded: it does not exist.")
            return

    servername = "%s-0" % (opts.prefix)
    masterName = servername
    nodes.append(server)

    # Create slave (worker) nodes
    if cnt>1 or opts.extend:
        startingOffset = 1
        if opts.extend: startingOffset = initialClusterSize
        for i in xrange(startingOffset, initialClusterSize+cnt):
            server = {}
            server = create_machine(opts, my_cyclades_client, i)
            if server == {}:
                return;
            nodes.append(server)
            servername = "%s-%d" % (opts.prefix, i)
            # Write the root password to a file
            adminPass_f.write('machine = %s, password = %s\n' % (servername, server['adminPass']))

    adminPass_f.close()

    # Setup Hadoop files and settings on all cluster nodes
    # Create the 'cluster' dictionary out of servers, with only Hadoop-relevant keys (name, ip, integer key)
    servers = my_cyclades_client.list_servers(detail=True)
    cluster = [s for s in my_cyclades_client.list_servers(detail=True) if s["name"].startswith(opts.prefix)]
    cluster = [(s["name"], s["attachments"][1]["ipv4"], int(s["name"][s["name"].find('-')+1:])) for s in cluster]
    cluster = sorted(cluster, key=lambda cluster: cluster[2])

    # Prepare Ansible-Hadoop config files (hosts, conf/slaves)
    hosts = open(opts.hadoop_dir+'/hosts', 'w')
    hosts.write('[master]\n')
    for i in xrange(0, initialClusterSize+cnt):
        for s in cluster:
            if s[0] == opts.prefix+"-"+str(i):
                if s[0] == masterName:
                    hosts.write(s[1]+'\n\n'+'[slaves]\n')
                else:
                    hosts.write(s[1]+'\n')
    hosts.close()

    slaves = open(opts.hadoop_dir+'/conf/slaves', 'w')
    for s in cluster[1:]:
        slaves.write(s[1]+'\n')
    slaves.close()

    # Execute respective ansible playbook
    if (opts.extend==False):
#.........这里部分代码省略.........
开发者ID:themiszamani,项目名称:hadoop,代码行数:103,代码来源:hadoop_cluster.py


注:本文中的kamaki.clients.astakos.AstakosClient.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。