コード例 #1
0
    def test_get_service_names(self):
        data = self.fixtures.load("_v2_0__auth.json")
        data = json.loads(data)
        service_catalog = data["access"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="2.0"
        )

        service_names = catalog.get_service_names()
        self.assertEqual(
            service_names,
            [
                "cinderv2",
                "cinderv3",
                "cloudFiles",
                "cloudFilesCDN",
                "cloudServers",
                "cloudServersOpenStack",
                "cloudServersPreprod",
                "glance",
                "neutron",
                "nova",
            ],
        )

        service_names = catalog.get_service_names(service_type="compute")
        self.assertEqual(
            service_names,
            ["cloudServers", "cloudServersOpenStack", "cloudServersPreprod", "nova"],
        )
コード例 #2
0
    def test_get_public_urls(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        public_urls = catalog.get_public_urls(service_type='object-store')
        expected_urls = ['https://storage101.lon1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111',
                         'https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111']
        self.assertEqual(public_urls, expected_urls)
コード例 #3
0
    def test_get_public_urls(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        public_urls = catalog.get_public_urls(service_type='object-store')
        expected_urls = ['https://storage101.lon1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111',
                         'https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111']
        self.assertEqual(public_urls, expected_urls)
コード例 #4
0
    def test_get_regions(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        regions = catalog.get_regions(service_type='object-store')
        self.assertEqual(regions, ['LON', 'ORD'])

        regions = catalog.get_regions(service_type='invalid')
        self.assertEqual(regions, [])
コード例 #5
0
    def test_get_service_types(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')
        service_types = catalog.get_service_types()
        self.assertEqual(service_types, ['compute', 'object-store',
                                         'rax:object-cdn'])

        service_types = catalog.get_service_types(region='ORD')
        self.assertEqual(service_types, ['rax:object-cdn'])
コード例 #6
0
    def test_get_service_types(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')
        service_types = catalog.get_service_types()
        self.assertEqual(service_types, ['compute', 'image', 'object-store',
                                         'rax:object-cdn'])

        service_types = catalog.get_service_types(region='ORD')
        self.assertEqual(service_types, ['rax:object-cdn'])
コード例 #7
0
    def test_get_regions(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        regions = catalog.get_regions(service_type='object-store')
        self.assertEqual(regions, ['LON', 'ORD'])

        regions = catalog.get_regions(service_type='invalid')
        self.assertEqual(regions, [])
コード例 #8
0
    def test_get_regions(self):
        data = self.fixtures.load("_v2_0__auth.json")
        data = json.loads(data)
        service_catalog = data["access"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="2.0"
        )

        regions = catalog.get_regions(service_type="object-store")
        self.assertEqual(regions, ["LON", "ORD"])

        regions = catalog.get_regions(service_type="invalid")
        self.assertEqual(regions, [])
コード例 #9
0
    def test_get_public_urls(self):
        data = self.fixtures.load("_v2_0__auth.json")
        data = json.loads(data)
        service_catalog = data["access"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="2.0"
        )

        public_urls = catalog.get_public_urls(service_type="object-store")
        expected_urls = [
            "https://storage101.lon1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111",
            "https://storage101.ord1.clouddrive.com/v1/MossoCloudFS_11111-111111111-1111111111-1111111",
        ]
        self.assertEqual(public_urls, expected_urls)
コード例 #10
0
    def test_parsing_auth_v2(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 6)

        entry = [e for e in entries if e.service_name == 'cloudServers'][0]
        self.assertEqual(entry.service_type, 'compute')
        self.assertEqual(entry.service_name, 'cloudServers')
        self.assertEqual(len(entry.endpoints), 1)
        self.assertEqual(entry.endpoints[0].region, None)
        self.assertEqual(entry.endpoints[0].url,
                         'https://servers.api.rackspacecloud.com/v1.0/1337')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
コード例 #11
0
    def test_parsing_auth_v2(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 8)

        entry = [e for e in entries if e.service_name == 'cloudServers'][0]
        self.assertEqual(entry.service_type, 'compute')
        self.assertEqual(entry.service_name, 'cloudServers')
        self.assertEqual(len(entry.endpoints), 1)
        self.assertEqual(entry.endpoints[0].region, None)
        self.assertEqual(entry.endpoints[0].url,
                         'https://servers.api.rackspacecloud.com/v1.0/1337')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
コード例 #12
0
    def test_parsing_auth_v3(self):
        data = self.fixtures.load('_v3__auth.json')
        data = json.loads(data)
        service_catalog = data['token']['catalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='3.x')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 6)
        entry = [e for e in entries if e.service_type == 'volume'][0]
        self.assertEqual(entry.service_type, 'volume')
        self.assertEqual(entry.service_name, None)
        self.assertEqual(len(entry.endpoints), 3)
        self.assertEqual(entry.endpoints[0].region, 'regionOne')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
        self.assertEqual(entry.endpoints[1].region, 'regionOne')
        self.assertEqual(entry.endpoints[1].endpoint_type, 'admin')
        self.assertEqual(entry.endpoints[2].region, 'regionOne')
        self.assertEqual(entry.endpoints[2].endpoint_type, 'internal')
コード例 #13
0
    def test_get_service_names(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        service_names = catalog.get_service_names()
        self.assertEqual(service_names, [
            'cloudFiles', 'cloudFilesCDN', 'cloudServers',
            'cloudServersOpenStack', 'cloudServersPreprod', 'nova'
        ])

        service_names = catalog.get_service_names(service_type='compute')
        self.assertEqual(service_names, [
            'cloudServers', 'cloudServersOpenStack', 'cloudServersPreprod',
            'nova'
        ])
コード例 #14
0
    def test_parsing_auth_v3(self):
        data = self.fixtures.load('_v3__auth.json')
        data = json.loads(data)
        service_catalog = data['token']['catalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='3.x')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 6)
        entry = [e for e in entries if e.service_type == 'volume'][0]
        self.assertEqual(entry.service_type, 'volume')
        self.assertEqual(entry.service_name, None)
        self.assertEqual(len(entry.endpoints), 3)
        self.assertEqual(entry.endpoints[0].region, 'regionOne')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
        self.assertEqual(entry.endpoints[1].region, 'regionOne')
        self.assertEqual(entry.endpoints[1].endpoint_type, 'admin')
        self.assertEqual(entry.endpoints[2].region, 'regionOne')
        self.assertEqual(entry.endpoints[2].endpoint_type, 'internal')
コード例 #15
0
    def test_parsing_auth_v1_1(self):
        data = self.fixtures.load('_v1_1__auth.json')
        data = json.loads(data)
        service_catalog = data['auth']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='1.0')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 3)

        entry = [e for e in entries if e.service_type == 'cloudFilesCDN'][0]
        self.assertEqual(entry.service_type, 'cloudFilesCDN')
        self.assertEqual(entry.service_name, None)
        self.assertEqual(len(entry.endpoints), 2)
        self.assertEqual(entry.endpoints[0].region, 'ORD')
        self.assertEqual(entry.endpoints[0].url,
                         'https://cdn2.clouddrive.com/v1/MossoCloudFS')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
        self.assertEqual(entry.endpoints[1].region, 'LON')
        self.assertEqual(entry.endpoints[1].endpoint_type, 'external')
コード例 #16
0
    def test_parsing_auth_v3(self):
        data = self.fixtures.load("_v3__auth.json")
        data = json.loads(data)
        service_catalog = data["token"]["catalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="3.x"
        )
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 6)
        entry = [e for e in entries if e.service_type == "volume"][0]
        self.assertEqual(entry.service_type, "volume")
        self.assertIsNone(entry.service_name)
        self.assertEqual(len(entry.endpoints), 3)
        self.assertEqual(entry.endpoints[0].region, "regionOne")
        self.assertEqual(entry.endpoints[0].endpoint_type, "external")
        self.assertEqual(entry.endpoints[1].region, "regionOne")
        self.assertEqual(entry.endpoints[1].endpoint_type, "admin")
        self.assertEqual(entry.endpoints[2].region, "regionOne")
        self.assertEqual(entry.endpoints[2].endpoint_type, "internal")
コード例 #17
0
    def test_parsing_auth_v2(self):
        data = self.fixtures.load("_v2_0__auth.json")
        data = json.loads(data)
        service_catalog = data["access"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="2.0"
        )
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 10)

        entry = [e for e in entries if e.service_name == "cloudServers"][0]
        self.assertEqual(entry.service_type, "compute")
        self.assertEqual(entry.service_name, "cloudServers")
        self.assertEqual(len(entry.endpoints), 1)
        self.assertIsNone(entry.endpoints[0].region)
        self.assertEqual(
            entry.endpoints[0].url, "https://servers.api.rackspacecloud.com/v1.0/1337"
        )
        self.assertEqual(entry.endpoints[0].endpoint_type, "external")
コード例 #18
0
    def test_parsing_auth_v1_1(self):
        data = self.fixtures.load('_v1_1__auth.json')
        data = json.loads(data)
        service_catalog = data['auth']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='1.0')
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 3)

        entry = [e for e in entries if e.service_type == 'cloudFilesCDN'][0]
        self.assertEqual(entry.service_type, 'cloudFilesCDN')
        self.assertEqual(entry.service_name, None)
        self.assertEqual(len(entry.endpoints), 2)
        self.assertEqual(entry.endpoints[0].region, 'ORD')
        self.assertEqual(entry.endpoints[0].url,
                         'https://cdn2.clouddrive.com/v1/MossoCloudFS')
        self.assertEqual(entry.endpoints[0].endpoint_type, 'external')
        self.assertEqual(entry.endpoints[1].region, 'LON')
        self.assertEqual(entry.endpoints[1].endpoint_type, 'external')
コード例 #19
0
    def test_get_service_names(self):
        data = self.fixtures.load('_v2_0__auth.json')
        data = json.loads(data)
        service_catalog = data['access']['serviceCatalog']

        catalog = OpenStackServiceCatalog(service_catalog=service_catalog,
                                          auth_version='2.0')

        service_names = catalog.get_service_names()
        self.assertEqual(service_names, ['cloudFiles', 'cloudFilesCDN',
                                         'cloudServers',
                                         'cloudServersOpenStack',
                                         'cloudServersPreprod',
                                         'nova'])

        service_names = catalog.get_service_names(service_type='compute')
        self.assertEqual(service_names, ['cloudServers',
                                         'cloudServersOpenStack',
                                         'cloudServersPreprod',
                                         'nova'])
コード例 #20
0
    def test_parsing_auth_v1_1(self):
        data = self.fixtures.load("_v1_1__auth.json")
        data = json.loads(data)
        service_catalog = data["auth"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="1.0"
        )
        entries = catalog.get_entries()
        self.assertEqual(len(entries), 3)

        entry = [e for e in entries if e.service_type == "cloudFilesCDN"][0]
        self.assertEqual(entry.service_type, "cloudFilesCDN")
        self.assertIsNone(entry.service_name)
        self.assertEqual(len(entry.endpoints), 2)
        self.assertEqual(entry.endpoints[0].region, "ORD")
        self.assertEqual(
            entry.endpoints[0].url, "https://cdn2.clouddrive.com/v1/MossoCloudFS"
        )
        self.assertEqual(entry.endpoints[0].endpoint_type, "external")
        self.assertEqual(entry.endpoints[1].region, "LON")
        self.assertEqual(entry.endpoints[1].endpoint_type, "external")
コード例 #21
0
    def test_get_service_types(self):
        data = self.fixtures.load("_v2_0__auth.json")
        data = json.loads(data)
        service_catalog = data["access"]["serviceCatalog"]

        catalog = OpenStackServiceCatalog(
            service_catalog=service_catalog, auth_version="2.0"
        )
        service_types = catalog.get_service_types()
        self.assertEqual(
            service_types,
            [
                "compute",
                "image",
                "network",
                "object-store",
                "rax:object-cdn",
                "volumev2",
                "volumev3",
            ],
        )

        service_types = catalog.get_service_types(region="ORD")
        self.assertEqual(service_types, ["rax:object-cdn"])
コード例 #22
0
ファイル: openstack.py プロジェクト: dimgal1/libcloud
    def _populate_hosts_and_request_paths(self):
        """
        OpenStack uses a separate host for API calls which is only provided
        after an initial authentication request.
        """
        osa = self.get_auth_class()

        if self._ex_force_auth_token:
            # If ex_force_auth_token is provided we always hit the api directly
            # and never try to authenticate.
            #
            # Note: When ex_force_auth_token is provided, ex_force_base_url
            # must be provided as well.
            self._set_up_connection_info(url=self._ex_force_base_url)
            return

        if not osa.is_token_valid():
            # Token is not available or it has expired. Need to retrieve a
            # new one.
            if self._auth_version == "2.0_apikey":
                kwargs = {"auth_type": "api_key"}
            elif self._auth_version == "2.0_password":
                kwargs = {"auth_type": "password"}
            else:
                kwargs = {}

            # pylint: disable=unexpected-keyword-arg
            osa = osa.authenticate(**kwargs)  # may throw InvalidCreds
            # pylint: enable=unexpected-keyword-arg

            self.auth_token = osa.auth_token
            self.auth_token_expires = osa.auth_token_expires
            self.auth_user_info = osa.auth_user_info

            # Pull out and parse the service catalog
            osc = OpenStackServiceCatalog(
                service_catalog=osa.urls, auth_version=self._auth_version
            )
            self.service_catalog = osc

        url = self._ex_force_base_url or self.get_endpoint()
        self._set_up_connection_info(url=url)