Merge pull request #31 from Azure/development

Added cmd line args and updated README
This commit is contained in:
Onur Filiz 2016-09-30 16:32:14 -07:00 коммит произвёл GitHub
Родитель 4a0b8e7905 0bbb36dae6
Коммит bfc6e5aa22
6 изменённых файлов: 144 добавлений и 30 удалений

Просмотреть файл

@ -1,19 +1,66 @@
# Overview
Aqua is a libnetwork plugin that allows you to take advantage of the power of the Microsoft Azure SDN capabilities for your containers running in Azure.
## Overview
Aqua is a libnetwork plugin for containers running on Microsoft Azure. It enables containers to take advantage of Microsoft Azure SDN capabilities.
Note this plugin is still in development and will change based on feedback.
## Setup
Download the latest stable release from Docker plugin store.
```bash
$ docker plugin pull azure/aqua
```
## Supported Environments
[Microsoft Azure](https://azure.microsoft.com)<br>
[Microsoft Azure Stack](https://azure.microsoft.com/en-us/overview/azure-stack/)
## Usage
aqua [net] [ipam]
```bash
Usage: aqua [OPTIONS]
Options:
-e, --environment={azure|mas} Set the operating environment.
-l, --log-level={info|debug} Set the logging level.
-t, --log-target={syslog|stderr} Set the logging target.
-?, --help Print usage and version information.
```
## Examples
Create a network with aqua:<br>
To connect your containers to other resources on your Azure virtual network, you need to first create a Docker network. A network is a group of uniquely addressable endpoints that can communicate with each other.
Create a network:<br>
```bash
docker network create --driver=aquanet --ipam-driver=aquaipam azure
$ docker network create --driver=azurenet --ipam-driver=azureipam azure
```
When the command succeeds, it will return the network ID. Networks can also be listed by:
```bash
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
3159b0528a83 azure azurenet local
515779dadc8a bridge bridge local
ed6e704a74ef host host local
b35e3b663cc1 none null local
```
Connect containers to your network by specifying the network name when starting them:<br>
```bash
docker run --net=azure -it ubuntu:latest /bin/bash
$ docker run --net=azure -it ubuntu:latest /bin/bash
```
Finally, once all containers on the network exit, you can delete the network:
```bash
$ docker network rm azure
```
All endpoints on the network must be deleted before the network itself can be deleted.
## Topology
The plugin creates a bridge for each underlying Azure virtual network. The bridge functions in L2 mode and is bridged to the host network interface. The bridge itself can also be assigned an IP address, turning it into a gateway for containers.
If the container host VM has multiple network interfaces, the primary network interface is reserved for management traffic. A secondary interface is used for container traffic whenever possible.
## Changelog
See [CHANGELOG](CHANGELOG.md)
## Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

29
common/config.go Normal file
Просмотреть файл

@ -0,0 +1,29 @@
// Copyright Microsoft Corp.
// All rights reserved.
package common
// Command line options.
const (
// Operating environment.
OptEnvironmentKey = "environment"
OptEnvironmentKeyShort = "e"
OptEnvironmentAzure = "azure"
OptEnvironmentMAS = "mas"
// Logging level.
OptLogLevelKey = "log-level"
OptLogLevelKeyShort = "l"
OptLogLevelInfo = "info"
OptLogLevelDebug = "debug"
// Logging target.
OptLogTargetKey = "log-target"
OptLogTargetKeyShort = "t"
OptLogTargetSyslog = "syslog"
OptLogTargetStderr = "stderr"
// Help.
OptHelpKey = "help"
OptHelpKeyShort = "?"
)

Просмотреть файл

@ -49,7 +49,7 @@ func newAddressManager() (*addressManager, error) {
}
// Initialize configures address manager.
func (am *addressManager) Initialize(config *common.PluginConfig, sourceType string) error {
func (am *addressManager) Initialize(config *common.PluginConfig, environment string) error {
am.store = config.Store
am.netApi, _ = config.NetApi.(network.NetApi)
@ -60,7 +60,7 @@ func (am *addressManager) Initialize(config *common.PluginConfig, sourceType str
}
// Start source.
err = am.startSource(sourceType)
err = am.startSource(environment)
return err
}
@ -117,19 +117,22 @@ func (am *addressManager) save() error {
}
// Starts configuration source.
func (am *addressManager) startSource(sourceType string) error {
func (am *addressManager) startSource(environment string) error {
var err error
switch sourceType {
case "azure", "":
switch environment {
case common.OptEnvironmentAzure:
am.source, err = newAzureSource()
case "mas":
case common.OptEnvironmentMAS:
am.source, err = newMasSource()
case "null":
am.source, err = newNullSource()
case "":
am.source = nil
default:
return errInvalidConfiguration
}

Просмотреть файл

@ -59,7 +59,8 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error {
}
// Initialize address manager.
err = plugin.am.Initialize(config, plugin.GetOption("source"))
environment := plugin.GetOption(common.OptEnvironmentKey)
err = plugin.am.Initialize(config, environment)
if err != nil {
log.Printf("[ipam] Failed to initialize address manager, err:%v.", err)
return err

Просмотреть файл

@ -38,9 +38,8 @@ func TestMain(m *testing.M) {
return
}
// Configure test mode and null config source.
// Configure test mode.
plugin.(*ipamPlugin).Name = "test"
plugin.SetOption("source", "null")
// Start the plugin.
err = plugin.Start(&config)
@ -54,7 +53,6 @@ func TestMain(m *testing.M) {
// Get the internal config sink interface.
sink = plugin.(*ipamPlugin).am
plugin.(*ipamPlugin).am.source.refresh()
// Run tests.
exitCode := m.Run()

64
main.go
Просмотреть файл

@ -22,12 +22,19 @@ const (
name = "azure"
// Plugin version.
version = "v0.4"
version = "0.4"
)
// Prints description and usage information.
func printHelp() {
fmt.Println("Usage: aqua [net] [ipam]")
fmt.Printf("Azure container networking plugin\n")
fmt.Printf("Version %v\n\n", version)
fmt.Printf("Usage: aqua [OPTIONS]\n\n")
fmt.Printf("Options:\n")
fmt.Printf(" -e, --environment={azure|mas} Set the operating environment.\n")
fmt.Printf(" -l, --log-level={info|debug} Set the logging level.\n")
fmt.Printf(" -t, --log-target={syslog|stderr} Set the logging target.\n")
fmt.Printf(" -?, --help Print usage and version information.\n\n")
}
func main() {
@ -37,6 +44,8 @@ func main() {
var err error
// Set defaults.
environment := common.OptEnvironmentAzure
logLevel := log.LevelInfo
logTarget := log.TargetStderr
// Initialize plugin common configuration.
@ -61,7 +70,7 @@ func main() {
args := os.Args[1:]
for _, arg := range args {
if !strings.HasPrefix(arg, "--") {
if !strings.HasPrefix(arg, "-") {
// Process commands.
switch arg {
@ -71,23 +80,46 @@ func main() {
return
}
} else {
// Process options of format "--obj-option=value".
obj := strings.SplitN(arg[2:], "-", 2)
opt := strings.SplitN(obj[1], "=", 2)
// Process options of format "--key=value".
arg = strings.TrimLeft(arg, "-")
opt := strings.SplitN(arg, "=", 2)
if len(opt) == 1 {
opt = append(opt, "")
}
switch obj[0] {
case "ipam":
ipamPlugin.SetOption(opt[0], opt[1])
switch opt[0] {
case common.OptEnvironmentKey, common.OptEnvironmentKeyShort:
environment = opt[1]
case "log":
if opt[0] == "target" && opt[1] == "syslog" {
logTarget = log.TargetSyslog
case common.OptLogLevelKey, common.OptLogLevelKeyShort:
switch opt[1] {
case common.OptLogLevelInfo:
logLevel = log.LevelInfo
case common.OptLogLevelDebug:
logLevel = log.LevelDebug
default:
fmt.Printf("Invalid option: %v\nSee --help.\n", arg)
return
}
default:
fmt.Printf("Invalid option: %v\n", arg)
case common.OptLogTargetKey, common.OptLogTargetKeyShort:
switch opt[1] {
case common.OptLogTargetStderr:
logTarget = log.TargetStderr
case common.OptLogTargetSyslog:
logTarget = log.TargetSyslog
default:
fmt.Printf("Invalid option: %v\nSee --help.\n", arg)
return
}
case common.OptHelpKey, common.OptHelpKeyShort:
printHelp()
return
default:
fmt.Printf("Invalid option: %v\nSee --help.\n", arg)
return
}
}
}
@ -103,6 +135,7 @@ func main() {
}
// Create logging provider.
log.SetLevel(logLevel)
err = log.SetTarget(logTarget)
if err != nil {
fmt.Printf("Failed to configure logging: %v\n", err)
@ -113,6 +146,9 @@ func main() {
common.LogPlatformInfo()
common.LogNetworkInterfaces()
// Set plugin options.
ipamPlugin.SetOption(common.OptEnvironmentKey, environment)
// Start plugins.
if netPlugin != nil {
err = netPlugin.Start(&config)