Class DockerManager
- java.lang.Object
-
- io.patriot_framework.network_simulator.docker.manager.DockerManager
-
-
Constructor Summary
Constructors Constructor Description DockerManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildImage(File dockerfile, Set<String> tag)
Build image.void
connectContainerToNetwork(Container container, Network network)
Connect container to network.String
convertToNetworkIp(String ip, int mask)
Method converts host ip address to ip address of network or subnet.Container
createContainer(String name, String tag)
Create container container.Container
createContainer(String name, String tag, String elasticIP, Integer logshtashPort)
Container
createContainer(String name, String tag, String elasticIP, Integer logstashPort, List<String> environmentVariables)
Create container container with elastic log hook.Container
createContainer(String name, String tag, String volumePath, String bindPath)
Create container container.Network
createNetwork(String name, String subnet)
Create network network.void
delDefaultGateway(DockerContainer container)
void
deleteImage(String tag)
Delete image.void
destroyContainer(Container container)
Method which destroys docker network based on network id.void
destroyNetwork(Network network)
Method which destroys docker network based on network id.void
disconnectContainer(Container container, Network network)
Disconnects container from network.String
findIpAddress(Container container)
String
findIpAddress(Container container, Network network)
Find ip address string.String
getDefaultGwNetworkIp(Container container)
Integer
getDefaultGwNetworkMask(Container container)
Method gathers gateway's network mask.String
getGatewayIP(Container container)
void
killContainer(Container container)
Method stops container.List<Container>
listContainers()
Method providing service for finding containers and return list of all created containersList<Network>
listNetworks()
Method providing service for finding networks and return list of all created networksvoid
runCommand(Container container, String command)
Method is providing execution of commands directly in running docker container.void
startContainer(Container container)
Method which starts docker container based on container name.
-
-
-
Method Detail
-
findIpAddress
public String findIpAddress(Container container, Network network)
Description copied from interface:Manager
Find ip address string.- Specified by:
findIpAddress
in interfaceManager
- Parameters:
container
- the containernetwork
- the network- Returns:
- the string
-
buildImage
public void buildImage(File dockerfile, Set<String> tag)
Description copied from interface:Manager
Build image.- Specified by:
buildImage
in interfaceManager
- Parameters:
dockerfile
- the dockerfiletag
- the tag
-
deleteImage
public void deleteImage(String tag)
Description copied from interface:Manager
Delete image.- Specified by:
deleteImage
in interfaceManager
- Parameters:
tag
- the tag
-
createContainer
public Container createContainer(String name, String tag)
Description copied from interface:Manager
Create container container.- Specified by:
createContainer
in interfaceManager
- Parameters:
name
- the nametag
- the tag- Returns:
- the container
-
createContainer
public Container createContainer(String name, String tag, String volumePath, String bindPath)
Create container container.- Parameters:
name
- the nametag
- the tagvolumePath
- the volume pathbindPath
- the bind path- Returns:
- the container
-
createContainer
public Container createContainer(String name, String tag, String elasticIP, Integer logstashPort, List<String> environmentVariables)
Create container container with elastic log hook.- Parameters:
name
- the nametag
- the tagelasticIP
- the elastic iplogstashPort
- the logshtash port- Returns:
- the container
-
createContainer
public Container createContainer(String name, String tag, String elasticIP, Integer logshtashPort)
-
createNetwork
public Network createNetwork(String name, String subnet)
Description copied from interface:Manager
Create network network.- Specified by:
createNetwork
in interfaceManager
- Parameters:
name
- the namesubnet
- the subnet- Returns:
- the network
-
listContainers
public List<Container> listContainers()
Method providing service for finding containers and return list of all created containers- Specified by:
listContainers
in interfaceManager
- Returns:
-
listNetworks
public List<Network> listNetworks()
Method providing service for finding networks and return list of all created networks- Specified by:
listNetworks
in interfaceManager
- Returns:
- returns all networks running in docker
-
connectContainerToNetwork
public void connectContainerToNetwork(Container container, Network network)
Description copied from interface:Manager
Connect container to network.- Specified by:
connectContainerToNetwork
in interfaceManager
- Parameters:
container
- the containernetwork
- the network
-
killContainer
public void killContainer(Container container)
Description copied from interface:Manager
Method stops container.- Specified by:
killContainer
in interfaceManager
-
disconnectContainer
public void disconnectContainer(Container container, Network network)
Description copied from interface:Manager
Disconnects container from network.- Specified by:
disconnectContainer
in interfaceManager
-
destroyContainer
public void destroyContainer(Container container)
Method which destroys docker network based on network id.- Specified by:
destroyContainer
in interfaceManager
- Parameters:
container
- container which needs to be destroyed
-
destroyNetwork
public void destroyNetwork(Network network)
Method which destroys docker network based on network id.- Specified by:
destroyNetwork
in interfaceManager
- Parameters:
network
- network which needs to be destroyed
-
runCommand
public void runCommand(Container container, String command)
Method is providing execution of commands directly in running docker container.- Specified by:
runCommand
in interfaceManager
- Parameters:
container
- container in which will be command executedcommand
- command which will be executed
-
startContainer
public void startContainer(Container container)
Method which starts docker container based on container name.- Specified by:
startContainer
in interfaceManager
- Parameters:
container
- container which will be started
-
getDefaultGwNetworkMask
public Integer getDefaultGwNetworkMask(Container container)
Method gathers gateway's network mask.- Parameters:
container
- container from which will generator gather gateway- Returns:
- network mask (decimal)
-
convertToNetworkIp
public String convertToNetworkIp(String ip, int mask)
Method converts host ip address to ip address of network or subnet. Docker api doesn't store ip address of network in containers config so we have to convert it from container's ip and mask. Convert uses logic AND function.- Parameters:
ip
- IP Address of container in target network.mask
- mask of containers ip addres in target network.- Returns:
- Network IP Address
-
delDefaultGateway
public void delDefaultGateway(DockerContainer container)
-
-