Add --openstack-ip-version option

This option allows users to specify IP version.

Signed-off-by: Hironobu Saitoh <hiro@hironobu.org>
This commit is contained in:
Hironobu Saitoh 2015-10-04 23:43:42 +09:00
parent 71069cfc1d
commit 59545198ab
3 changed files with 19 additions and 1 deletions

View File

@ -34,6 +34,7 @@ Options:
- `--openstack-floatingip-pool`: The IP pool that will be used to get a public IP can assign it to the machine. If there is an - `--openstack-floatingip-pool`: The IP pool that will be used to get a public IP can assign it to the machine. If there is an
IP address already allocated but not assigned to any machine, this IP will be chosen and assigned to the machine. If IP address already allocated but not assigned to any machine, this IP will be chosen and assigned to the machine. If
there is no IP address already allocated a new IP will be allocated and assigned to the machine. there is no IP address already allocated a new IP will be allocated and assigned to the machine.
- `--openstack-ip-version`: If the instance has both IPv4 and IPv6 address, you can select IP version. If not provided `4` will be used.
- `--openstack-ssh-user`: The username to use for SSH into the machine. If not provided `root` will be used. - `--openstack-ssh-user`: The username to use for SSH into the machine. If not provided `root` will be used.
- `--openstack-ssh-port`: Customize the SSH port if the SSH server on the machine does not listen on the default port. - `--openstack-ssh-port`: Customize the SSH port if the SSH server on the machine does not listen on the default port.
- `--openstack-active-timeout`: The timeout in seconds until the OpenStack instance must be active. - `--openstack-active-timeout`: The timeout in seconds until the OpenStack instance must be active.
@ -61,6 +62,7 @@ Environment variables and default values:
| `--openstack-net-id` | - | - | | `--openstack-net-id` | - | - |
| `--openstack-sec-groups` | - | - | | `--openstack-sec-groups` | - | - |
| `--openstack-floatingip-pool` | - | - | | `--openstack-floatingip-pool` | - | - |
| `--openstack-ip-version` | `OS_IP_VERSION` | `4` |
| `--openstack-ssh-user` | - | `root` | | `--openstack-ssh-user` | - | `root` |
| `--openstack-ssh-port` | - | `22` | | `--openstack-ssh-port` | - | `22` |
| `--openstack-active-timeout` | - | `200` | | `--openstack-active-timeout` | - | `200` |

View File

@ -89,6 +89,7 @@ type IpAddress struct {
Network string Network string
AddressType string AddressType string
Address string Address string
Version int
Mac string Mac string
} }
@ -163,10 +164,16 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
for network, networkAddresses := range server.Addresses { for network, networkAddresses := range server.Addresses {
for _, element := range networkAddresses.([]interface{}) { for _, element := range networkAddresses.([]interface{}) {
address := element.(map[string]interface{}) address := element.(map[string]interface{})
version, ok := address["version"].(float64)
if !ok {
// Assume IPv4 if no version present.
version = 4
}
addr := IpAddress{ addr := IpAddress{
Network: network, Network: network,
Address: address["addr"].(string), Address: address["addr"].(string),
Version: int(version),
} }
if tp, ok := address["OS-EXT-IPS:type"]; ok { if tp, ok := address["OS-EXT-IPS:type"]; ok {
@ -179,6 +186,7 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
addresses = append(addresses, addr) addresses = append(addresses, addr)
} }
} }
return addresses, nil return addresses, nil
} }

View File

@ -39,6 +39,7 @@ type Driver struct {
SecurityGroups []string SecurityGroups []string
FloatingIpPool string FloatingIpPool string
FloatingIpPoolId string FloatingIpPoolId string
IpVersion int
client Client client Client
} }
@ -160,6 +161,12 @@ func GetCreateFlags() []cli.Flag {
Usage: "OpenStack floating IP pool to get an IP from to assign to the instance", Usage: "OpenStack floating IP pool to get an IP from to assign to the instance",
Value: "", Value: "",
}, },
cli.IntFlag{
EnvVar: "OS_IP_VERSION",
Name: "openstack-ip-version",
Usage: "OpenStack version of IP address assigned for the machine",
Value: 4,
},
cli.StringFlag{ cli.StringFlag{
Name: "openstack-ssh-user", Name: "openstack-ssh-user",
Usage: "OpenStack SSH user", Usage: "OpenStack SSH user",
@ -226,6 +233,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",") d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",")
} }
d.FloatingIpPool = flags.String("openstack-floatingip-pool") d.FloatingIpPool = flags.String("openstack-floatingip-pool")
d.IpVersion = flags.Int("openstack-ip-version")
d.SSHUser = flags.String("openstack-ssh-user") d.SSHUser = flags.String("openstack-ssh-user")
d.SSHPort = flags.Int("openstack-ssh-port") d.SSHPort = flags.Int("openstack-ssh-port")
d.SwarmMaster = flags.Bool("swarm-master") d.SwarmMaster = flags.Bool("swarm-master")
@ -269,7 +277,7 @@ func (d *Driver) GetIP() (string, error) {
return "", err return "", err
} }
for _, a := range addresses { for _, a := range addresses {
if a.AddressType == addressType { if a.AddressType == addressType && a.Version == d.IpVersion {
return a.Address, nil return a.Address, nil
} }
} }