php-opencloud / openstack

PHP SDK for OpenStack clouds
Apache License 2.0
221 stars 148 forks source link

Endpoint URL could not be found in the catalog for this service #91

Open tflament opened 8 years ago

tflament commented 8 years ago

Hello,

I have a problem with that authentification code:

require 'vendor/autoload.php';

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'password' => '{password}'
    ],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);

I change all these settings to my configuration.

Return to me that errror : When authenticating with a username, you must also provide either the domain name or domain ID to which the user belongs to. Alternatively, if you provide a user ID instead, you do not need to provide domain information.

So i changed to that one code adding domain information at the user array :

$openstack = new OpenStack\OpenStack([
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'domain'    => ['id' => 'default'],
        'password' => '{password}'
    ],
    'scope'   => ['project' => ['id' => '{projectId}']]
]);

But i got that error now : Endpoint URL could not be found in the catalog for this service. Name: swift Type: object-store Region: GRA1 URL type: public

The old API worked well with username password and tenantID. What can i do ? Thanks in advance.

haroldiedema commented 7 years ago

The v3 API requires you to also specify a domain_id. By default the value for this is "default".

You can see this in detail on the API reference page at http://developer.openstack.org/api-ref/identity/v3/?expanded=password-authentication-with-unscoped-authorization-detail

kristiandrucker commented 7 years ago

Hi, when using this code to connect to openstack I get the same error

$this->openstack = new \OpenStack\OpenStack([
            'authUrl' => config('openstack.authUrl'),
            'region'  => config('openstack.region'),
            'user'    => [
                'id'       => config('openstack.user.id'),
                'domain'    => [
                    'id' => 'default',
                    'name' => 'Default'
                ],
                'password' => config('openstack.user.password')
            ],
            'scope' => [
                'project' => [
                    'id' => config('openstack.project.id')
                ]
            ]
        ]);
Endpoint URL could not be found in the catalog for this service.
Name: glance
Type: image
Region: nova
URL type: public

please may you fix the issue?

tflament commented 7 years ago

I wasn't able to resolve this bug without using CURL directly to send request to the OpenStack API. I wonder if this problem comes from this library or from the hosting provider. What's your hosting provider ?

kristiandrucker commented 7 years ago

I'm using openstack kolla on my own server.

kristiandrucker commented 7 years ago

It's definitely the library, because I've tried out deis v1 auto provision on openstack from the same laptop to the same server and it worked without any problems.

NexPB commented 7 years ago

I'm having the same issue using OVHs cloud storage.

Can anyone help me out?

tflament commented 7 years ago

You can use php Curl to exchange with the Object Storage. That's what i'm using for GooPics (hosting images website). This could also help you to directly ask OVH why it's not working with these SDK.

NexPB commented 7 years ago

@adraqi it worked fine with https://github.com/rackspace/php-opencloud but wanted to upgrade to this one.

haphan commented 7 years ago

Hi @nextpb, Thanks for reporting this issue. What is the openstack version in use and can you provide the response from the api?

I will take a look sometime today.

NexPB commented 7 years ago

@haphan https://www.openstack.org/marketplace/public-clouds/ovh-group/ovh-public-cloud

What API response would you like? Authenticating using Identity v3 was working fine, but I encoutered this error trying to use object storage.

haphan commented 7 years ago

@NexPB I've not tested the SDK with OVH flavor openstack but my take is it should work.

You can enable debug by setting debugLog to true and also injecting logger and messageFormatter.

use GuzzleHttp\MessageFormatter;
use Monolog\Logger;

$logger = new Logger('console');
$messageFormatter = new MessageFormatter(MessageFormatter::DEBUG);

$params = [
    'authUrl' => '{authUrl}',
    'region'  => '{region}',
    'user'    => [
        'id'       => '{userId}',
        'domain'    => ['id' => 'default'],
        'password' => '{password}'
    ],
    'scope'   => ['project' => ['id' => '{projectId}']],

    // enable debug mode
    'debugLog'         => true,
    'logger'           => $logger,
    'messageFormatter' => $messageFormatter,
];
$openstack = new OpenStack\OpenStack($params);

//Put your problematic code here
$openstack->objectStoreV1()-> ... 

