2015-01-25 06:32:33 +03:00
|
|
|
// Copyright 2015 CoreOS, Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2014-10-18 02:36:22 +04:00
|
|
|
|
2014-06-18 22:58:18 +04:00
|
|
|
package initialize
|
|
|
|
|
2014-08-25 23:01:27 +04:00
|
|
|
import (
|
|
|
|
"sort"
|
2014-09-22 03:46:58 +04:00
|
|
|
|
2015-01-23 04:35:39 +03:00
|
|
|
"github.com/coreos/coreos-cloudinit/datasource"
|
2014-08-25 23:01:27 +04:00
|
|
|
)
|
2014-06-18 22:58:18 +04:00
|
|
|
|
2014-09-11 19:35:09 +04:00
|
|
|
// ExtractIPsFromMetaData parses a JSON blob in the OpenStack metadata service
|
|
|
|
// format and returns a substitution map possibly containing private_ipv4,
|
|
|
|
// public_ipv4, private_ipv6, and public_ipv6 addresses.
|
2015-01-23 04:35:39 +03:00
|
|
|
func ExtractIPsFromMetadata(metadata datasource.Metadata) map[string]string {
|
|
|
|
subs := map[string]string{}
|
|
|
|
if metadata.PrivateIPv4 != nil {
|
|
|
|
subs["$private_ipv4"] = metadata.PrivateIPv4.String()
|
2014-06-25 04:46:06 +04:00
|
|
|
}
|
2015-01-23 04:35:39 +03:00
|
|
|
if metadata.PublicIPv4 != nil {
|
|
|
|
subs["$public_ipv4"] = metadata.PublicIPv4.String()
|
2014-06-25 04:46:06 +04:00
|
|
|
}
|
2015-01-23 04:35:39 +03:00
|
|
|
if metadata.PrivateIPv6 != nil {
|
|
|
|
subs["$private_ipv6"] = metadata.PrivateIPv6.String()
|
2014-06-25 04:46:06 +04:00
|
|
|
}
|
2015-01-23 04:35:39 +03:00
|
|
|
if metadata.PublicIPv6 != nil {
|
|
|
|
subs["$public_ipv6"] = metadata.PublicIPv6.String()
|
2014-09-11 19:35:09 +04:00
|
|
|
}
|
2015-01-23 04:35:39 +03:00
|
|
|
|
|
|
|
return subs
|
2014-06-25 04:46:06 +04:00
|
|
|
}
|
2014-08-25 23:01:27 +04:00
|
|
|
|
|
|
|
func sortedKeys(m map[string]string) (keys []string) {
|
|
|
|
for key := range m {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
return
|
|
|
|
}
|