Fix ipv6 support in antietcd_adapter
This commit is contained in:
+11
-6
@@ -28,23 +28,28 @@ class AntiEtcdAdapter
|
|||||||
is_local['::'] = true;
|
is_local['::'] = true;
|
||||||
is_local[''] = true;
|
is_local[''] = true;
|
||||||
// split :, 3 -> <schema>:<//ip>:<port>
|
// split :, 3 -> <schema>:<//ip>:<port>
|
||||||
const selected = cluster.map(s => s.split(':', 3)).filter(ip => is_local[ip[1].substr(2)] && (!cfg_port || ip[2] == cfg_port));
|
const cluster_local = cluster.map(s =>
|
||||||
|
{
|
||||||
|
const m = /^https?:\/\/(?:\[(.*)\]|([^\[\:]+))(?::(\d+))?$/.exec(s);
|
||||||
|
return [ m[2] || m[1], m[3] || 2379 ];
|
||||||
|
});
|
||||||
|
const selected = cluster_local.filter(ip => is_local[ip[0]] && (!cfg_port || ip[1] == cfg_port));
|
||||||
if (selected.length > 1)
|
if (selected.length > 1)
|
||||||
{
|
{
|
||||||
console.error('More than 1 etcd_address matches local IPs, please specify port');
|
console.error('More than 1 etcd_address matches local IPs: '+(selected.join(', '))+', please specify port');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
else if (selected.length == 1)
|
else if (selected.length == 1)
|
||||||
{
|
{
|
||||||
const antietcd_config = {
|
const antietcd_config = {
|
||||||
ip: selected[0][1].substr(2),
|
ip: selected[0][0],
|
||||||
port: selected[0][2],
|
port: selected[0][1],
|
||||||
cert: config.antietcd_cert,
|
cert: config.antietcd_cert,
|
||||||
key: config.antietcd_key,
|
key: config.antietcd_key,
|
||||||
ca: config.antietcd_ca,
|
ca: config.antietcd_ca,
|
||||||
data: config.antietcd_data_file || ((config.antietcd_data_dir || '/var/lib/vitastor') + '/mon_'+selected[0][2]+'.json.gz'),
|
data: config.antietcd_data_file || ((config.antietcd_data_dir || '/var/lib/vitastor') + '/mon_'+selected[0][1]+'.json.gz'),
|
||||||
persist_filter: vitastor_persist_filter({ vitastor_prefix: config.etcd_prefix || '/vitastor' }),
|
persist_filter: vitastor_persist_filter({ vitastor_prefix: config.etcd_prefix || '/vitastor' }),
|
||||||
node_id: selected[0][1].substr(2)+':'+selected[0][2], // node_id = ip:port
|
node_id: selected[0][0]+':'+selected[0][1], // node_id = ip:port
|
||||||
cluster: (cluster.length == 1 ? null : cluster.reduce((a, c) => { a[c.replace(/^(https?:\/\/)/, '')] = c; return a; }, {})),
|
cluster: (cluster.length == 1 ? null : cluster.reduce((a, c) => { a[c.replace(/^(https?:\/\/)/, '')] = c; return a; }, {})),
|
||||||
cluster_key: (config.etcd_prefix || '/vitastor'),
|
cluster_key: (config.etcd_prefix || '/vitastor'),
|
||||||
stale_read: 1,
|
stale_read: 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user