2016-12-02 13:52:40 -08:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package rgw
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2017-12-04 08:33:19 -08:00
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/client"
|
2016-12-02 13:52:40 -08:00
|
|
|
)
|
|
|
|
|
|
2017-08-31 10:54:59 -07:00
|
|
|
type Context struct {
|
2017-09-11 14:56:10 -07:00
|
|
|
context *clusterd.Context
|
|
|
|
|
Name string
|
|
|
|
|
ClusterName string
|
2017-08-31 10:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
func NewContext(context *clusterd.Context, name, clusterName string) *Context {
|
|
|
|
|
return &Context{context: context, Name: name, ClusterName: clusterName}
|
2017-08-31 10:54:59 -07:00
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:56:10 -07:00
|
|
|
func runAdminCommandNoRealm(c *Context, args ...string) (string, error) {
|
|
|
|
|
options := client.AppendAdminConnectionArgs(args, c.context.ConfigDir, c.ClusterName)
|
2016-12-02 13:52:40 -08:00
|
|
|
|
2016-12-02 16:19:26 -08:00
|
|
|
// start the rgw admin command
|
2017-08-31 10:54:59 -07:00
|
|
|
output, err := c.context.Executor.ExecuteCommandWithCombinedOutput(false, "", "radosgw-admin", options...)
|
2016-12-02 13:52:40 -08:00
|
|
|
if err != nil {
|
2017-06-06 12:58:09 -07:00
|
|
|
return "", fmt.Errorf("failed to run radosgw-admin: %+v", err)
|
2016-12-02 13:52:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output, nil
|
|
|
|
|
}
|
2017-09-11 14:56:10 -07:00
|
|
|
|
|
|
|
|
func runAdminCommand(c *Context, args ...string) (string, error) {
|
|
|
|
|
options := []string{
|
|
|
|
|
fmt.Sprintf("--rgw-realm=%s", c.Name),
|
|
|
|
|
fmt.Sprintf("--rgw-zonegroup=%s", c.Name),
|
|
|
|
|
}
|
|
|
|
|
return runAdminCommandNoRealm(c, append(args, options...)...)
|
|
|
|
|
}
|