public class DockerOvs extends Object implements AutoCloseable
try(DockerOvs ovs = new DockerOvs()) { ConnectionInfo connectionInfo = SouthboundUtils.getConnectionInfo( ovs.getOvsdbAddress(0), ovs.getOvsdbPort(0)); ... nodeInfo.disconnect(); } catch (Exception e) { ...Nota bene, DockerOvs will check whether or not docker-compose command requires "sudo" to run. However, if it does require sudo, it must be configured to not prompt for a password ("NOPASSWD: ALL" is the sudoers file). DockerOvs loads its docker-compose yaml files from inside the ovsdb-it-utils bundle at the path META-INF/docker-compose-files/. Currently, a single yaml file is used, "docker-ovs-2.5.1.yml." DockerOvs does support docker-compose files that launch more than one docker image, more on this later. DockerOvs will wait for OVS to accept OVSDB connections. Any docker-compose file must have a port mapping. The following explains how system properties are used to configure DockerOvs
private static String ENV_USAGE = "-Ddocker.run - explicitly configure whether or not DockerOvs should run docker-compose\n" + "-Dovsdbserver.ipaddress - specify IP address of ovsdb server - implies -Ddocker.run=false\n" + "-Dovsdbserver.port - specify the port of the ovsdb server - required with -Dovsdbserver.ipaddress\n" + "-Ddocker.compose.file - docker compose file in META-INF/docker-compose-files/. If not specified, default file is used\n" + "-Dovsdb.userspace.enabled - true when Ovs is running in user space (usually the case with docker)\n" + "-Dovsdb.controller.address - IP address of the controller (usually the docker0 interface with docker)\n" + "To auto-run Ovs and connect actively:\n" + " -Dovsdb.controller.address=x.x.x.x -Dovsdb.userspace.enabled=yes [-Ddocker.compose.file=ffff]\n" + "To auto-run Ovs and connect passively:\n" + " -Dovsdbserver.connection=passive -Dovsdb.controller.address=x.x.x.x -Dovsdb.userspace.enabled=yes [-Ddocker.compose.file=ffff]\n" + "To actively connect to a running Ovs:\n" + " -Dovsdbserver.ipaddress=x.x.x.x -Dovsdbserver.port=6641 -Dovsdb.controller.address=y.y.y.y\n" + "To passively connect to a running Ovs:\n" + " -Dovsdbserver.connection=passive -Ddocker.run=false\n";Note: Ommiting the environment variable ovsdb.controller.address will cause DockerOvs to use a predefined docker network called "odl". This network's subnet must be 172.99.0.0/16 and its gateway must be defined as 172.99.0.254. If the "odl" network is not present, DockerOvs will create it for you. When DockerOvs does not run docker-compose getOvsdbAddress and getOvsdbPort return the address and port specified in the system properties.
Constructor and Description |
---|
DockerOvs()
Bring up all docker images in the default docker-compose file.
|
DockerOvs(String yamlFileName)
Bring up all docker images in the provided docker-compose file under "META-INF/docker-compose-files/".
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Shut everything down.
|
String[] |
getExecCmdPrefix(int numOvs) |
int |
getNumOvsNodes()
How many OVS nodes are there.
|
String |
getOvsdbAddress(int ovsNumber)
Get the IP address of the n'th OVS.
|
String |
getOvsdbPort(int ovsNumber)
Get the port of the n'th OVS.
|
String |
getOvsdbPort(String ovsName) |
static org.ops4j.pax.exam.Option[] |
getSysPropOptions()
Get the array of system properties as pax exam Option objects for use in pax exam
unit tests with Configuration annotation.
|
void |
logState(int dockerInstance,
String logText)
Useful for debugging.
|
int |
runInContainer(int reserved,
int waitFor,
int numOvs,
String... cmdWords) |
void |
runInContainer(int waitFor,
int numOvs,
String... cmdWords) |
int |
runInContainer(int reserved,
int waitFor,
StringBuilder capturedStdout,
int numOvs,
String... cmdWords) |
void |
tryInContainer(String logText,
int waitFor,
int numOvs,
String... cmdWords) |
boolean |
usingExternalDocker()
Are we using some other OVS, not a docker we spin up?
|
public DockerOvs() throws IOException, InterruptedException
IOException
- if something goes wrong on the IO endInterruptedException
- If this thread is interruptedpublic DockerOvs(String yamlFileName) throws IOException, InterruptedException
yamlFileName
- Just the file nameIOException
- if something goes wrong on the IO endInterruptedException
- If this thread is interruptedpublic static org.ops4j.pax.exam.Option[] getSysPropOptions()
public boolean usingExternalDocker()
public String getOvsdbAddress(int ovsNumber)
ovsNumber
- which OVS?public String getOvsdbPort(int ovsNumber)
ovsNumber
- which OVS?public int getNumOvsNodes()
public String[] getExecCmdPrefix(int numOvs)
public void runInContainer(int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException
IOException
InterruptedException
public int runInContainer(int reserved, int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException
IOException
InterruptedException
public int runInContainer(int reserved, int waitFor, StringBuilder capturedStdout, int numOvs, String... cmdWords) throws IOException, InterruptedException
IOException
InterruptedException
public void tryInContainer(String logText, int waitFor, int numOvs, String... cmdWords) throws IOException, InterruptedException
IOException
InterruptedException
public void close() throws Exception
close
in interface AutoCloseable
Exception
- but not reallypublic void logState(int dockerInstance, String logText) throws IOException, InterruptedException
IOException
- If something goes wrong with reading the process outputInterruptedException
- because there's some sleeping in hereCopyright © 2018 OpenDaylight. All rights reserved.