Implement Network Connect/Modify for SQLite state
Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
parent
8ab18d8482
commit
939a4ccef4
|
|
@ -808,7 +808,6 @@ func (s *SQLiteState) NetworkModify(ctr *Container, network string, opts types.P
|
||||||
}
|
}
|
||||||
|
|
||||||
// networkModify allows you to modify or add a new network, to add a new network use the new bool
|
// networkModify allows you to modify or add a new network, to add a new network use the new bool
|
||||||
// TODO TODO TODO
|
|
||||||
func (s *SQLiteState) networkModify(ctr *Container, network string, opts types.PerNetworkOptions, new bool) error {
|
func (s *SQLiteState) networkModify(ctr *Container, network string, opts types.PerNetworkOptions, new bool) error {
|
||||||
if !s.valid {
|
if !s.valid {
|
||||||
return define.ErrDBClosed
|
return define.ErrDBClosed
|
||||||
|
|
@ -822,52 +821,30 @@ func (s *SQLiteState) networkModify(ctr *Container, network string, opts types.P
|
||||||
return fmt.Errorf("network names must not be empty: %w", define.ErrInvalidArg)
|
return fmt.Errorf("network names must not be empty: %w", define.ErrInvalidArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return define.ErrNotImplemented
|
// Grab a fresh copy of the config, in case anything changed
|
||||||
|
newCfg, err := s.getCtrConfig(ctr.ID())
|
||||||
|
if err != nil && errors.Is(err, define.ErrNoSuchCtr) {
|
||||||
|
ctr.valid = false
|
||||||
|
return define.ErrNoSuchCtr
|
||||||
|
}
|
||||||
|
|
||||||
// optBytes, err := json.Marshal(opts)
|
_, ok := newCfg.Networks[network]
|
||||||
// if err != nil {
|
if new && ok {
|
||||||
// return fmt.Errorf("marshalling network options JSON for container %s: %w", ctr.ID(), err)
|
return fmt.Errorf("container %s is already connected to network %s: %w", ctr.ID(), network, define.ErrInvalidArg)
|
||||||
// }
|
}
|
||||||
|
if !new && !ok {
|
||||||
|
return fmt.Errorf("container %s is not connected to network %s: %w", ctr.ID(), network, define.ErrInvalidArg)
|
||||||
|
}
|
||||||
|
|
||||||
// ctrID := []byte(ctr.ID())
|
newCfg.Networks[network] = opts
|
||||||
|
|
||||||
// db, err := s.getDBCon()
|
if err := s.rewriteContainerConfig(ctr, newCfg); err != nil {
|
||||||
// if err != nil {
|
return err
|
||||||
// return err
|
}
|
||||||
// }
|
|
||||||
// defer s.deferredCloseDBCon(db)
|
|
||||||
|
|
||||||
// return db.Update(func(tx *bolt.Tx) error {
|
ctr.config = newCfg
|
||||||
// ctrBucket, err := getCtrBucket(tx)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// dbCtr := ctrBucket.Bucket(ctrID)
|
return nil
|
||||||
// if dbCtr == nil {
|
|
||||||
// ctr.valid = false
|
|
||||||
// return fmt.Errorf("container %s does not exist in database: %w", ctr.ID(), define.ErrNoSuchCtr)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ctrNetworksBkt := dbCtr.Bucket(networksBkt)
|
|
||||||
// if ctrNetworksBkt == nil {
|
|
||||||
// return fmt.Errorf("container %s does not have a network bucket: %w", ctr.ID(), define.ErrNoSuchNetwork)
|
|
||||||
// }
|
|
||||||
// netConnected := ctrNetworksBkt.Get([]byte(network))
|
|
||||||
|
|
||||||
// if new && netConnected != nil {
|
|
||||||
// return fmt.Errorf("container %s is already connected to network %q: %w", ctr.ID(), network, define.ErrNetworkConnected)
|
|
||||||
// } else if !new && netConnected == nil {
|
|
||||||
// return fmt.Errorf("container %s is not connected to network %q: %w", ctr.ID(), network, define.ErrNoSuchNetwork)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Modify/Add the network
|
|
||||||
// if err := ctrNetworksBkt.Put([]byte(network), optBytes); err != nil {
|
|
||||||
// return fmt.Errorf("adding container %s to network %s in DB: %w", ctr.ID(), network, err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return nil
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworkDisconnect disconnects the container from the given network, also
|
// NetworkDisconnect disconnects the container from the given network, also
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue