ashleyhood / php-lxd Goto Github PK
View Code? Open in Web Editor NEWA PHP library for interacting with the LXD REST API
License: MIT License
A PHP library for interacting with the LXD REST API
License: MIT License
Looks like deleting a file inside a container is not yet implemented, although supported according to the docs: https://github.com/lxc/lxd/blob/master/doc/rest-api.md#delete-pathpathinsidethecontainer
When using the file write method there happens a PHP Catchable fatal error.
Has anybody already used file write and read successfully?
$lxd->containers->files->write($containernamename,'/etc/network/interfaces', 'test');
leads to:
PHP Catchable fatal error: Argument 1 passed to Opensaucesystems\Lxd\Endpoint\AbstructEndpoint::createJsonBody() must be of the type arra
y, string given, called in /..../vendor/opensaucesystems/lxd/src/Endpoint/AbstructEndpoint.php on line 51 and defined in /..../vendor/opensaucesystems/lxd/src/Endpoint/AbstructEndpoint.php on line 121
Hello,
I searched the documentation but found no reference to using Cloud-init:
user.user-data: |
#cloud-config
package_upgrade: true
packages:
- package1
- package2
Something is probably missing but I can't figure out where to set the password on PHP script side.
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://x.x.x.x:8443/1.0/containers` resulted in a `403 Forbidden` response:
{"error":"not authorized","error_code":403,"type":"error"}
t=2020-06-04T20:45:15+0200 lvl=warn msg="Rejecting request from untrusted client" ip=10.244.228.95:35874
Method references to show() should be changed to info()
Hello,
I was wondering if there a roadmap for this project? or any planned milestones?
I want to add support for better handling of pushing and pulling files and folders, and execution of commands.
Do you have any preferences on how to run the project? Would you prefer I just work on my fork and add in pull requests?
Are there any established rules regarding dependencies and php version support?
In Endpoint/Containers.php the execute function parse incorrectly dotnet
arguments command.
Example:
$cmd = 'dotnet test SomeCSharpSolution.sln --nologo --logger:"trx;LogFileName=result.trx"';
$r = $lxd->containers->execute('container-name', $cmd);
Expected parameters parsing result:
array(1) {
["command"]=>
array(5) {
[0]=>
string(6) 'dotnet'
[1]=>
string(4) 'test'
[2]=>
string(25) 'SomeCSharpSolution.sln'
[3]=>
string(8) '--nologo'
[4]=>
string(36) '--logger:"trx;LogFileName=result.trx"'
}
But the actual result is:
array(1) {
["command"]=>
array(6) {
[0]=>
string(6) "dotnet"
[1]=>
string(4) "test"
[2]=>
string(25) "SomeCSharpSolution.sln"
[3]=>
string(8) "--nologo"
[4]=>
string(9) "--logger:"
[5]=>
string(39) "trx;LogFileName=result.trx"
}
This incorrect parsing give this dotnet
result
MSBUILD : error MSB1008: Only one project can be specified.
Switch: trx;LogFileName=result.trx
For switch syntax, type "MSBuild -help"
I think the problem is in the split
function, in the regex
(line 691 in Containers.php) but i don't know how to fix this.
Perhaps it is not this php-lxd library that should solve this problem?
But, in this case, how can I pass the arguments?
Thank you for your work.
Best Regards.
PiF
When creating a new container with option 'alias" there is an PHP Notice about undefined index. That's not so good for environments where error-reporting is set to E_ALL.
PHP Notice: Undefined index: empty in /var/www/clients/client1/web2/subwebs/test.profi-webspace.eu/vendor/opensaucesystems/lxd/src/Endpoint/Containers.php on line 257
should be added an "isset"-check before check for empty-Value...
Hi,
There is a mistake in arguments between Endpoint/Containers/Files/write() (line55) and Endpoint/AbstructEndpoint/post() (line 49).
In the first method (write) when you make a call to post
(line 55) you give 3 arguments :
->post(the container name?with_get_params, follow by data, and headers)
but you must add an parameter between data and headers because in the post method the 3rd parameters is used to buildPath
and actually you buildPath
with requestHeaders
array.
I corrected it like that at
return $this->post($this->getEndpoint().$name.'/files?path='.$filepath, $data, /****** USLESS ********/ [] /****** ARRAY ******/, $headers);
but i think you can find a more elegant way.
Best regards
PS: sorry for my poor english
Based on a very quick test it looks like the project runs fine on PHP 8.0.
Would it be possible to mark it as such in composer?
- opensaucesystems/lxd v0.10.0 requires php ~7.2 -> your PHP version (8.0.0) does not satisfy that requirement.
Small bug in containers documentation:
unfreeze is missing (start instead of unfreeze):
$lxd->containers->start('container-name');
should be
$lxd->containers->unfreeze('container-name');
The API currently uses the obsolete containers endpoint instead of instances, and has no support for virtual-machines endpoint - https://documentation.ubuntu.com/lxd/en/latest/rest-api/#instances-containers-and-virtual-machines
There is a fork which already implemented this - https://github.com/turtle0x1/php-lxd
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
:-)
Hi,
In Containers.php (line 504) and Containers/Logs.php (line 26) you have two time the same error:
foreach ($this->get($this->getEndpoint().$name.'/logs/') as $log) {
$logs[] = str_replace(
'/'.$this->client->getApiVersion().'/containers/'.$name.'/logs/',
'',
$log
);
}
You must replace /containers/ by /instances/
Best Regards
PiF
It would be great to have a possibility to change the configuration of an existing container. Usecase is e.g. to change size of the root-fs in containers with quota - so after a container is running several months a customer can upgrade it and get more space if needed.
I think it is possible over the api like described here:
https://github.com/lxc/lxd/blob/master/doc/rest-api.md#user-content-put-etag-supported-2
Guzzle 7 is there and the first frameworks are already using it (e.g. Laravel 8)
unfortunatelly php-http/guzzle6-adapter doesn't work with Guzzle 7 and the solution of php-http was to create a complete new package php-http/guzzle7-adapter.
php-http/guzzle7-adapter on the other side needs php-http/httplug 2 and php-lxd requires httplug 1
so how to go on? my suggestion is also switching to Guzzle 7 here and raise the version-number to 0.10- if anybody wants to use guzzle6 he has to stick with 0.9...
what do you think?
Get this error when installing.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for opensaucesystems/lxd ^0.2.0 -> satisfiable by opensaucesystems/lxd[v0.2.0].
- opensaucesystems/lxd v0.2.0 requires php-http/client-implementation ^1.0 -> no matching package found.
Move the require-dev dependency php-http/guzzle6-adapter: ^1.1
into require...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.