2017-01-16 18:26:26 -05:00
# Golang Admin Client API Reference [![Slack](https://slack.minio.io/slack?type=svg)](https://slack.minio.io)
2016-12-20 21:49:48 -05:00
## Initialize Minio Admin Client object.
## Minio
```go
package main
import (
2017-01-17 13:02:58 -05:00
"fmt"
2016-12-20 21:49:48 -05:00
2017-01-17 13:02:58 -05:00
"github.com/minio/minio/pkg/madmin"
2016-12-20 21:49:48 -05:00
)
func main() {
2017-01-17 13:02:58 -05:00
// 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)
2016-12-20 21:49:48 -05:00
}
```
2017-02-25 14:06:08 -05:00
| Service operations|LockInfo operations|Healing operations|Config operations| Misc |
|:---|:---|:---|:---|:---|
|[`ServiceStatus`](#ServiceStatus)| [`ListLocks` ](#ListLocks )| [`ListObjectsHeal` ](#ListObjectsHeal )|[`GetConfig`](#GetConfig)| [`SetCredentials` ](#SetCredentials )|
2017-02-27 14:40:27 -05:00
|[`ServiceRestart`](#ServiceRestart)| [`ClearLocks` ](#ClearLocks )| [`ListBucketsHeal` ](#ListBucketsHeal )|[`SetConfig`](#SetConfig)||
2017-02-25 14:06:08 -05:00
| | |[`HealBucket`](#HealBucket) |||
| | |[`HealObject`](#HealObject)|||
| | |[`HealFormat`](#HealFormat)|||
2016-12-20 21:49:48 -05:00
## 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)
2017-01-17 13:02:58 -05:00
Fetch service status, replies disk space used, backend type and total disks offline/online (applicable in distributed mode).
2016-12-20 21:49:48 -05:00
| Param | Type | Description |
|---|---|---|
2017-01-17 13:02:58 -05:00
|`serviceStatus` | _ServiceStatusMetadata_ | Represents current server status info in following format: |
2016-12-20 21:49:48 -05:00
| Param | Type | Description |
|---|---|---|
2017-01-23 11:56:06 -05:00
|`st.ServerVersion.Version` | _string_ | Server version. |
|`st.ServerVersion.CommitID` | _string_ | Server commit id. |
|`st.StorageInfo.Total` | _int64_ | Total disk space. |
|`st.StorageInfo.Free` | _int64_ | Free disk space. |
|`st.StorageInfo.Backend`| _struct{}_ | Represents backend type embedded structure. |
2016-12-20 21:49:48 -05:00
| Param | Type | Description |
|---|---|---|
2017-02-10 02:26:44 -05:00
|`backend.Type` | _BackendType_ | Type of backend used by the server currently only FS or Erasure. |
|`backend.OnlineDisks`| _int_ | Total number of disks online (only applies to Erasure backend), is empty for FS. |
|`backend.OfflineDisks` | _int_ | Total number of disks offline (only applies to Erasure backend), is empty for FS. |
2016-12-20 21:49:48 -05:00
|`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__
2017-01-17 13:02:58 -05:00
2016-12-20 21:49:48 -05:00
```go
st, err := madmClnt.ServiceStatus()
if err != nil {
log.Fatalln(err)
}
log.Printf("%#v\n", st)
```
< a name = "ServiceRestart" > < / a >
### ServiceRestart() (error)
If successful restarts the running minio service, for distributed setup restarts all remote minio servers.
__Example__
2017-01-17 13:02:58 -05:00
2016-12-20 21:49:48 -05:00
```go
st, err := madmClnt.ServiceRestart()
if err != nil {
log.Fatalln(err)
}
2017-01-17 13:02:58 -05:00
log.Printf("Success")
2016-12-20 21:49:48 -05:00
```
2017-02-25 14:06:08 -05:00
2017-04-21 10:15:53 -04:00
## 3. Info operations
< a name = "ServerInfo" > < / a >
### ServerInfo() ([]ServerInfo, error)
Fetch all information for all cluster nodes, such as uptime, region, network statistics, etc..
__Example__
```go
serversInfo, err := madmClnt.ServerInfo()
if err != nil {
log.Fatalln(err)
}
for _, peerInfo := range serversInfo {
log.Printf("Node: %s, Info: %v\n", peerInfo.Addr, peerInfo.Data)
}
```
## 4. Lock operations
2017-02-25 14:06:08 -05:00
2017-01-17 13:02:58 -05:00
< a name = "ListLocks" > < / a >
2017-02-01 14:17:30 -05:00
### ListLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error)
If successful returns information on the list of locks held on ``bucket`` matching ``prefix`` for longer than ``duration`` seconds.
2017-01-17 13:02:58 -05:00
__Example__
``` go
volLocks, err := madmClnt.ListLocks("mybucket", "myprefix", 30 * time.Second)
if err != nil {
log.Fatalln(err)
}
log.Println("List of locks: ", volLocks)
```
< a name = "ClearLocks" > < / a >
2017-02-01 14:17:30 -05:00
### ClearLocks(bucket, prefix string, duration time.Duration) ([]VolumeLockInfo, error)
If successful returns information on the list of locks cleared on ``bucket`` matching ``prefix`` for longer than ``duration`` seconds.
2017-01-17 13:02:58 -05:00
__Example__
2016-12-20 21:49:48 -05:00
2017-01-17 13:02:58 -05:00
``` go
volLocks, err := madmClnt.ClearLocks("mybucket", "myprefix", 30 * time.Second)
if err != nil {
log.Fatalln(err)
}
log.Println("List of locks cleared: ", volLocks)
```
2017-04-21 10:15:53 -04:00
## 5. Heal operations
2017-02-25 14:06:08 -05:00
2017-01-17 13:02:58 -05:00
< a name = "ListObjectsHeal" > < / a >
### ListObjectsHeal(bucket, prefix string, recursive bool, doneCh <-chan struct{}) (<-chan ObjectInfo, error)
If successful returns information on the list of objects that need healing in ``bucket`` matching ``prefix``.
__Example__
``` go
// Create a done channel to control 'ListObjectsHeal' go routine.
doneCh := make(chan struct{})
// Indicate to our routine to exit cleanly upon return.
defer close(doneCh)
// Set true if recursive listing is needed.
isRecursive := true
// List objects that need healing for a given bucket and
// prefix.
healObjectCh, err := madmClnt.ListObjectsHeal("mybucket", "myprefix", isRecursive, doneCh)
if err != nil {
fmt.Println(err)
return
}
for object := range healObjectsCh {
if object.Err != nil {
log.Fatalln(err)
return
}
2017-01-19 12:34:18 -05:00
if object.HealObjectInfo != nil {
switch healInfo := *object.HealObjectInfo; healInfo.Status {
2017-01-17 13:02:58 -05:00
case madmin.CanHeal:
fmt.Println(object.Key, " can be healed.")
case madmin.QuorumUnavailable:
fmt.Println(object.Key, " can't be healed until quorum is available.")
case madmin.Corrupted:
fmt.Println(object.Key, " can't be healed, not enough information.")
}
}
fmt.Println("object: ", object)
}
```
2017-01-23 03:32:55 -05:00
< a name = "ListBucketsHeal" > < / a >
### ListBucketsHeal() error
2017-01-19 12:34:18 -05:00
If successful returns information on the list of buckets that need healing.
__Example__
``` go
2017-01-23 03:32:55 -05:00
// List buckets that need healing
2017-01-19 12:34:18 -05:00
healBucketsList, err := madmClnt.ListBucketsHeal()
if err != nil {
fmt.Println(err)
return
}
for bucket := range healBucketsList {
if bucket.HealBucketInfo != nil {
switch healInfo := *object.HealBucketInfo; healInfo.Status {
case madmin.CanHeal:
fmt.Println(bucket.Key, " can be healed.")
case madmin.QuorumUnavailable:
fmt.Println(bucket.Key, " can't be healed until quorum is available.")
case madmin.Corrupted:
fmt.Println(bucket.Key, " can't be healed, not enough information.")
}
}
fmt.Println("bucket: ", bucket)
}
```
2017-01-17 13:02:58 -05:00
< a name = "HealBucket" > < / a >
### HealBucket(bucket string, isDryRun bool) error
If bucket is successfully healed returns nil, otherwise returns error indicating the reason for failure. If isDryRun is true, then the bucket is not healed, but heal bucket request is validated by the server. e.g, if the bucket exists, if bucket name is valid etc.
__Example__
``` go
isDryRun := false
err := madmClnt.HealBucket("mybucket", isDryRun)
if err != nil {
log.Fatalln(err)
}
log.Println("successfully healed mybucket")
```
< a name = "HealObject" > < / a >
2017-04-03 11:25:32 -04:00
### HealObject(bucket, object string, isDryRun bool) (HealResult, error)
2017-01-17 13:02:58 -05:00
If object is successfully healed returns nil, otherwise returns error indicating the reason for failure. If isDryRun is true, then the object is not healed, but heal object request is validated by the server. e.g, if the object exists, if object name is valid etc.
2017-04-14 13:28:35 -04:00
| Param | Type | Description |
|---|---|---|
|`h.State` | _HealState_ | Represents the result of heal operation. It could be one of `HealNone` , `HealPartial` or `HealOK` . |
| Value | Description |
|---|---|
|`HealNone` | Object/Upload wasn't healed on any of the disks |
|`HealPartial` | Object/Upload was healed on some of the disks needing heal |
| `HealOK` | Object/Upload was healed on all the disks needing heal |
2017-01-17 13:02:58 -05:00
__Example__
``` go
2017-03-31 20:55:15 -04:00
isDryRun = false
healResult, err := madmClnt.HealObject("mybucket", "myobject", isDryRun)
2017-01-17 13:02:58 -05:00
if err != nil {
log.Fatalln(err)
}
2017-03-31 20:55:15 -04:00
log.Println("Heal-object result: ", healResult)
2017-01-17 13:02:58 -05:00
```
2017-01-23 03:32:55 -05:00
< a name = "HealFormat" > < / a >
2017-01-24 11:11:05 -05:00
### HealFormat(isDryRun bool) error
2017-01-23 03:32:55 -05:00
Heal storage format on available disks. This is used when disks were replaced or were found with missing format. This is supported only for erasure-coded backend.
__Example__
``` go
2017-01-24 11:11:05 -05:00
isDryRun := true
err := madmClnt.HealFormat(isDryRun)
if err != nil {
log.Fatalln(err)
}
isDryRun = false
err = madmClnt.HealFormat(isDryRun)
2017-01-23 03:32:55 -05:00
if err != nil {
log.Fatalln(err)
}
log.Println("successfully healed storage format on available disks.")
```
2017-02-25 14:06:08 -05:00
2017-04-21 10:15:53 -04:00
## 6. Config operations
2017-02-25 14:06:08 -05:00
2017-02-20 15:58:50 -05:00
< a name = "GetConfig" > < / a >
### GetConfig() ([]byte, error)
Get config.json of a minio setup.
__Example__
``` go
configBytes, err := madmClnt.GetConfig()
if err != nil {
log.Fatalf("failed due to: %v", err)
}
// Pretty-print config received as json.
var buf bytes.Buffer
err = json.Indent(buf, configBytes, "", "\t")
if err != nil {
log.Fatalf("failed due to: %v", err)
}
log.Println("config received successfully: ", string(buf.Bytes()))
```
2017-02-25 14:06:08 -05:00
2017-02-27 14:40:27 -05:00
< a name = "SetConfig" > < / a >
### SetConfig(config io.Reader) (SetConfigResult, error)
Set config.json of a minio setup and restart setup for configuration
change to take effect.
2017-02-25 14:06:08 -05:00
2017-02-27 14:40:27 -05:00
| Param | Type | Description |
|---|---|---|
|`st.Status` | _bool_ | true if set-config succeeded, false otherwise. |
|`st.NodeSummary.Name` | _string_ | Network address of the node. |
2017-03-03 05:53:48 -05:00
|`st.NodeSummary.ErrSet` | _bool_ | Bool representation indicating if an error is encountered with the node.|
|`st.NodeSummary.ErrMsg` | _string_ | String representation of the error (if any) on the node.|
2017-02-27 14:40:27 -05:00
__Example__
``` go
config := bytes.NewReader([]byte(`config.json contents go here`))
result, err := madmClnt.SetConfig(config)
if err != nil {
log.Fatalf("failed due to: %v", err)
}
var buf bytes.Buffer
enc := json.NewEncoder(& buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
err = enc.Encode(result)
if err != nil {
log.Fatalln(err)
}
log.Println("SetConfig: ", string(buf.Bytes()))
```
2017-04-21 10:15:53 -04:00
## 7. Misc operations
< a name = "SetCredentials" > < / a >
### SetCredentials() error
Set new credentials of a Minio setup.
__Example__
``` go
err = madmClnt.SetCredentials("YOUR-NEW-ACCESSKEY", "YOUR-NEW-SECRETKEY")
if err != nil {
log.Fatalln(err)
}
log.Println("New credentials successfully set.")
```