mirror of https://github.com/ceph/go-ceph
cephfs admin: add flagSet interface and mergeFlags function
To prepare for multiple flags types, we create a flagSet interface and break out the functionality that was in Update into a per-type method and then the common "merger" function. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
98afaf6376
commit
7524b39272
|
@ -2,17 +2,37 @@
|
|||
|
||||
package admin
|
||||
|
||||
// For APIs that accept extra sets of "boolean" flags we may end up wanting
|
||||
// multiple different sets of supported flags. Example: most rm functions
|
||||
// accept a force flag, but only subvolume delete has retain snapshots.
|
||||
// To make this somewhat uniform in the admin package we define a utility
|
||||
// interface and helper function to merge flags with naming options.
|
||||
|
||||
type flagSet interface {
|
||||
flags() map[string]bool
|
||||
}
|
||||
|
||||
type commonRmFlags struct {
|
||||
force bool
|
||||
}
|
||||
|
||||
func (f commonRmFlags) Update(m map[string]string) map[string]interface{} {
|
||||
o := make(map[string]interface{})
|
||||
for k, v := range m {
|
||||
o[k] = v
|
||||
}
|
||||
func (f commonRmFlags) flags() map[string]bool {
|
||||
o := make(map[string]bool)
|
||||
if f.force {
|
||||
o["force"] = true
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// mergeFlags combines a set of key-value settings with any type implementing
|
||||
// the flagSet interface.
|
||||
func mergeFlags(m map[string]string, f flagSet) map[string]interface{} {
|
||||
o := make(map[string]interface{})
|
||||
for k, v := range m {
|
||||
o[k] = v
|
||||
}
|
||||
for k, v := range f.flags() {
|
||||
o[k] = v
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ func (fsa *FSAdmin) rmSubVolume(volume, group, name string, o commonRmFlags) err
|
|||
if group != NoGroup {
|
||||
m["group_name"] = group
|
||||
}
|
||||
return fsa.marshalMgrCommand(o.Update(m)).noData().End()
|
||||
return fsa.marshalMgrCommand(mergeFlags(m, o)).noData().End()
|
||||
}
|
||||
|
||||
type subVolumeResizeFields struct {
|
||||
|
@ -287,7 +287,7 @@ func (fsa *FSAdmin) rmSubVolumeSnapshot(volume, group, subvolume, name string, o
|
|||
if group != NoGroup {
|
||||
m["group_name"] = group
|
||||
}
|
||||
return fsa.marshalMgrCommand(o.Update(m)).noData().End()
|
||||
return fsa.marshalMgrCommand(mergeFlags(m, o)).noData().End()
|
||||
}
|
||||
|
||||
// ListSubVolumeSnapshots returns a listing of snapshots for a given subvolume.
|
||||
|
|
|
@ -80,12 +80,12 @@ func (fsa *FSAdmin) ForceRemoveSubVolumeGroup(volume, name string) error {
|
|||
}
|
||||
|
||||
func (fsa *FSAdmin) rmSubVolumeGroup(volume, name string, o commonRmFlags) error {
|
||||
res := fsa.marshalMgrCommand(o.Update(map[string]string{
|
||||
res := fsa.marshalMgrCommand(mergeFlags(map[string]string{
|
||||
"prefix": "fs subvolumegroup rm",
|
||||
"vol_name": volume,
|
||||
"group_name": name,
|
||||
"format": "json",
|
||||
}))
|
||||
}, o))
|
||||
return res.noData().End()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue