admin: Add missing madmin examples and API docs. (#3483)
parent
e7b4e4e105
commit
f57f773189
@ -0,0 +1,135 @@ |
||||
# Golang Admin Client API Reference [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
||||
|
||||
## Initialize Minio Admin Client object. |
||||
|
||||
## Minio |
||||
|
||||
```go |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/minio/minio/pkg/madmin" |
||||
) |
||||
|
||||
func main() { |
||||
// Use a secure connection. |
||||
ssl := true |
||||
|
||||
// Initialize minio client object. |
||||
mdmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETKEY", ssl) |
||||
if err != nil { |
||||
fmt.Println(err) |
||||
return |
||||
} |
||||
|
||||
// Fetch service status. |
||||
st, err := mdmClnt.ServiceStatus() |
||||
if err != nil { |
||||
fmt.Println(err) |
||||
return |
||||
} |
||||
fmt.Printf("%#v\n", st) |
||||
} |
||||
|
||||
``` |
||||
|
||||
| Service operations|LockInfo operations|Healing operations| |
||||
|:---|:---|:---| |
||||
|[`ServiceStatus`](#ServiceStatus)| | | |
||||
|[`ServiceStop`](#ServiceStop)| | | |
||||
|[`ServiceRestart`](#ServiceRestart)| | | |
||||
|
||||
## 1. Constructor |
||||
<a name="Minio"></a> |
||||
|
||||
### New(endpoint string, accessKeyID string, secretAccessKey string, ssl bool) (*AdminClient, error) |
||||
Initializes a new admin client object. |
||||
|
||||
__Parameters__ |
||||
|
||||
|
||||
|Param |Type |Description | |
||||
|:---|:---| :---| |
||||
|`endpoint` | _string_ |Minio endpoint. | |
||||
|`accessKeyID` |_string_ | Access key for the object storage endpoint. | |
||||
|`secretAccessKey` | _string_ |Secret key for the object storage endpoint. | |
||||
|`ssl` | _bool_ | Set this value to 'true' to enable secure (HTTPS) access. | |
||||
|
||||
|
||||
## 2. Service operations |
||||
|
||||
<a name="ServiceStatus"></a> |
||||
### ServiceStatus() (ServiceStatusMetadata, error) |
||||
Fetch service status, replies disk space used, backend type and total disks offline/online (XL). |
||||
|
||||
| Param | Type | Description | |
||||
|---|---|---| |
||||
|`serviceStatus` | _ServiceStatusMetadata_ | Represents current server status info in following format: | |
||||
|
||||
|
||||
| Param | Type | Description | |
||||
|---|---|---| |
||||
|`st.Total` | _int64_ | Total disk space. | |
||||
|`st.Free` | _int64_ | Free disk space. | |
||||
|`st.Backend`| _struct{}_ | Represents backend type embedded structure. | |
||||
|
||||
| Param | Type | Description | |
||||
|---|---|---| |
||||
|`backend.Type` | _BackendType_ | Type of backend used by the server currently only FS or XL. | |
||||
|`backend.OnlineDisks`| _int_ | Total number of disks online (only applies to XL backend), is empty for FS. | |
||||
|`backend.OfflineDisks` | _int_ | Total number of disks offline (only applies to XL backend), is empty for FS. | |
||||
|`backend.ReadQuorum` | _int_ | Current total read quorum threshold before reads will be unavailable, is empty for FS. | |
||||
|`backend.WriteQuorum` | _int_ | Current total write quorum threshold before writes will be unavailable, is empty for FS. | |
||||
|
||||
|
||||
__Example__ |
||||
|
||||
|
||||
```go |
||||
|
||||
st, err := madmClnt.ServiceStatus() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Printf("%#v\n", st) |
||||
|
||||
``` |
||||
|
||||
<a name="ServiceStop"></a> |
||||
### ServiceStop() (error) |
||||
If successful shuts down the running minio service, for distributed setup stops all remote minio servers. |
||||
|
||||
__Example__ |
||||
|
||||
|
||||
```go |
||||
|
||||
st, err := madmClnt.ServiceStop() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Printf("Succes") |
||||
|
||||
``` |
||||
|
||||
<a name="ServiceRestart"></a> |
||||
### ServiceRestart() (error) |
||||
If successful restarts the running minio service, for distributed setup restarts all remote minio servers. |
||||
|
||||
__Example__ |
||||
|
||||
|
||||
```go |
||||
|
||||
|
||||
st, err := madmClnt.ServiceRestart() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Printf("Succes") |
||||
|
||||
``` |
||||
|
@ -0,0 +1,122 @@ |
||||
# Minio Admin Library. [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
||||
The Minio Admin Golang Client SDK provides APIs to manage Minio services. |
||||
|
||||
This quickstart guide will show you how to install the Minio Admin client SDK, connect to Minio admin service, and provide a walkthrough of a simple file uploader. |
||||
|
||||
This document assumes that you have a working [Golang setup](https://docs.minio.io/docs/how-to-install-golang). |
||||
|
||||
## Download from Github |
||||
|
||||
```sh |
||||
|
||||
go get -u github.com/minio/minio/pkg/madmin |
||||
|
||||
``` |
||||
|
||||
## Initialize Minio Admin Client |
||||
|
||||
You need four items to connect to Minio admin services. |
||||
|
||||
|
||||
| Parameter | Description| |
||||
| :--- | :--- | |
||||
| endpoint | URL to object storage service. | |
||||
| accessKeyID | Access key is the user ID that uniquely identifies your account. | |
||||
| secretAccessKey | Secret key is the password to your account. | |
||||
| secure | Set this value to 'true' to enable secure (HTTPS) access. | |
||||
|
||||
|
||||
```go |
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"github.com/minio/minio/pkg/madmin" |
||||
"log" |
||||
) |
||||
|
||||
func main() { |
||||
endpoint := "your-minio.example.com:9000" |
||||
accessKeyID := "YOUR-ACCESSKEYID" |
||||
secretAccessKey := "YOUR-SECRETKEY" |
||||
useSSL := true |
||||
|
||||
// Initialize minio admin client object. |
||||
madmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL) |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
|
||||
log.Println("%v", madmClnt) // Minio admin client is now setup |
||||
|
||||
|
||||
``` |
||||
|
||||
## Quick Start Example - Service Status. |
||||
|
||||
This example program connects to minio server, gets the current disk status. |
||||
|
||||
We will use the Minio server running at [https://your-minio.example.com:9000](https://your-minio.example.com:9000) in this example. Feel free to use this service for testing and development. Access credentials shown in this example are open to the public. |
||||
|
||||
#### ServiceStatus.go |
||||
|
||||
```go |
||||
package main |
||||
|
||||
import ( |
||||
"log" |
||||
|
||||
"github.com/minio/minio/pkg/madmin" |
||||
) |
||||
|
||||
func main() { |
||||
endpoint := "your-minio.example.com:9000" |
||||
accessKeyID := "YOUR-ACCESSKEYID" |
||||
secretAccessKey := "YOUR-SECRETKEY" |
||||
useSSL := true |
||||
|
||||
// Initialize minio admin client. |
||||
mdmClnt, err := madmin.New(endpoint, accessKeyID, secretAccessKey, useSSL) |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
|
||||
st, err := madmClnt.ServiceStatus() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Printf("%#v\n", st) |
||||
|
||||
} |
||||
|
||||
``` |
||||
|
||||
#### Run ServiceStatus |
||||
|
||||
```sh |
||||
|
||||
go run service-status.go |
||||
2016/12/20 16:46:01 madmin.ServiceStatusMetadata{Total:177038229504, Free:120365559808, Backend:struct { Type madmin.BackendType; OnlineDisks int; OfflineDisks int; ReadQuorum int; WriteQuorum int }{Type:1, OnlineDisks:0, OfflineDisks:0, ReadQuorum:0, WriteQuorum:0}} |
||||
|
||||
``` |
||||
|
||||
## API Reference |
||||
|
||||
### API Reference : Service Operations |
||||
|
||||
* [`ServiceStatus`](./API.md#ServiceStatus) |
||||
* [`ServiceStop`](./API.md#ServiceStop) |
||||
* [`ServiceRestart`](./API.md#ServiceRestart) |
||||
|
||||
## Full Examples |
||||
|
||||
#### Full Examples : Service Operations |
||||
|
||||
* [service-status.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-status.go) |
||||
* [service-stop.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-stop.go) |
||||
* [service-restart.go](https://github.com/minio/minio/blob/master/pkg/madmin/examples/service-restart.go) |
||||
|
||||
## Contribute |
||||
|
||||
[Contributors Guide](https://github.com/minio/minio/blob/master/CONTRIBUTING.md) |
||||
|
@ -0,0 +1,46 @@ |
||||
// +build ignore
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* 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 main |
||||
|
||||
import ( |
||||
"log" |
||||
|
||||
"github.com/minio/minio/pkg/madmin" |
||||
) |
||||
|
||||
func main() { |
||||
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
|
||||
// dummy values, please replace them with original values.
|
||||
|
||||
// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
|
||||
// This boolean value is the last argument for New().
|
||||
|
||||
// New returns an Minio Admin client object.
|
||||
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
|
||||
st, err := madmClnt.ServiceStatus() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Println(st) |
||||
} |
@ -0,0 +1,46 @@ |
||||
// +build ignore
|
||||
|
||||
/* |
||||
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||
* |
||||
* 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 main |
||||
|
||||
import ( |
||||
"log" |
||||
|
||||
"github.com/minio/minio/pkg/madmin" |
||||
) |
||||
|
||||
func main() { |
||||
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
|
||||
// dummy values, please replace them with original values.
|
||||
|
||||
// Requests are always secure (HTTPS) by default. Set secure=false to enable insecure (HTTP) access.
|
||||
// This boolean value is the last argument for New().
|
||||
|
||||
// New returns an Minio Admin client object.
|
||||
madmClnt, err := madmin.New("your-minio.example.com:9000", "YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", true) |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
|
||||
err = madmClnt.ServiceStop() |
||||
if err != nil { |
||||
log.Fatalln(err) |
||||
} |
||||
log.Println("Success") |
||||
} |
Loading…
Reference in new issue