Skip to content

Commit

Permalink
Merge pull request #549 from shaleman/cfgtool
Browse files Browse the repository at this point in the history
Add a tool to modify cfg objects
  • Loading branch information
shaleman authored Sep 10, 2016
2 parents 98d865e + 76ca8ba commit 40b58cb
Show file tree
Hide file tree
Showing 5 changed files with 423 additions and 19 deletions.
26 changes: 13 additions & 13 deletions netmaster/docknet/docknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const (
var netDriverName = "netplugin"
var ipamDriverName = "netplugin"

// OperState has oper state of docker network
type OperState struct {
// DnetOperState has oper state of docker network
type DnetOperState struct {
core.CommonState
TenantName string `json:"tenantName"`
NetworkName string `json:"networkName"`
Expand All @@ -48,30 +48,30 @@ type OperState struct {
}

// Write the state.
func (s *OperState) Write() error {
func (s *DnetOperState) Write() error {
key := fmt.Sprintf(docknetOperPath, s.ID)
return s.StateDriver.WriteState(key, s, json.Marshal)
}

// Read the state for a given identifier
func (s *OperState) Read(id string) error {
func (s *DnetOperState) Read(id string) error {
key := fmt.Sprintf(docknetOperPath, id)
return s.StateDriver.ReadState(key, s, json.Unmarshal)
}

// ReadAll state and return the collection.
func (s *OperState) ReadAll() ([]core.State, error) {
func (s *DnetOperState) ReadAll() ([]core.State, error) {
return s.StateDriver.ReadAllState(docknetOperPrefix, s, json.Unmarshal)
}

// WatchAll state transitions and send them through the channel.
func (s *OperState) WatchAll(rsps chan core.WatchState) error {
func (s *DnetOperState) WatchAll(rsps chan core.WatchState) error {
return s.StateDriver.WatchAllState(docknetOperPrefix, s, json.Unmarshal,
rsps)
}

// Clear removes the state.
func (s *OperState) Clear() error {
func (s *DnetOperState) Clear() error {
key := fmt.Sprintf(docknetOperPath, s.ID)
return s.StateDriver.ClearState(key)
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func CreateDockNet(tenantName, networkName, serviceName string, nwCfg *mastercfg
}

// save docknet oper state
dnetOper := OperState{
dnetOper := DnetOperState{
TenantName: tenantName,
NetworkName: networkName,
ServiceName: serviceName,
Expand Down Expand Up @@ -233,7 +233,7 @@ func DeleteDockNet(tenantName, networkName, serviceName string) error {
}

// save docknet oper state
dnetOper := OperState{}
dnetOper := DnetOperState{}
dnetOper.ID = fmt.Sprintf("%s.%s.%s", tenantName, networkName, serviceName)
dnetOper.StateDriver = stateDriver

Expand All @@ -247,15 +247,15 @@ func DeleteDockNet(tenantName, networkName, serviceName string) error {
}

// FindDocknetByUUID find the docknet by UUID
func FindDocknetByUUID(dnetID string) (*OperState, error) {
func FindDocknetByUUID(dnetID string) (*DnetOperState, error) {
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Warnf("Couldn't read global config %v", err)
return nil, err
}

tmpDnet := OperState{}
tmpDnet := DnetOperState{}
tmpDnet.StateDriver = stateDriver
dnetOperList, err := tmpDnet.ReadAll()
if err != nil {
Expand All @@ -265,8 +265,8 @@ func FindDocknetByUUID(dnetID string) (*OperState, error) {

// Walk all dnets and find the matching UUID
for _, dnet := range dnetOperList {
if dnet.(*OperState).DocknetUUID == dnetID {
return dnet.(*OperState), nil
if dnet.(*DnetOperState).DocknetUUID == dnetID {
return dnet.(*DnetOperState), nil
}
}

Expand Down
4 changes: 2 additions & 2 deletions netmaster/docknet/docknet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func initStateDriver() (core.StateDriver, error) {
}

// getDocknetState gets docknet oper state
func getDocknetState(tenantName, networkName, serviceName string) *OperState {
func getDocknetState(tenantName, networkName, serviceName string) *DnetOperState {
// Get the state driver
stateDriver, err := utils.GetStateDriver()
if err != nil {
Expand All @@ -45,7 +45,7 @@ func getDocknetState(tenantName, networkName, serviceName string) *OperState {
}

// save docknet oper state
dnetOper := OperState{}
dnetOper := DnetOperState{}
dnetOper.StateDriver = stateDriver

// write the dnet oper state
Expand Down
Loading

0 comments on commit 40b58cb

Please sign in to comment.