import { RandomUuid , Uuid } from "./uuid" ; import { log } from "./logger" ; import { ReaperInstance } from "./reaper" ; import { createNetwork , CreateNetworkOptions } from "./docker/functions/network/create-network" ; import { removeNetwork } from "./docker/functions/network/remove-network" ; export class Network { private readonly createNetworkOptions : CreateNetworkOptions ; constructor ( createNetworkOptions = { } , uuid = new RandomUuid ( ) ) { this . createNetworkOptions = { name : uuid . nextUuid ( ) , driver : "bridge" , checkDuplicate : true , internal : false , attachable : false , ingress : false , enableIPv6 : false , ... createNetworkOptions , } ; } public async start ( ) { await ReaperInstance . getInstance ( ) ; const id = await createNetwork ( this . createNetworkOptions ) ; log . info ( `Started network with ID: ${ id }` ) ; return new StartedNetwork ( id , this . createNetworkOptions ) ; } } export class StartedNetwork { constructor ( private readonly id , private readonly options ) { } public getId ( ) { return this . id ; } public getName ( ) { return this . options . name ; } public async stop ( ) { log . info ( `Stopping network with ID: ${ this . id }` ) ; await removeNetwork ( this . id ) ; return new StoppedNetwork ( ) ; } } export class StoppedNetwork { }