This will basically log all the guzzle request and response to console. Please submit the log here so I can take a look.

NexPB commented 7 years ago

@haphan I couldn't get the logging working passing the laravel monolog instance.

I can provide only the laravel log but I'm not sure if that will be of any help...

[2017-02-07 18:03:49] local.ERROR: RuntimeException: Endpoint URL could not be found in the catalog for this service.
Name: swift
Type: object-store
Region: SBG1
URL type: public in /home/vagrant/Code/masterani-2/vendor/php-opencloud/openstack/src/Identity/v3/Models/Catalog.php:46
Stack trace:
#0 /home/vagrant/Code/masterani-2/vendor/php-opencloud/openstack/src/Identity/v3/Service.php(41): OpenStack\Identity\v3\Models\Catalog->getServiceUrl('swift', 'object-store', 'SBG1', 'public')
#1 /home/vagrant/Code/masterani-2/vendor/php-opencloud/openstack/src/Common/Service/Builder.php(96): OpenStack\Identity\v3\Service->authenticate(Array)
#2 /home/vagrant/Code/masterani-2/vendor/php-opencloud/openstack/src/Common/Service/Builder.php(82): OpenStack\Common\Service\Builder->stockHttpClient(Array, 'ObjectStore\\v1')
#3 /home/vagrant/Code/masterani-2/vendor/php-opencloud/openstack/src/OpenStack.php(157): OpenStack\Common\Service\Builder->createService('ObjectStore\\v1', Array)
#4 /home/vagrant/Code/masterani-2/app/Ovh/StorageClient.php(27): OpenStack\OpenStack->objectStoreV1()
#5 /home/vagrant/Code/masterani-2/app/Providers/OVHServiceProvider.php(31): App\OVH\StorageClient->__construct(Array, 'SBG1', 'official')

EDIT: It seems to work perfectly fine if I authenticate using Identity v2

haphan commented 7 years ago

@NexPBare I am unable to re-produce your issue locally. Perhaps you can double check if the region is indeed SBG1. Please note that SDK consider case-sensitivity so that SBG1 does not match sbg1.

Alternatively, I have just created this bug report template which hopefully benefit everyone in reporting issue: https://github.com/haphan/openstack-issue-report

Please follow instruction and post the result here. Thank you.

haphan commented 7 years ago

@adraqi @kristiandrucker Can you also follow following issue report template https://github.com/haphan/openstack-issue-report and post result here? Thank you.

julienfastre commented 7 years ago

Hi,

I experienced the same issue as @NexPB, and I could reproduce the bug using the api directly with curl: the catalog is empty when you retrieve a token without tenant information.

Using those params solve the problem :

$params = [
            'username' => $username,
            'password' => $password,
            'authUrl'  => $auth_url,
            'region'   => $region,
            // the tenant id is required here for a valid catalog
            'tenantId' => $tenant_id,
            // this result in an empty service catalog
            /*
            'scope' => [
                'project' => [
                    'id' => $tenant_id,
                ]
            ],
             */
            'identityService'   => \OpenStack\Identity\v2\Service::factory(
                new \GuzzleHttp\Client( [
                    'base_uri'  => \OpenStack\Common\Transport\Utils::normalizeUrl( $auth_url ),
                    'handler'   => \GuzzleHttp\HandlerStack::create(),
                ] ) ),
        ]
;

HTH

thiagodamas commented 7 years ago

Hi, after investigating, I solved the problem with the following code:


diff -ru vendor/php-opencloud/openstack/src/Identity/v3/Models/Endpoint.php ../openstack/vendor/php-opencloud/openstack/src/Identity/v3/Models/Endpoint.php
--- vendor/php-opencloud/openstack/src/Identity/v3/Models/Endpoint.php  2017-07-14 04:39:28.000000000 -0300
+++ ../openstack/vendor/php-opencloud/openstack/src/Identity/v3/Models/Endpoint.php 2017-09-18 16:37:45.303314819 -0300
@@ -77,6 +77,8 @@

     public function regionMatches(string $value): bool
     {
+        if($this->region == '*')
+            return true;
         return $this->region && $this->region == $value;
     }

