Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Merge requests
!88
Use SPF Viper for configuration
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Use SPF Viper for configuration
68-burntsushi-toml-is-unmaintained
into
v.0.1.0-codename-threadbare
Overview
0
Commits
15
Pipelines
3
Changes
16
Merged
Ghost User
requested to merge
68-burntsushi-toml-is-unmaintained
into
v.0.1.0-codename-threadbare
4 years ago
Overview
0
Commits
15
Pipelines
3
Changes
16
Expand
Closes
#68 (closed)
Edited
4 years ago
by
Ghost User
0
0
Merge request reports
Viewing commit
31dbfa67
Prev
Next
Show latest version
16 files
+
2662
−
31
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
16
Search (e.g. *.vue) (Ctrl+P)
31dbfa67
rescue goarista fork
· 31dbfa67
Manuel Kieweg
authored
4 years ago
forks/goarista/gnmi/arbitration.go
0 → 100644
+
58
−
0
Options
// Copyright (c) 2019 Arista Networks, Inc.
// Use of this source code is governed by the Apache License 2.0
// that can be found in the COPYING file.
package
gnmi
import
(
"fmt"
"strconv"
"strings"
"github.com/openconfig/gnmi/proto/gnmi_ext"
)
// ArbitrationExt takes a string representation of a master arbitration value
// (e.g. "23", "role:42") and return a *gnmi_ext.Extension.
func
ArbitrationExt
(
s
string
)
(
*
gnmi_ext
.
Extension
,
error
)
{
if
s
==
""
{
return
nil
,
nil
}
roleID
,
electionID
,
err
:=
parseArbitrationString
(
s
)
if
err
!=
nil
{
return
nil
,
err
}
arb
:=
&
gnmi_ext
.
MasterArbitration
{
Role
:
&
gnmi_ext
.
Role
{
Id
:
roleID
},
ElectionId
:
&
gnmi_ext
.
Uint128
{
High
:
0
,
Low
:
electionID
},
}
ext
:=
gnmi_ext
.
Extension_MasterArbitration
{
MasterArbitration
:
arb
}
return
&
gnmi_ext
.
Extension
{
Ext
:
&
ext
},
nil
}
// parseArbitrationString parses the supplied string and returns the role and election id
// values. Input is of the form [<role>:]<election_id>, where election_id is a uint64.
//
// Examples:
// "1"
// "admin:42"
func
parseArbitrationString
(
s
string
)
(
string
,
uint64
,
error
)
{
tokens
:=
strings
.
Split
(
s
,
":"
)
switch
len
(
tokens
)
{
case
1
:
// just election id
id
,
err
:=
parseElectionID
(
tokens
[
0
])
return
""
,
id
,
err
case
2
:
// role and election id
id
,
err
:=
parseElectionID
(
tokens
[
1
])
return
tokens
[
0
],
id
,
err
}
return
""
,
0
,
fmt
.
Errorf
(
"badly formed arbitration id (%s)"
,
s
)
}
func
parseElectionID
(
s
string
)
(
uint64
,
error
)
{
id
,
err
:=
strconv
.
ParseUint
(
s
,
0
,
64
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"badly formed arbitration id (%s)"
,
s
)
}
return
id
,
nil
}
Loading