From 867147c90efb036827706ea368cd7581b60cdba1 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Sat, 6 Jun 2020 08:19:10 -0400 Subject: [PATCH] api: add snapshot restore --- api/api.go | 4 ++++ api/operator.go | 11 +++++++++++ vendor/github.com/hashicorp/nomad/api/api.go | 4 ++++ vendor/github.com/hashicorp/nomad/api/operator.go | 11 +++++++++++ 4 files changed, 30 insertions(+) diff --git a/api/api.go b/api/api.go index 95fcd7344..83ccf6bd2 100644 --- a/api/api.go +++ b/api/api.go @@ -945,6 +945,10 @@ func decodeBody(resp *http.Response, out interface{}) error { // encodeBody is used to encode a request body func encodeBody(obj interface{}) (io.Reader, error) { + if reader, ok := obj.(io.Reader); ok { + return reader, nil + } + buf := bytes.NewBuffer(nil) enc := json.NewEncoder(buf) if err := enc.Encode(obj); err != nil { diff --git a/api/operator.go b/api/operator.go index ddcc531e5..3fad32aa3 100644 --- a/api/operator.go +++ b/api/operator.go @@ -222,6 +222,17 @@ func (op *Operator) Snapshot(q *QueryOptions) (io.ReadCloser, error) { return cr, nil } +// SnapshotRestore is used to restore a running nomad cluster to an original +// state. +func (op *Operator) SnapshotRestore(in io.Reader, q *WriteOptions) (*WriteMeta, error) { + wm, err := op.c.write("/v1/operator/snapshot", in, nil, q) + if err != nil { + return nil, err + } + + return wm, nil +} + type License struct { // The unique identifier of the license LicenseID string diff --git a/vendor/github.com/hashicorp/nomad/api/api.go b/vendor/github.com/hashicorp/nomad/api/api.go index 95fcd7344..83ccf6bd2 100644 --- a/vendor/github.com/hashicorp/nomad/api/api.go +++ b/vendor/github.com/hashicorp/nomad/api/api.go @@ -945,6 +945,10 @@ func decodeBody(resp *http.Response, out interface{}) error { // encodeBody is used to encode a request body func encodeBody(obj interface{}) (io.Reader, error) { + if reader, ok := obj.(io.Reader); ok { + return reader, nil + } + buf := bytes.NewBuffer(nil) enc := json.NewEncoder(buf) if err := enc.Encode(obj); err != nil { diff --git a/vendor/github.com/hashicorp/nomad/api/operator.go b/vendor/github.com/hashicorp/nomad/api/operator.go index ddcc531e5..3fad32aa3 100644 --- a/vendor/github.com/hashicorp/nomad/api/operator.go +++ b/vendor/github.com/hashicorp/nomad/api/operator.go @@ -222,6 +222,17 @@ func (op *Operator) Snapshot(q *QueryOptions) (io.ReadCloser, error) { return cr, nil } +// SnapshotRestore is used to restore a running nomad cluster to an original +// state. +func (op *Operator) SnapshotRestore(in io.Reader, q *WriteOptions) (*WriteMeta, error) { + wm, err := op.c.write("/v1/operator/snapshot", in, nil, q) + if err != nil { + return nil, err + } + + return wm, nil +} + type License struct { // The unique identifier of the license LicenseID string