diff -ru vendor/php-opencloud/openstack/src/Identity/v3/Models/Service.php ../openstack/vendor/php-opencloud/openstack/src/Identity/v3/Models/Service.php
--- vendor/php-opencloud/openstack/src/Identity/v3/Models/Service.php   2017-07-14 04:39:28.000000000 -0300
+++ ../openstack/vendor/php-opencloud/openstack/src/Identity/v3/Models/Service.php  2017-09-18 16:31:53.184373496 -0300
@@ -79,7 +79,7 @@

     private function typeMatches(string $value): bool
     {
-        return $this->type && $this->type = $value;
+        return $this->type && $this->type == $value;
     }

     /**
@@ -94,7 +94,7 @@
      */
     public function getUrl(string $name, string $type, string $region, string $interface)
     {
-        if (!$this->nameMatches($name) || !$this->typeMatches($type)) {
+        if (!$this->nameMatches($name) && !$this->typeMatches($type)) {
             return false;
         }
phansys commented 6 years ago

Fix proposed at #154. BTW, this issue seems to be vendor specific (Telefónica Open Cloud).

cocosistemas commented 6 years ago

I have the same problem. After debugging, in vendor/php-opencloud/openstack/src/Identity/v3/Models/Service.php; in method getUrl (it is previous to throw the 'EndPoint Url not found...', the values are:

this.name: EMPTY this.type: object-store name: swift type: object-store

so, this.name !== name, getUrl returns false and never find endpoint so throws the exception.

Then, ¿why $this->name is empty? anyone knows how to solve this? (if it wash 'swift' the endpoint would be found.

the code:

public function getUrl(string $name, string $type, string $region, string $interface) { //this is my poor man debug method: echo 'this.name '.$this->name.' this.type '.$this->type.' name '.$name.' type '.$type.'
';
if (!$this->nameMatches($name) || !$this->typeMatches($type)) { return false; }

Thansk!

Frzk commented 5 years ago

I pulled my hair upon this one today and finally figured it out after a few hours.

In my case I needed to pass the catalogName option when creating the object store object, so that it will match the provider's one instead of the default swift.

$objectStoreOptions = [
    'catalogName' => 'openio-swift',
];

$openstack = new OpenStack\OpenStack($yourParams);
$objectStore = $openstack->objectStoreV1($objectStoreOptions);

Another available option is catalogType, which defaults to object-store.

I've been able to figure out the value by reading the token value.

Hope it can help :-)

tomasruprich commented 4 years ago

Hi guys, just needed to solve the very same error. I personally use OVH services on multiple projects and price for their products is unbeatable. Huge problem with OVH is in the complete lack of documentation and support with anything behind scope of basic usage.

Which is probably cause of many issues posted in this thread. All OVH cloud services are connected with datacenter (SBG3, GRA1 etc.), just object storage is connected with region (SBG, GRA) and not the specific datacenter. You need to go to the Openstack Horizon management interface and check API access. If you choose datacenter SBG3 or GRA3, then you'll see just a dash in the EndPoint column. You have to switch to SBG/GRA/whatever and there you have object storage endpoint (and all other endpoints are missing).

So the issue doesn't seem to be connected with PHP OpenStack SDK, EndPoint really isn't defined with datacenters specified in former posts.

This code based on former solutions is OVH compatible:

</php
require 'vendor/autoload.php';

$username = 'ovh-horizon-username';
$password = 'ovh-horizon-password';
$region = 'SBG';
$container = 'test-container';
// projectName/projectId are visible on https://horizon.cloud.ovh.net/identity/
$projectName = '0123456789012345';
$projectId = '0987654321abcdef0987654321abcdef';

$openstack = new \OpenStack\OpenStack([
  'authUrl' => 'https://auth.cloud.ovh.net/v3/',
  'region' => $region,
  'user'    => [
      'name'       => $username,
      'domain'    => ['id' => 'default'],
      'password' => $password
  ],
  'scope'   => [
    'project' => [
      'id' => $projectId,
      'name' => $projectName,
      'domain' => ['id' => 'default', 'name' => 'Default'],
    ]
  ],
]);

$service = $openstack->objectStoreV1();
$container = $service->getContainer($container);
...