ashleyhood / php-lxd

A PHP library for interacting with the LXD REST API
MIT License
28 stars 15 forks source link

Create fails #21

Closed MichaelNino closed 4 years ago

MichaelNino commented 4 years ago

Hi,

I am creating 3 containers: test-nginx, test-php and test-mysql so that I might create a containerized LEMP stack using php-lxd. I first executed: lxc launch from the terminal to verify LXD is working. Then I endeavored to create the second container, test-php, using php-lxd. For some reason, LXD responds that "No matching image found" Below are my code snippets:

test-nginx

lxc launch images:ubuntu/18.04 test-nginx

test-php

$ ./artisan lxd:client

   Http\Client\Exception\HttpException  : Client error: `POST https://127.0.0.1:8443/1.0/containers` resulted in a `400 Bad Request` response:
{"error":"No matching image could be found","error_code":400,"type":"error"}

  at /media/michael/Data/LaunchSoftwareSite/vendor/php-http/guzzle6-adapter/src/Promise.php:127
    123| 
    124|         if ($exception instanceof GuzzleExceptions\RequestException) {
    125|             // Make sure we have a response for the HttpException
    126|             if ($exception->hasResponse()) {
  > 127|                 return new HttplugException\HttpException(
    128|                     $exception->getMessage(),
    129|                     $exception->getRequest(),
    130|                     $exception->getResponse(),
    131|                     $exception

  Exception trace:

  1   Http\Adapter\Guzzle6\Promise::handleException(Object(GuzzleHttp\Exception\ClientException), Object(GuzzleHttp\Psr7\Request))
      /media/michael/Data/LaunchSoftwareSite/vendor/php-http/guzzle6-adapter/src/Promise.php:63

  2   GuzzleHttp\Exception\ClientException::("Client error: `POST https://127.0.0.1:8443/1.0/containers` resulted in a `400 Bad Request` response:
{"error":"No matching image could be found","error_code":400,"type":"error"}

")
      /media/michael/Data/LaunchSoftwareSite/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

This is my first attempt using both LXD and php-lxd. Am I using the correct API call? Is there something I a missing about images? Maybe remote? What is the corresponding API call for lxc launch?

Thanks @ashleyhood

:-)

MichaelNino commented 4 years ago

Your assistance or input is greatly appreciated. Any direction would be helpful. I am endeavoring to create a Laravel package for php-lxd and GUI.

ashleyhood commented 4 years ago

@MichaelNino try the following options:

$options = [
    'server' => 'https://cloud-images.ubuntu.com/releases',
    'alias' => '18.04/amd64',
    'protocol' => 'simplestreams',
];

$lxd->containers->create('test-php', $options);

This will download a cloud image for you.

MichaelNino commented 4 years ago

Ah, the $options array makes more sense with the server and protocol keys. Worked perfectly! Thanks!