@@ -1273,6 +1273,152 @@ public function execInspect($exec)
1273
1273
)->then (array ($ this ->parser , 'expectJson ' ));
1274
1274
}
1275
1275
1276
+ /**
1277
+ * List networks.
1278
+ *
1279
+ * @return PromiseInterface Promise<array>
1280
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkList
1281
+ */
1282
+ public function networkList ()
1283
+ {
1284
+ return $ this ->browser ->get (
1285
+ $ this ->uri ->expand (
1286
+ '/networks ' ,
1287
+ array ()
1288
+ )
1289
+ )->then (array ($ this ->parser , 'expectJson ' ));
1290
+ }
1291
+
1292
+ /**
1293
+ * Inspect network.
1294
+ *
1295
+ * @param string $network The network id or name
1296
+ *
1297
+ * @return PromiseInterface Promise<array>
1298
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkInspect
1299
+ */
1300
+ public function networkInspect ($ network )
1301
+ {
1302
+ return $ this ->browser ->get (
1303
+ $ this ->uri ->expand (
1304
+ '/networks/{network} ' ,
1305
+ array (
1306
+ 'network ' => $ network
1307
+ )
1308
+ )
1309
+ )->then (array ($ this ->parser , 'expectJson ' ));
1310
+ }
1311
+
1312
+ /**
1313
+ * Remove network.
1314
+ *
1315
+ * @param string $network The network id or name
1316
+ *
1317
+ * @return PromiseInterface Promise<null>
1318
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkRemove
1319
+ */
1320
+ public function networkRemove ($ network )
1321
+ {
1322
+ return $ this ->browser ->delete (
1323
+ $ this ->uri ->expand (
1324
+ '/networks/{network} ' ,
1325
+ array (
1326
+ 'network ' => $ network
1327
+ )
1328
+ )
1329
+ )->then (array ($ this ->parser , 'expectEmpty ' ));
1330
+ }
1331
+
1332
+ /**
1333
+ * Create network.
1334
+ *
1335
+ * @param string $name The network name
1336
+ * @param array $config (optional) The network configuration
1337
+ *
1338
+ * @return PromiseInterface Promise<array>
1339
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkCreate
1340
+ */
1341
+ public function networkCreate ($ name , $ config = array ())
1342
+ {
1343
+ $ config ['Name ' ] = $ name ;
1344
+
1345
+ return $ this ->postJson (
1346
+ $ this ->uri ->expand (
1347
+ '/networks/create '
1348
+ ),
1349
+ $ config
1350
+ )->then (array ($ this ->parser , 'expectJson ' ));
1351
+ }
1352
+
1353
+ /**
1354
+ * Connect container to network
1355
+ *
1356
+ * @param string $network The network id or name
1357
+ * @param string $container The id or name of the container to connect to network
1358
+ * @param array $endpointConfig (optional) Configuration for a network endpoint
1359
+ *
1360
+ * @return PromiseInterface Promise<array>
1361
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkConnect
1362
+ */
1363
+ public function networkConnect ($ network , $ container , $ endpointConfig = array ())
1364
+ {
1365
+ return $ this ->postJson (
1366
+ $ this ->uri ->expand (
1367
+ '/networks/{network}/connect ' ,
1368
+ array (
1369
+ 'network ' => $ network
1370
+ )
1371
+ ),
1372
+ array (
1373
+ 'Container ' => $ container ,
1374
+ 'EndpointConfig ' => $ endpointConfig ? json_encode ($ endpointConfig ) : null
1375
+ )
1376
+ )->then (array ($ this ->parser , 'expectJson ' ));
1377
+ }
1378
+
1379
+ /**
1380
+ * Disconnect container from network.
1381
+ *
1382
+ * @param string $network The id or name of network
1383
+ * @param string $container The id or name of container to disconnect
1384
+ * @param bool $force (optional) Force the disconnect
1385
+ *
1386
+ * @return PromiseInterface Promise<null>
1387
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkDisconnect
1388
+ */
1389
+ public function networkDisconnect ($ network , $ container , $ force = false )
1390
+ {
1391
+ return $ this ->postJson (
1392
+ $ this ->uri ->expand (
1393
+ '/networks/{network}/disconnect ' ,
1394
+ array (
1395
+ 'network ' => $ network
1396
+ )
1397
+ ),
1398
+ array (
1399
+ 'Container ' => $ container ,
1400
+ 'Force ' => $ this ->boolArg ($ force )
1401
+ )
1402
+ )->then (array ($ this ->parser , 'expectEmpty ' ));
1403
+ }
1404
+
1405
+ /**
1406
+ * Remove all unused networks.
1407
+ *
1408
+ * @return PromiseInterface Promise<array>
1409
+ * @link https://docs.docker.com/engine/api/v1.40/#operation/NetworkPrune
1410
+ */
1411
+ public function networkPrune ()
1412
+ {
1413
+ return $ this ->postJson (
1414
+ $ this ->uri ->expand (
1415
+ '/networks/prune ' ,
1416
+ array ()
1417
+ ),
1418
+ array ()
1419
+ )->then (array ($ this ->parser , 'expectJson ' ));
1420
+ }
1421
+
1276
1422
private function postJson ($ url , $ data )
1277
1423
{
1278
1424
$ body = $ this ->json ($ data );
0 commit comments