Remove scaleio from volume plugins

This commit is contained in:
Jiawei Wang 2021-04-30 16:41:06 -07:00
parent bacab40a9f
commit 94db1e18ba
35 changed files with 0 additions and 9990 deletions

View File

@ -1,206 +0,0 @@
= vendor/github.com/thecodeteam/goscaleio licensed under: =
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.
= vendor/github.com/thecodeteam/goscaleio/LICENSE d2794c0df5b907fdace235a619d80314

View File

@ -43,7 +43,6 @@ import (
"k8s.io/kubernetes/pkg/volume/portworx"
"k8s.io/kubernetes/pkg/volume/quobyte"
"k8s.io/kubernetes/pkg/volume/rbd"
"k8s.io/kubernetes/pkg/volume/scaleio"
"k8s.io/kubernetes/pkg/volume/storageos"
volumeutil "k8s.io/kubernetes/pkg/volume/util"
@ -65,7 +64,6 @@ func ProbeAttachableVolumePlugins() ([]volume.VolumePlugin, error) {
return allPlugins, err
}
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, iscsi.ProbeVolumePlugins()...)
@ -92,7 +90,6 @@ func ProbeExpandableVolumePlugins(config persistentvolumeconfig.VolumeConfigurat
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, glusterfs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
return allPlugins, nil
@ -145,7 +142,6 @@ func ProbeControllerVolumePlugins(cloud cloudprovider.Interface, config persiste
allPlugins = append(allPlugins, flocker.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, local.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)

View File

@ -41,7 +41,6 @@ import (
"k8s.io/kubernetes/pkg/volume/projected"
"k8s.io/kubernetes/pkg/volume/quobyte"
"k8s.io/kubernetes/pkg/volume/rbd"
"k8s.io/kubernetes/pkg/volume/scaleio"
"k8s.io/kubernetes/pkg/volume/secret"
"k8s.io/kubernetes/pkg/volume/storageos"
@ -80,7 +79,6 @@ func ProbeVolumePlugins(featureGate featuregate.FeatureGate) ([]volume.VolumePlu
allPlugins = append(allPlugins, configmap.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, projected.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, local.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)

2
go.mod
View File

@ -85,7 +85,6 @@ require (
github.com/spf13/viper v1.7.0
github.com/storageos/go-api v2.2.0+incompatible
github.com/stretchr/testify v1.7.0
github.com/thecodeteam/goscaleio v0.1.0
github.com/urfave/negroni v1.0.0 // indirect
github.com/vishvananda/netlink v1.1.0
github.com/vmware/govmomi v0.20.3
@ -429,7 +428,6 @@ replace (
github.com/stretchr/testify => github.com/stretchr/testify v1.7.0
github.com/subosito/gotenv => github.com/subosito/gotenv v1.2.0
github.com/syndtr/gocapability => github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
github.com/thecodeteam/goscaleio => github.com/thecodeteam/goscaleio v0.1.0
github.com/tidwall/pretty => github.com/tidwall/pretty v1.0.0
github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
github.com/urfave/cli => github.com/urfave/cli v1.22.2

2
go.sum
View File

@ -468,8 +468,6 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/thecodeteam/goscaleio v0.1.0 h1:SB5tO98lawC+UK8ds/U2jyfOCH7GTcFztcF5x9gbut4=
github.com/thecodeteam/goscaleio v0.1.0/go.mod h1:68sdkZAsK8bvEwBlbQnlLS+xU+hvLYM/iQ8KXej1AwM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=

View File

@ -54,7 +54,6 @@ import (
"k8s.io/kubernetes/pkg/volume/projected"
"k8s.io/kubernetes/pkg/volume/quobyte"
"k8s.io/kubernetes/pkg/volume/rbd"
"k8s.io/kubernetes/pkg/volume/scaleio"
"k8s.io/kubernetes/pkg/volume/secret"
"k8s.io/kubernetes/pkg/volume/storageos"
"k8s.io/kubernetes/pkg/volume/util/hostutil"
@ -86,7 +85,6 @@ func volumePlugins() []volume.VolumePlugin {
allPlugins = append(allPlugins, configmap.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, projected.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, local.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)

View File

@ -1,582 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"time"
utilexec "k8s.io/utils/exec"
sio "github.com/thecodeteam/goscaleio"
siotypes "github.com/thecodeteam/goscaleio/types/v1"
"k8s.io/klog/v2"
proxyutil "k8s.io/kubernetes/pkg/proxy/util"
)
var (
sioDiskIDPath = "/dev/disk/by-id"
)
type sioVolumeID string
type sioInterface interface {
FindVolume(name string) (*siotypes.Volume, error)
Volume(sioVolumeID) (*siotypes.Volume, error)
CreateVolume(name string, sizeGB int64) (*siotypes.Volume, error)
AttachVolume(sioVolumeID, bool) error
DetachVolume(sioVolumeID) error
DeleteVolume(sioVolumeID) error
IID() (string, error)
Devs() (map[string]string, error)
WaitForAttachedDevice(token string) (string, error)
WaitForDetachedDevice(token string) error
GetVolumeRefs(sioVolumeID) (int, error)
}
type sioClient struct {
client *sio.Client
gateway string
username string
password string `datapolicy:"password"`
insecure bool
certsEnabled bool
system *siotypes.System
sysName string
sysClient *sio.System
protectionDomain *siotypes.ProtectionDomain
pdName string
pdClient *sio.ProtectionDomain
storagePool *siotypes.StoragePool
spName string
spClient *sio.StoragePool
provisionMode string
sdcPath string
sdcGUID string
instanceID string
inited bool
diskRegex *regexp.Regexp
mtx sync.Mutex
exec utilexec.Interface
filteredDialOptions *proxyutil.FilteredDialOptions
}
func newSioClient(gateway, username, password string, sslEnabled bool, exec utilexec.Interface, filteredDialOptions *proxyutil.FilteredDialOptions) (*sioClient, error) {
client := new(sioClient)
client.gateway = gateway
client.username = username
client.password = password
client.exec = exec
client.filteredDialOptions = filteredDialOptions
if sslEnabled {
client.insecure = false
client.certsEnabled = true
} else {
client.insecure = true
client.certsEnabled = false
}
r, err := regexp.Compile(`^emc-vol-\w*-\w*$`)
if err != nil {
klog.Error(log("failed to compile regex: %v", err))
return nil, err
}
client.diskRegex = r
// delay client setup/login until init()
return client, nil
}
// init setups client and authenticate
func (c *sioClient) init() error {
c.mtx.Lock()
defer c.mtx.Unlock()
if c.inited {
return nil
}
klog.V(4).Infoln(log("initializing scaleio client"))
client, err := sio.NewClientWithArgs(c.gateway, "", c.insecure, c.certsEnabled)
if err != nil {
klog.Error(log("failed to create client: %v", err))
return err
}
transport, ok := client.Http.Transport.(*http.Transport)
if !ok {
return errors.New("could not set http.Transport options for scaleio client")
}
//lint:ignore SA1019 DialTLS must be used to support legacy clients.
if transport.DialTLS != nil {
return errors.New("DialTLS will be used instead of DialContext")
}
transport.DialContext = proxyutil.NewFilteredDialContext(transport.DialContext, nil, c.filteredDialOptions)
c.client = client
if _, err = c.client.Authenticate(
&sio.ConfigConnect{
Endpoint: c.gateway,
Version: "",
Username: c.username,
Password: c.password},
); err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("client authentication failed: %v", err))
return errors.New("client authentication failed")
}
// retrieve system
if c.system, err = c.findSystem(c.sysName); err != nil {
klog.Error(log("unable to find system %s: %v", c.sysName, err))
return err
}
// retrieve protection domain
if c.protectionDomain, err = c.findProtectionDomain(c.pdName); err != nil {
klog.Error(log("unable to find protection domain %s: %v", c.protectionDomain, err))
return err
}
// retrieve storage pool
if c.storagePool, err = c.findStoragePool(c.spName); err != nil {
klog.Error(log("unable to find storage pool %s: %v", c.storagePool, err))
return err
}
c.inited = true
return nil
}
func (c *sioClient) Volumes() ([]*siotypes.Volume, error) {
if err := c.init(); err != nil {
return nil, err
}
vols, err := c.getVolumes()
if err != nil {
klog.Error(log("failed to retrieve volumes: %v", err))
return nil, err
}
return vols, nil
}
func (c *sioClient) Volume(id sioVolumeID) (*siotypes.Volume, error) {
if err := c.init(); err != nil {
return nil, err
}
vols, err := c.getVolumesByID(id)
if err != nil {
klog.Error(log("failed to retrieve volume by id: %v", err))
return nil, err
}
vol := vols[0]
if vol == nil {
klog.V(4).Info(log("volume not found, id %s", id))
return nil, errors.New("volume not found")
}
return vol, nil
}
func (c *sioClient) FindVolume(name string) (*siotypes.Volume, error) {
if err := c.init(); err != nil {
return nil, err
}
klog.V(4).Info(log("searching for volume %s", name))
volumes, err := c.getVolumesByName(name)
if err != nil {
klog.Error(log("failed to find volume by name %v", err))
return nil, err
}
for _, volume := range volumes {
if volume.Name == name {
klog.V(4).Info(log("found volume %s", name))
return volume, nil
}
}
klog.V(4).Info(log("volume not found, name %s", name))
return nil, errors.New("volume not found")
}
func (c *sioClient) CreateVolume(name string, sizeGB int64) (*siotypes.Volume, error) {
if err := c.init(); err != nil {
return nil, err
}
params := &siotypes.VolumeParam{
Name: name,
VolumeSizeInKb: strconv.Itoa(int(sizeGB) * 1024 * 1024),
VolumeType: c.provisionMode,
}
createResponse, err := c.client.CreateVolume(params, c.storagePool.Name)
if err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("failed to create volume %s: %v", name, err))
return nil, errors.New("failed to create volume: see kubernetes logs for details")
}
return c.Volume(sioVolumeID(createResponse.ID))
}
// AttachVolume maps the scaleio volume to an sdc node. If the multipleMappings flag
// is true, ScaleIO will allow other SDC to map to that volume.
func (c *sioClient) AttachVolume(id sioVolumeID, multipleMappings bool) error {
if err := c.init(); err != nil {
klog.Error(log("failed to init'd client in attach volume: %v", err))
return err
}
iid, err := c.IID()
if err != nil {
klog.Error(log("failed to get instanceIID for attach volume: %v", err))
return err
}
params := &siotypes.MapVolumeSdcParam{
SdcID: iid,
AllowMultipleMappings: strconv.FormatBool(multipleMappings),
AllSdcs: "",
}
volClient := sio.NewVolume(c.client)
volClient.Volume = &siotypes.Volume{ID: string(id)}
if err := volClient.MapVolumeSdc(params); err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("failed to attach volume id %s: %v", id, err))
return errors.New("failed to attach volume: see kubernetes logs for details")
}
klog.V(4).Info(log("volume %s attached successfully", id))
return nil
}
// DetachVolume detaches the volume with specified id.
func (c *sioClient) DetachVolume(id sioVolumeID) error {
if err := c.init(); err != nil {
return err
}
iid, err := c.IID()
if err != nil {
return err
}
params := &siotypes.UnmapVolumeSdcParam{
SdcID: "",
IgnoreScsiInitiators: "true",
AllSdcs: iid,
}
volClient := sio.NewVolume(c.client)
volClient.Volume = &siotypes.Volume{ID: string(id)}
if err := volClient.UnmapVolumeSdc(params); err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("failed to detach volume id %s: %v", id, err))
return errors.New("failed to detach volume: see kubernetes logs for details")
}
return nil
}
// DeleteVolume deletes the volume with the specified id
func (c *sioClient) DeleteVolume(id sioVolumeID) error {
if err := c.init(); err != nil {
return err
}
vol, err := c.Volume(id)
if err != nil {
return err
}
volClient := sio.NewVolume(c.client)
volClient.Volume = vol
if err := volClient.RemoveVolume("ONLY_ME"); err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("failed to remove volume id %s: %v", id, err))
return errors.New("failed to remove volume: see kubernetes logs for details")
}
return nil
}
// IID returns the scaleio instance id for node
func (c *sioClient) IID() (string, error) {
if err := c.init(); err != nil {
return "", err
}
// if instanceID not set, retrieve it
if c.instanceID == "" {
guid, err := c.getGUID()
if err != nil {
return "", err
}
sdc, err := c.sysClient.FindSdc("SdcGUID", guid)
if err != nil {
// don't log error details from client calls in events
klog.V(4).Infof(log("failed to retrieve sdc info %s", err))
return "", errors.New("failed to retrieve sdc info: see kubernetes logs for details")
}
c.instanceID = sdc.Sdc.ID
klog.V(4).Info(log("retrieved instanceID %s", c.instanceID))
}
return c.instanceID, nil
}
// getGUID returns instance GUID, if not set using resource labels
// it attempts to fallback to using drv_cfg binary
func (c *sioClient) getGUID() (string, error) {
if c.sdcGUID == "" {
klog.V(4).Info(log("sdc guid label not set, falling back to using drv_cfg"))
cmd := c.getSdcCmd()
output, err := c.exec.Command(cmd, "--query_guid").CombinedOutput()
if err != nil {
klog.Error(log("drv_cfg --query_guid failed: %v", err))
return "", err
}
c.sdcGUID = strings.TrimSpace(string(output))
}
return c.sdcGUID, nil
}
// getSioDiskPaths traverse local disk devices to retrieve device path
// The path is extracted from /dev/disk/by-id; each sio device path has format:
// emc-vol-<mdmID-volID> e.g.:
// emc-vol-788d9efb0a8f20cb-a2b8419300000000
func (c *sioClient) getSioDiskPaths() ([]os.FileInfo, error) {
files, err := ioutil.ReadDir(sioDiskIDPath)
if err != nil {
if os.IsNotExist(err) {
// sioDiskIDPath may not exist yet which is fine
return []os.FileInfo{}, nil
}
klog.Error(log("failed to ReadDir %s: %v", sioDiskIDPath, err))
return nil, err
}
result := []os.FileInfo{}
for _, file := range files {
if c.diskRegex.MatchString(file.Name()) {
result = append(result, file)
}
}
return result, nil
}
// GetVolumeRefs counts the number of references an SIO volume has a disk device.
// This is useful in preventing premature detach.
func (c *sioClient) GetVolumeRefs(volID sioVolumeID) (refs int, err error) {
files, err := c.getSioDiskPaths()
if err != nil {
return 0, err
}
for _, file := range files {
if strings.Contains(file.Name(), string(volID)) {
refs++
}
}
return
}
// Devs returns a map of local devices as map[<volume.id>]<deviceName>
func (c *sioClient) Devs() (map[string]string, error) {
volumeMap := make(map[string]string)
files, err := c.getSioDiskPaths()
if err != nil {
return nil, err
}
for _, f := range files {
// split emc-vol-<mdmID>-<volumeID> to pull out volumeID
parts := strings.Split(f.Name(), "-")
if len(parts) != 4 {
return nil, errors.New("unexpected ScaleIO device name format")
}
volumeID := parts[3]
devPath, err := filepath.EvalSymlinks(fmt.Sprintf("%s/%s", sioDiskIDPath, f.Name()))
if err != nil {
klog.Error(log("devicepath-to-volID mapping error: %v", err))
return nil, err
}
// map volumeID to devicePath
volumeMap[volumeID] = devPath
}
return volumeMap, nil
}
// WaitForAttachedDevice sets up a timer to wait for an attached device to appear in the instance's list.
func (c *sioClient) WaitForAttachedDevice(token string) (string, error) {
if token == "" {
return "", fmt.Errorf("invalid attach token")
}
// wait for device to show up in local device list
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
timer := time.NewTimer(30 * time.Second)
defer timer.Stop()
for {
select {
case <-ticker.C:
devMap, err := c.Devs()
if err != nil {
klog.Error(log("failed while waiting for volume to attach: %v", err))
return "", err
}
go func() {
klog.V(4).Info(log("waiting for volume %s to be mapped/attached", token))
}()
if path, ok := devMap[token]; ok {
klog.V(4).Info(log("device %s mapped to vol %s", path, token))
return path, nil
}
case <-timer.C:
klog.Error(log("timed out while waiting for volume to be mapped to a device"))
return "", fmt.Errorf("volume attach timeout")
}
}
}
// waitForDetachedDevice waits for device to be detached
func (c *sioClient) WaitForDetachedDevice(token string) error {
if token == "" {
return fmt.Errorf("invalid detach token")
}
// wait for attach.Token to show up in local device list
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
timer := time.NewTimer(30 * time.Second)
defer timer.Stop()
for {
select {
case <-ticker.C:
devMap, err := c.Devs()
if err != nil {
klog.Error(log("failed while waiting for volume to unmap/detach: %v", err))
return err
}
go func() {
klog.V(4).Info(log("waiting for volume %s to be unmapped/detached", token))
}()
// can't find vol id, then ok.
if _, ok := devMap[token]; !ok {
return nil
}
case <-timer.C:
klog.Error(log("timed out while waiting for volume %s to be unmapped/detached", token))
return fmt.Errorf("volume detach timeout")
}
}
}
// ***********************************************************************
// Little Helpers!
// ***********************************************************************
func (c *sioClient) findSystem(sysname string) (sys *siotypes.System, err error) {
if c.sysClient, err = c.client.FindSystem("", sysname, ""); err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to find system %q: %v", sysname, err))
return nil, errors.New("failed to find system: see kubernetes logs for details")
}
systems, err := c.client.GetInstance("")
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to retrieve instances: %v", err))
return nil, errors.New("failed to retrieve instances: see kubernetes logs for details")
}
for _, sys = range systems {
if sys.Name == sysname {
return sys, nil
}
}
klog.Error(log("system %s not found", sysname))
return nil, errors.New("system not found")
}
func (c *sioClient) findProtectionDomain(pdname string) (*siotypes.ProtectionDomain, error) {
c.pdClient = sio.NewProtectionDomain(c.client)
if c.sysClient != nil {
protectionDomain, err := c.sysClient.FindProtectionDomain("", pdname, "")
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to retrieve protection domains: %v", err))
return nil, errors.New("failed to retrieve protection domains: see kubernetes logs for details")
}
c.pdClient.ProtectionDomain = protectionDomain
return protectionDomain, nil
}
klog.Error(log("protection domain %s not set", pdname))
return nil, errors.New("protection domain not set")
}
func (c *sioClient) findStoragePool(spname string) (*siotypes.StoragePool, error) {
c.spClient = sio.NewStoragePool(c.client)
if c.pdClient != nil {
sp, err := c.pdClient.FindStoragePool("", spname, "")
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to retrieve storage pool: %v", err))
return nil, errors.New("failed to retrieve storage pool: see kubernetes logs for details")
}
c.spClient.StoragePool = sp
return sp, nil
}
klog.Error(log("storage pool %s not set", spname))
return nil, errors.New("storage pool not set")
}
func (c *sioClient) getVolumes() ([]*siotypes.Volume, error) {
volumes, err := c.client.GetVolume("", "", "", "", true)
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to get volumes: %v", err))
return nil, errors.New("failed to get volumes: see kubernetes logs for details")
}
return volumes, nil
}
func (c *sioClient) getVolumesByID(id sioVolumeID) ([]*siotypes.Volume, error) {
volumes, err := c.client.GetVolume("", string(id), "", "", true)
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to get volumes by id: %v", err))
return nil, errors.New("failed to get volumes by id: see kubernetes logs for details")
}
return volumes, nil
}
func (c *sioClient) getVolumesByName(name string) ([]*siotypes.Volume, error) {
volumes, err := c.client.GetVolume("", "", "", name, true)
if err != nil {
// don't log error details from clients in events
klog.V(4).Infof(log("failed to get volumes by name: %v", err))
return nil, errors.New("failed to get volumes by name: see kubernetes logs for details")
}
return volumes, nil
}
func (c *sioClient) getSdcPath() string {
return sdcRootPath
}
func (c *sioClient) getSdcCmd() string {
return filepath.Join(c.getSdcPath(), "drv_cfg")
}

View File

@ -1,241 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"errors"
"strconv"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/volume"
utilexec "k8s.io/utils/exec"
siotypes "github.com/thecodeteam/goscaleio/types/v1"
)
type sioMgr struct {
client sioInterface
configData map[string]string
exec utilexec.Interface
host volume.VolumeHost
}
func newSioMgr(configs map[string]string, host volume.VolumeHost, exec utilexec.Interface) (*sioMgr, error) {
if configs == nil {
return nil, errors.New("missing configuration data")
}
configs[confKey.protectionDomain] = defaultString(configs[confKey.protectionDomain], "default")
configs[confKey.storagePool] = defaultString(configs[confKey.storagePool], "default")
configs[confKey.sdcRootPath] = defaultString(configs[confKey.sdcRootPath], sdcRootPath)
configs[confKey.storageMode] = defaultString(configs[confKey.storageMode], "ThinProvisioned")
mgr := &sioMgr{configData: configs, host: host, exec: exec}
return mgr, nil
}
// getClient safely returns an sioInterface
func (m *sioMgr) getClient() (sioInterface, error) {
if m.client == nil {
klog.V(4).Info(log("creating scaleio client"))
configs := m.configData
username := configs[confKey.username]
password := configs[confKey.password]
gateway := configs[confKey.gateway]
b, err := strconv.ParseBool(configs[confKey.sslEnabled])
if err != nil {
klog.Error(log("failed to parse sslEnabled, must be either \"true\" or \"false\""))
return nil, err
}
certsEnabled := b
klog.V(4).Info(log("creating new client for gateway %s", gateway))
client, err := newSioClient(gateway, username, password, certsEnabled, m.exec, m.host.GetFilteredDialOptions())
if err != nil {
klog.Error(log("failed to create scaleio client: %v", err))
return nil, err
}
client.sysName = configs[confKey.system]
client.pdName = configs[confKey.protectionDomain]
client.spName = configs[confKey.storagePool]
client.sdcPath = configs[confKey.sdcRootPath]
client.provisionMode = configs[confKey.storageMode]
client.sdcGUID = configs[confKey.sdcGUID]
m.client = client
klog.V(4).Info(log("client created successfully [gateway=%s]", gateway))
}
return m.client, nil
}
// CreateVolume creates a new ScaleIO volume
func (m *sioMgr) CreateVolume(volName string, sizeGB int64) (*siotypes.Volume, error) {
client, err := m.getClient()
if err != nil {
return nil, err
}
klog.V(4).Infof("scaleio: creating volume %s", volName)
vol, err := client.CreateVolume(volName, sizeGB)
if err != nil {
klog.V(4).Infof("scaleio: failed creating volume %s: %v", volName, err)
return nil, err
}
klog.V(4).Infof("scaleio: created volume %s successfully", volName)
return vol, nil
}
// AttachVolume maps a ScaleIO volume to the running node. If flag multiMaps,
// ScaleIO will allow other SDC to map to volume.
func (m *sioMgr) AttachVolume(volName string, multipleMappings bool) (string, error) {
client, err := m.getClient()
if err != nil {
klog.Error(log("attach volume failed: %v", err))
return "", err
}
klog.V(4).Infoln(log("attaching volume %s", volName))
iid, err := client.IID()
if err != nil {
klog.Error(log("failed to get instanceID"))
return "", err
}
klog.V(4).Info(log("attaching volume %s to host instance %s", volName, iid))
devs, err := client.Devs()
if err != nil {
return "", err
}
vol, err := client.FindVolume(volName)
if err != nil {
klog.Error(log("failed to find volume %s: %v", volName, err))
return "", err
}
// handle vol if already attached
if len(vol.MappedSdcInfo) > 0 {
if m.isSdcMappedToVol(iid, vol) {
klog.V(4).Info(log("skipping attachment, volume %s already attached to sdc %s", volName, iid))
return devs[vol.ID], nil
}
}
// attach volume, get deviceName
if err := client.AttachVolume(sioVolumeID(vol.ID), multipleMappings); err != nil {
klog.Error(log("attachment for volume %s failed :%v", volName, err))
return "", err
}
device, err := client.WaitForAttachedDevice(vol.ID)
if err != nil {
klog.Error(log("failed while waiting for device to attach: %v", err))
return "", err
}
klog.V(4).Info(log("volume %s attached successfully as %s to instance %s", volName, device, iid))
return device, nil
}
// IsAttached verifies that the named ScaleIO volume is still attached
func (m *sioMgr) IsAttached(volName string) (bool, error) {
client, err := m.getClient()
if err != nil {
return false, err
}
iid, err := client.IID()
if err != nil {
klog.Error("scaleio: failed to get instanceID")
return false, err
}
vol, err := client.FindVolume(volName)
if err != nil {
return false, err
}
return m.isSdcMappedToVol(iid, vol), nil
}
// DetachVolume detaches the name ScaleIO volume from an instance
func (m *sioMgr) DetachVolume(volName string) error {
client, err := m.getClient()
if err != nil {
return err
}
iid, err := client.IID()
if err != nil {
klog.Error(log("failed to get instanceID: %v", err))
return err
}
vol, err := client.FindVolume(volName)
if err != nil {
return err
}
if !m.isSdcMappedToVol(iid, vol) {
klog.Warning(log(
"skipping detached, vol %s not attached to instance %s",
volName, iid,
))
return nil
}
if err := client.DetachVolume(sioVolumeID(vol.ID)); err != nil {
klog.Error(log("failed to detach vol %s: %v", volName, err))
return err
}
klog.V(4).Info(log("volume %s detached successfully", volName))
return nil
}
// DeleteVolumes removes the ScaleIO volume
func (m *sioMgr) DeleteVolume(volName string) error {
client, err := m.getClient()
if err != nil {
return err
}
vol, err := client.FindVolume(volName)
if err != nil {
return err
}
if err := client.DeleteVolume(sioVolumeID(vol.ID)); err != nil {
klog.Error(log("failed to delete volume %s: %v", volName, err))
return err
}
klog.V(4).Info(log("deleted volume %s successfully", volName))
return nil
}
// isSdcMappedToVol returns true if the sdc is mapped to the volume
func (m *sioMgr) isSdcMappedToVol(sdcID string, vol *siotypes.Volume) bool {
if len(vol.MappedSdcInfo) == 0 {
klog.V(4).Info(log("no attachment found"))
return false
}
for _, sdcInfo := range vol.MappedSdcInfo {
if sdcInfo.SdcID == sdcID {
return true
}
}
return false
}

View File

@ -1,339 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"errors"
"testing"
"time"
siotypes "github.com/thecodeteam/goscaleio/types/v1"
volumetesting "k8s.io/kubernetes/pkg/volume/testing"
"k8s.io/utils/exec/testing"
)
var (
fakeSdcID = "test-sdc-123456789"
fakeVolumeID = "1234567890"
fakeDev = "/dev/testABC"
fakeConfig = map[string]string{
confKey.gateway: "http://sio.gateway:1234",
confKey.sslEnabled: "false",
confKey.system: "scaleio",
confKey.volumeName: "sio-0001",
confKey.secretName: "sio-secret",
confKey.username: "c2lvdXNlcgo=", // siouser
confKey.password: "c2lvcGFzc3dvcmQK", // siopassword
}
)
func newTestMgr(t *testing.T) *sioMgr {
host := volumetesting.NewFakeVolumeHost(t, "/tmp/fake", nil, nil)
mgr, err := newSioMgr(fakeConfig, host, &testingexec.FakeExec{})
if err != nil {
t.Error(err)
}
mgr.client = newFakeSio()
return mgr
}
func TestMgrNew(t *testing.T) {
host := volumetesting.NewFakeVolumeHost(t, "/tmp/fake", nil, nil)
mgr, err := newSioMgr(fakeConfig, host, &testingexec.FakeExec{})
if err != nil {
t.Fatal(err)
}
if mgr.configData == nil {
t.Fatal("configuration data not set")
}
if mgr.configData[confKey.volumeName] != "sio-0001" {
t.Errorf("expecting %s, got %s", "sio-0001", mgr.configData[confKey.volumeName])
}
// check defaults
if mgr.configData[confKey.protectionDomain] != "default" {
t.Errorf("unexpected value for confData[protectionDomain] %s", mgr.configData[confKey.protectionDomain])
}
if mgr.configData[confKey.storagePool] != "default" {
t.Errorf("unexpected value for confData[storagePool] %s", mgr.configData[confKey.storagePool])
}
if mgr.configData[confKey.storageMode] != "ThinProvisioned" {
t.Errorf("unexpected value for confData[storageMode] %s", mgr.configData[confKey.storageMode])
}
}
func TestMgrGetClient(t *testing.T) {
mgr := newTestMgr(t)
_, err := mgr.getClient()
if err != nil {
t.Fatal(err)
}
if mgr.client == nil {
t.Fatal("mgr.client not set")
}
}
func TestMgrCreateVolume(t *testing.T) {
mgr := newTestMgr(t)
vol, err := mgr.CreateVolume("test-vol-0001", 8*1024*1024)
if err != nil {
t.Fatal(err)
}
if vol.Name != "test-vol-0001" {
t.Errorf("unexpected vol.Name %s", vol.Name)
}
}
func TestMgrAttachVolume(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
device, err := mgr.AttachVolume("test-vol-0001", false)
if err != nil {
t.Fatal(err)
}
if device != "/dev/testABC" {
t.Errorf("unexpected value for mapped device %s", device)
}
}
func TestMgrAttachVolume_AlreadyAttached(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
mgr.AttachVolume("test-vol-0001", false)
dev, err := mgr.AttachVolume("test-vol-0001", false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if dev != "/dev/testABC" {
t.Errorf("unexpected value for mapped device %s", dev)
}
}
func TestMgrAttachVolume_VolumeNotFoundError(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
_, err := mgr.AttachVolume("test-vol-0002", false)
if err == nil {
t.Error("attachVolume should fail with volume not found error")
}
}
func TestMgrAttachVolume_WaitForAttachError(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
go func() {
c := mgr.client.(*fakeSio)
close(c.waitAttachCtrl)
}()
_, err := mgr.AttachVolume("test-vol-0001", false)
if err == nil {
t.Error("attachVolume should fail with attach timeout error")
}
}
func TestMgrDetachVolume(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
mgr.AttachVolume("test-vol-0001", false)
if err := mgr.DetachVolume("test-vol-0001"); err != nil {
t.Fatal(err)
}
fakeSio := mgr.client.(*fakeSio)
if len(fakeSio.volume.MappedSdcInfo) != 0 {
t.Errorf("expecting attached sdc to 0, got %d", len(fakeSio.volume.MappedSdcInfo))
}
if len(fakeSio.devs) != 0 {
t.Errorf("expecting local devs to be 0, got %d", len(fakeSio.devs))
}
}
func TestMgrDetachVolume_VolumeNotFound(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
mgr.AttachVolume("test-vol-0001", false)
err := mgr.DetachVolume("test-vol-0002")
if err == nil {
t.Fatal("expected a volume not found failure")
}
}
func TestMgrDetachVolume_VolumeNotAttached(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
err := mgr.DetachVolume("test-vol-0001")
if err != nil {
t.Fatal(err)
}
}
func TestMgrDetachVolume_VolumeAlreadyDetached(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
mgr.AttachVolume("test-vol-0001", false)
mgr.DetachVolume("test-vol-0001")
err := mgr.DetachVolume("test-vol-0001")
if err != nil {
t.Fatal("failed detaching a volume already detached")
}
}
func TestMgrDetachVolume_WaitForDetachError(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
mgr.AttachVolume("test-vol-0001", false)
err := mgr.DetachVolume("test-vol-0001")
if err != nil {
t.Error("detachVolume failed")
}
}
func TestMgrDeleteVolume(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
err := mgr.DeleteVolume("test-vol-0001")
if err != nil {
t.Fatal(err)
}
sio := mgr.client.(*fakeSio)
if sio.volume != nil {
t.Errorf("volume not nil after delete operation")
}
}
func TestMgrDeleteVolume_VolumeNotFound(t *testing.T) {
mgr := newTestMgr(t)
mgr.CreateVolume("test-vol-0001", 8*1024*1024)
err := mgr.DeleteVolume("test-vol-0002")
if err == nil {
t.Fatal("expected volume not found error")
}
}
// ************************************************************
// Helper Test Types
// ************************************************************
type fakeSio struct {
volume *siotypes.Volume
waitAttachCtrl chan struct{}
waitDetachCtrl chan struct{}
devs map[string]string
isMultiMap bool
}
func newFakeSio() *fakeSio {
return &fakeSio{
waitAttachCtrl: make(chan struct{}),
waitDetachCtrl: make(chan struct{}),
}
}
func (f *fakeSio) FindVolume(volumeName string) (*siotypes.Volume, error) {
if f.volume == nil || f.volume.Name != volumeName {
return nil, errors.New("volume not found")
}
return f.volume, nil
}
func (f *fakeSio) Volume(id sioVolumeID) (*siotypes.Volume, error) {
if f.volume == nil || f.volume.ID != string(id) {
return nil, errors.New("volume not found")
}
return f.volume, nil
}
func (f *fakeSio) CreateVolume(volName string, sizeGB int64) (*siotypes.Volume, error) {
f.volume = &siotypes.Volume{
ID: fakeVolumeID,
Name: volName,
SizeInKb: int(sizeGB),
VolumeType: "test",
}
return f.volume, nil
}
func (f *fakeSio) AttachVolume(id sioVolumeID, multiMaps bool) error {
f.isMultiMap = multiMaps
_, err := f.Volume(id)
if err != nil {
return err
}
f.volume.MappedSdcInfo = []*siotypes.MappedSdcInfo{
{SdcID: fakeSdcID},
}
return nil
}
func (f *fakeSio) DetachVolume(id sioVolumeID) error {
if _, err := f.Volume(id); err != nil {
return err
}
f.volume.MappedSdcInfo = nil
delete(f.devs, f.volume.ID)
return nil
}
func (f *fakeSio) DeleteVolume(id sioVolumeID) error {
if _, err := f.Volume(id); err != nil {
return err
}
f.volume = nil
return nil
}
func (f *fakeSio) IID() (string, error) {
return fakeSdcID, nil
}
func (f *fakeSio) Devs() (map[string]string, error) {
if f.volume == nil {
return nil, errors.New("volume not found")
}
f.devs = map[string]string{
f.volume.ID: fakeDev,
}
return f.devs, nil
}
func (f *fakeSio) GetVolumeRefs(volID sioVolumeID) (int, error) {
if f.volume == nil {
return 0, nil
}
return 1, nil
}
func (f *fakeSio) WaitForAttachedDevice(token string) (string, error) {
select {
case <-time.After(500 * time.Millisecond):
return fakeDev, nil
case <-f.waitAttachCtrl:
return "", errors.New("attached device timeout")
}
}
func (f *fakeSio) WaitForDetachedDevice(token string) error {
select {
case <-time.After(500 * time.Millisecond):
delete(f.devs, f.volume.ID)
return nil
case <-f.waitDetachCtrl:
return errors.New("detach device timeout")
}
}

View File

@ -1,220 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"errors"
api "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/utils/keymutex"
)
const (
sioPluginName = "kubernetes.io/scaleio"
sioConfigFileName = "sioconf.dat"
)
type sioPlugin struct {
host volume.VolumeHost
volumeMtx keymutex.KeyMutex
}
// ProbeVolumePlugins is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.VolumePlugin {
p := &sioPlugin{
host: nil,
}
return []volume.VolumePlugin{p}
}
// *******************
// VolumePlugin Impl
// *******************
var _ volume.VolumePlugin = &sioPlugin{}
func (p *sioPlugin) Init(host volume.VolumeHost) error {
p.host = host
p.volumeMtx = keymutex.NewHashed(0)
return nil
}
func (p *sioPlugin) GetPluginName() string {
return sioPluginName
}
func (p *sioPlugin) GetVolumeName(spec *volume.Spec) (string, error) {
attribs, err := getVolumeSourceAttribs(spec)
if err != nil {
return "", err
}
return attribs.volName, nil
}
func (p *sioPlugin) CanSupport(spec *volume.Spec) bool {
return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.ScaleIO != nil) ||
(spec.Volume != nil && spec.Volume.ScaleIO != nil)
}
func (p *sioPlugin) RequiresRemount(spec *volume.Spec) bool {
return false
}
func (p *sioPlugin) NewMounter(
spec *volume.Spec,
pod *api.Pod,
_ volume.VolumeOptions) (volume.Mounter, error) {
// extract source info from either ScaleIOVolumeSource or ScaleIOPersistentVolumeSource type
attribs, err := getVolumeSourceAttribs(spec)
if err != nil {
return nil, errors.New(log("mounter failed to extract volume attributes from spec: %v", err))
}
secretName, secretNS, err := getSecretAndNamespaceFromSpec(spec, pod)
if err != nil {
return nil, errors.New(log("failed to get secret name or secretNamespace: %v", err))
}
return &sioVolume{
pod: pod,
spec: spec,
secretName: secretName,
secretNamespace: secretNS,
volSpecName: spec.Name(),
volName: attribs.volName,
podUID: pod.UID,
readOnly: attribs.readOnly,
fsType: attribs.fsType,
plugin: p,
}, nil
}
// NewUnmounter creates a representation of the volume to unmount
func (p *sioPlugin) NewUnmounter(specName string, podUID types.UID) (volume.Unmounter, error) {
klog.V(4).Info(log("Unmounter for %s", specName))
return &sioVolume{
podUID: podUID,
volSpecName: specName,
plugin: p,
}, nil
}
func (p *sioPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
sioVol := &api.Volume{
Name: volumeName,
VolumeSource: api.VolumeSource{
ScaleIO: &api.ScaleIOVolumeSource{},
},
}
return volume.NewSpecFromVolume(sioVol), nil
}
// SupportsMountOption returns true if volume plugins supports Mount options
// Specifying mount options in a volume plugin that doesn't support
// user specified mount options will result in error creating persistent volumes
func (p *sioPlugin) SupportsMountOption() bool {
return false
}
// SupportsBulkVolumeVerification checks if volume plugin type is capable
// of enabling bulk polling of all nodes. This can speed up verification of
// attached volumes by quite a bit, but underlying pluging must support it.
func (p *sioPlugin) SupportsBulkVolumeVerification() bool {
return false
}
//******************************
// PersistentVolumePlugin Impl
// *****************************
var _ volume.PersistentVolumePlugin = &sioPlugin{}
func (p *sioPlugin) GetAccessModes() []api.PersistentVolumeAccessMode {
return []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
}
}
// ***************************
// DeletableVolumePlugin Impl
//****************************
var _ volume.DeletableVolumePlugin = &sioPlugin{}
func (p *sioPlugin) NewDeleter(spec *volume.Spec) (volume.Deleter, error) {
attribs, err := getVolumeSourceAttribs(spec)
if err != nil {
klog.Error(log("deleter failed to extract volume attributes from spec: %v", err))
return nil, err
}
secretName, secretNS, err := getSecretAndNamespaceFromSpec(spec, nil)
if err != nil {
return nil, errors.New(log("failed to get secret name or secretNamespace: %v", err))
}
return &sioVolume{
spec: spec,
secretName: secretName,
secretNamespace: secretNS,
volSpecName: spec.Name(),
volName: attribs.volName,
plugin: p,
readOnly: attribs.readOnly,
}, nil
}
// *********************************
// ProvisionableVolumePlugin Impl
// *********************************
var _ volume.ProvisionableVolumePlugin = &sioPlugin{}
func (p *sioPlugin) NewProvisioner(options volume.VolumeOptions) (volume.Provisioner, error) {
klog.V(4).Info(log("creating Provisioner"))
configData := options.Parameters
if configData == nil {
klog.Error(log("provisioner missing parameters, unable to continue"))
return nil, errors.New("option parameters missing")
}
// Supports ref of name of secret a couple of ways:
// options.Parameters["secretRef"] for backward compat, or
// options.Parameters["secretName"]
secretName := configData[confKey.secretName]
if secretName == "" {
secretName = configData["secretName"]
configData[confKey.secretName] = secretName
}
secretNS := configData[confKey.secretNamespace]
if secretNS == "" {
secretNS = options.PVC.Namespace
}
return &sioVolume{
configData: configData,
plugin: p,
options: options,
secretName: secretName,
secretNamespace: secretNS,
volSpecName: options.PVName,
}, nil
}

View File

@ -1,336 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"encoding/gob"
"errors"
"fmt"
"os"
"path"
"strconv"
"k8s.io/klog/v2"
api "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/volume"
volutil "k8s.io/kubernetes/pkg/volume/util"
)
type volSourceAttribs struct {
volName,
fsType string
readOnly bool
}
var (
confKey = struct {
gateway,
sslEnabled,
secretName,
system,
protectionDomain,
storagePool,
storageMode,
sdcRootPath,
volumeName,
volSpecName,
fsType,
readOnly,
username,
password,
secretNamespace,
sdcGUID string
}{
gateway: "gateway",
sslEnabled: "sslEnabled",
secretName: "secretRef",
secretNamespace: "secretNamespace",
system: "system",
protectionDomain: "protectionDomain",
storagePool: "storagePool",
storageMode: "storageMode",
sdcRootPath: "sdcRootPath",
volumeName: "volumeName",
volSpecName: "volSpecName",
fsType: "fsType",
readOnly: "readOnly",
username: "username",
password: "password",
sdcGUID: "sdcGUID",
}
sdcGUIDLabelName = "scaleio.sdcGUID"
sdcRootPath = "/opt/emc/scaleio/sdc/bin"
errSecretNotFound = errors.New("secret not found")
errGatewayNotProvided = errors.New("ScaleIO gateway not provided")
errSecretRefNotProvided = errors.New("secret ref not provided")
errSystemNotProvided = errors.New("ScaleIO system not provided")
errStoragePoolNotProvided = errors.New("ScaleIO storage pool not provided")
errProtectionDomainNotProvided = errors.New("ScaleIO protection domain not provided")
)
// mapVolumeSpec maps attributes from either ScaleIOVolumeSource or ScaleIOPersistentVolumeSource to config
func mapVolumeSpec(config map[string]string, spec *volume.Spec) {
if source, err := getScaleIOPersistentVolumeSourceFromSpec(spec); err == nil {
config[confKey.gateway] = source.Gateway
config[confKey.system] = source.System
config[confKey.volumeName] = source.VolumeName
config[confKey.sslEnabled] = strconv.FormatBool(source.SSLEnabled)
config[confKey.protectionDomain] = source.ProtectionDomain
config[confKey.storagePool] = source.StoragePool
config[confKey.storageMode] = source.StorageMode
config[confKey.fsType] = source.FSType
config[confKey.readOnly] = strconv.FormatBool(source.ReadOnly)
}
if source, err := getScaleIOVolumeSourceFromSpec(spec); err == nil {
config[confKey.gateway] = source.Gateway
config[confKey.system] = source.System
config[confKey.volumeName] = source.VolumeName
config[confKey.sslEnabled] = strconv.FormatBool(source.SSLEnabled)
config[confKey.protectionDomain] = source.ProtectionDomain
config[confKey.storagePool] = source.StoragePool
config[confKey.storageMode] = source.StorageMode
config[confKey.fsType] = source.FSType
config[confKey.readOnly] = strconv.FormatBool(source.ReadOnly)
}
//optionals
applyConfigDefaults(config)
}
func validateConfigs(config map[string]string) error {
if config[confKey.gateway] == "" {
return errGatewayNotProvided
}
if config[confKey.secretName] == "" {
return errSecretRefNotProvided
}
if config[confKey.system] == "" {
return errSystemNotProvided
}
if config[confKey.storagePool] == "" {
return errStoragePoolNotProvided
}
if config[confKey.protectionDomain] == "" {
return errProtectionDomainNotProvided
}
return nil
}
// applyConfigDefaults apply known defaults to incoming spec for dynamic PVCs.
func applyConfigDefaults(config map[string]string) {
b, err := strconv.ParseBool(config[confKey.sslEnabled])
if err != nil {
klog.Warning(log("failed to parse param sslEnabled, setting it to false"))
b = false
}
config[confKey.sslEnabled] = strconv.FormatBool(b)
config[confKey.storageMode] = defaultString(config[confKey.storageMode], "ThinProvisioned")
config[confKey.fsType] = defaultString(config[confKey.fsType], "xfs")
b, err = strconv.ParseBool(config[confKey.readOnly])
if err != nil {
klog.Warning(log("failed to parse param readOnly, setting it to false"))
b = false
}
config[confKey.readOnly] = strconv.FormatBool(b)
}
func defaultString(val, defVal string) string {
if val == "" {
return defVal
}
return val
}
// loadConfig loads configuration data from a file on disk
func loadConfig(configName string) (map[string]string, error) {
klog.V(4).Info(log("loading config file %s", configName))
file, err := os.Open(configName)
if err != nil {
klog.Error(log("failed to open config file %s: %v", configName, err))
return nil, err
}
defer file.Close()
data := map[string]string{}
if err := gob.NewDecoder(file).Decode(&data); err != nil {
klog.Error(log("failed to parse config data %s: %v", configName, err))
return nil, err
}
applyConfigDefaults(data)
if err := validateConfigs(data); err != nil {
klog.Error(log("failed to load ConfigMap %s: %v", err))
return nil, err
}
return data, nil
}
// saveConfig saves the configuration data to local disk
func saveConfig(configName string, data map[string]string) error {
klog.V(4).Info(log("saving config file %s", configName))
dir := path.Dir(configName)
if _, err := os.Stat(dir); err != nil {
if !os.IsNotExist(err) {
return err
}
klog.V(4).Info(log("creating config dir for config data: %s", dir))
if err := os.MkdirAll(dir, 0750); err != nil {
klog.Error(log("failed to create config data dir %v", err))
return err
}
}
file, err := os.Create(configName)
if err != nil {
klog.V(4).Info(log("failed to save config data file %s: %v", configName, err))
return err
}
defer file.Close()
if err := gob.NewEncoder(file).Encode(data); err != nil {
klog.Error(log("failed to save config %s: %v", configName, err))
return err
}
klog.V(4).Info(log("config data file saved successfully as %s", configName))
return nil
}
// attachSecret loads secret object and attaches to configData
func attachSecret(plug *sioPlugin, namespace string, configData map[string]string) error {
// load secret
secretRefName := configData[confKey.secretName]
kubeClient := plug.host.GetKubeClient()
secretMap, err := volutil.GetSecretForPV(namespace, secretRefName, sioPluginName, kubeClient)
if err != nil {
klog.Error(log("failed to get secret: %v", err))
return errSecretNotFound
}
// merge secret data
for key, val := range secretMap {
configData[key] = val
}
return nil
}
// attachSdcGUID injects the sdc guid node label value into config
func attachSdcGUID(plug *sioPlugin, conf map[string]string) error {
guid, err := getSdcGUIDLabel(plug)
if err != nil {
return err
}
conf[confKey.sdcGUID] = guid
return nil
}
// getSdcGUIDLabel fetches the scaleio.sdcGuid node label
// associated with the node executing this code.
func getSdcGUIDLabel(plug *sioPlugin) (string, error) {
nodeLabels, err := plug.host.GetNodeLabels()
if err != nil {
return "", err
}
label, ok := nodeLabels[sdcGUIDLabelName]
if !ok {
klog.V(4).Info(log("node label %s not found", sdcGUIDLabelName))
return "", nil
}
klog.V(4).Info(log("found node label %s=%s", sdcGUIDLabelName, label))
return label, nil
}
// getVolumeSourceFromSpec safely extracts ScaleIOVolumeSource or ScaleIOPersistentVolumeSource from spec
func getVolumeSourceFromSpec(spec *volume.Spec) (interface{}, error) {
if spec.Volume != nil && spec.Volume.ScaleIO != nil {
return spec.Volume.ScaleIO, nil
}
if spec.PersistentVolume != nil &&
spec.PersistentVolume.Spec.ScaleIO != nil {
return spec.PersistentVolume.Spec.ScaleIO, nil
}
return nil, fmt.Errorf("ScaleIO not defined in spec")
}
func getVolumeSourceAttribs(spec *volume.Spec) (*volSourceAttribs, error) {
attribs := new(volSourceAttribs)
if pvSource, err := getScaleIOPersistentVolumeSourceFromSpec(spec); err == nil {
attribs.volName = pvSource.VolumeName
attribs.fsType = pvSource.FSType
attribs.readOnly = pvSource.ReadOnly
} else if pSource, err := getScaleIOVolumeSourceFromSpec(spec); err == nil {
attribs.volName = pSource.VolumeName
attribs.fsType = pSource.FSType
attribs.readOnly = pSource.ReadOnly
} else {
msg := log("failed to get ScaleIOVolumeSource or ScaleIOPersistentVolumeSource from spec")
klog.Error(msg)
return nil, errors.New(msg)
}
return attribs, nil
}
func getScaleIOPersistentVolumeSourceFromSpec(spec *volume.Spec) (*api.ScaleIOPersistentVolumeSource, error) {
source, err := getVolumeSourceFromSpec(spec)
if err != nil {
return nil, err
}
if val, ok := source.(*api.ScaleIOPersistentVolumeSource); ok {
return val, nil
}
return nil, fmt.Errorf("spec is not a valid ScaleIOPersistentVolume type")
}
func getScaleIOVolumeSourceFromSpec(spec *volume.Spec) (*api.ScaleIOVolumeSource, error) {
source, err := getVolumeSourceFromSpec(spec)
if err != nil {
return nil, err
}
if val, ok := source.(*api.ScaleIOVolumeSource); ok {
return val, nil
}
return nil, fmt.Errorf("spec is not a valid ScaleIOVolume type")
}
func getSecretAndNamespaceFromSpec(spec *volume.Spec, pod *api.Pod) (secretName string, secretNS string, err error) {
if source, err := getScaleIOVolumeSourceFromSpec(spec); err == nil {
secretName = source.SecretRef.Name
if pod != nil {
secretNS = pod.Namespace
}
} else if source, err := getScaleIOPersistentVolumeSourceFromSpec(spec); err == nil {
if source.SecretRef != nil {
secretName = source.SecretRef.Name
secretNS = source.SecretRef.Namespace
if secretNS == "" && pod != nil {
secretNS = pod.Namespace
}
}
} else {
return "", "", errors.New("failed to get ScaleIOVolumeSource or ScaleIOPersistentVolumeSource")
}
return secretName, secretNS, nil
}
func log(msg string, parts ...interface{}) string {
return fmt.Sprintf(fmt.Sprintf("scaleio: %s", msg), parts...)
}

View File

@ -1,224 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"encoding/gob"
"os"
"path/filepath"
"reflect"
"testing"
api "k8s.io/api/core/v1"
utiltesting "k8s.io/client-go/util/testing"
"k8s.io/kubernetes/pkg/volume"
)
var (
vol = &api.Volume{
Name: testSioVolName,
VolumeSource: api.VolumeSource{
ScaleIO: &api.ScaleIOVolumeSource{
Gateway: "http://test.scaleio:1111",
System: "sio",
ProtectionDomain: "defaultPD",
StoragePool: "defaultSP",
VolumeName: "test-vol",
FSType: "ext4",
SecretRef: &api.LocalObjectReference{Name: "test-secret"},
},
},
}
config = map[string]string{
confKey.system: "sio",
confKey.gateway: "http://sio/",
confKey.volSpecName: testSioVolName,
confKey.volumeName: "sio-vol",
confKey.secretName: "sio-secret",
confKey.protectionDomain: "defaultPD",
confKey.storagePool: "deraultSP",
confKey.fsType: "xfs",
confKey.readOnly: "true",
}
testConfigFile = "conf.dat"
)
func TestUtilMapVolumeSource(t *testing.T) {
data := make(map[string]string)
mapVolumeSpec(data, volume.NewSpecFromVolume(vol))
if data[confKey.gateway] != "http://test.scaleio:1111" {
t.Error("Unexpected gateway value")
}
if data[confKey.system] != "sio" {
t.Error("Unexpected system value")
}
if data[confKey.protectionDomain] != "defaultPD" {
t.Error("Unexpected protection domain value")
}
if data[confKey.storagePool] != "defaultSP" {
t.Error("Unexpected storage pool value")
}
if data[confKey.volumeName] != "test-vol" {
t.Error("Unexpected volume name value")
}
if data[confKey.fsType] != "ext4" {
t.Error("Unexpected fstype value")
}
if data[confKey.sslEnabled] != "false" {
t.Error("Unexpected sslEnabled value")
}
if data[confKey.readOnly] != "false" {
t.Error("Unexpected readOnly value: ", data[confKey.readOnly])
}
}
func TestUtilValidateConfigs(t *testing.T) {
data := map[string]string{
confKey.secretName: "sio-secret",
confKey.system: "sio",
}
if err := validateConfigs(data); err != errGatewayNotProvided {
t.Error("Expecting error for missing gateway, but did not get it")
}
}
func TestUtilApplyConfigDefaults(t *testing.T) {
data := map[string]string{
confKey.system: "sio",
confKey.gateway: "http://sio/",
confKey.volumeName: "sio-vol",
confKey.secretName: "test-secret",
}
applyConfigDefaults(data)
if data[confKey.gateway] != "http://sio/" {
t.Error("Unexpected gateway value")
}
if data[confKey.system] != "sio" {
t.Error("Unexpected system value")
}
if data[confKey.protectionDomain] != "" {
t.Error("Unexpected protection domain value")
}
if data[confKey.storagePool] != "" {
t.Error("Unexpected storage pool value")
}
if data[confKey.volumeName] != "sio-vol" {
t.Error("Unexpected volume name value")
}
if data[confKey.fsType] != "xfs" {
t.Error("Unexpected fstype value")
}
if data[confKey.storageMode] != "ThinProvisioned" {
t.Error("Unexpected storage mode value")
}
if data[confKey.secretName] != "test-secret" {
t.Error("Unexpected secret ref value")
}
if data[confKey.sslEnabled] != "false" {
t.Error("Unexpected sslEnabled value")
}
if data[confKey.readOnly] != "false" {
t.Error("Unexpected readOnly value: ", data[confKey.readOnly])
}
}
func TestUtilDefaultString(t *testing.T) {
if defaultString("", "foo") != "foo" {
t.Error("Unexpected value for default value")
}
}
func TestUtilSaveConfig(t *testing.T) {
tmpDir, err := utiltesting.MkTmpdir("scaleio-test")
if err != nil {
t.Fatalf("can't make a temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
config := filepath.Join(tmpDir, testConfigFile)
data := map[string]string{
confKey.gateway: "https://test-gateway/",
confKey.secretName: "sio-secret",
confKey.sslEnabled: "false",
}
if err := saveConfig(config, data); err != nil {
t.Fatalf("failed while saving data: %v", err)
}
file, err := os.Open(config)
if err != nil {
t.Fatalf("failed to open conf file %s: %v", config, err)
}
defer file.Close()
dataRcvd := map[string]string{}
if err := gob.NewDecoder(file).Decode(&dataRcvd); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(data, dataRcvd) {
t.Error("we got problem, config data not the same")
}
}
func TestUtilAttachSecret(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Errorf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Errorf("Cannot assert plugin to be type sioPlugin")
}
data := make(map[string]string)
for k, v := range config {
data[k] = v
}
if err := attachSecret(sioPlug, "default", data); err != nil {
t.Errorf("failed to setupConfigData %v", err)
}
if data[confKey.username] == "" {
t.Errorf("failed to merge secret")
}
}
func TestUtilLoadConfig(t *testing.T) {
tmpDir, err := utiltesting.MkTmpdir("scaleio-test")
if err != nil {
t.Fatalf("can't make a temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
configFile := filepath.Join(tmpDir, sioConfigFileName)
if err := saveConfig(configFile, config); err != nil {
t.Fatalf("failed to save configFile %s error:%v", configFile, err)
}
dataRcvd, err := loadConfig(configFile)
if err != nil {
t.Fatalf("failed to load configFile %s error:%v", configFile, err)
}
if dataRcvd[confKey.gateway] != config[confKey.gateway] ||
dataRcvd[confKey.system] != config[confKey.system] {
t.Fatal("loaded config data not matching saved config data")
}
}

View File

@ -1,530 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"k8s.io/klog/v2"
"k8s.io/mount-utils"
utilstrings "k8s.io/utils/strings"
api "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/uuid"
volumehelpers "k8s.io/cloud-provider/volume/helpers"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
)
type sioVolume struct {
sioMgr *sioMgr
plugin *sioPlugin
pod *api.Pod
podUID types.UID
spec *volume.Spec
secretName string
secretNamespace string
volSpecName string
volName string
readOnly bool
fsType string
options volume.VolumeOptions
configData map[string]string
volume.MetricsNil
}
const (
minimumVolumeSizeGiB = 8
)
// *******************
// volume.Volume Impl
var _ volume.Volume = &sioVolume{}
// GetPath returns the path where the volume will be mounted.
func (v *sioVolume) GetPath() string {
return v.plugin.host.GetPodVolumeDir(
v.podUID,
utilstrings.EscapeQualifiedName(sioPluginName),
v.volSpecName)
}
// *************
// Mounter Impl
// *************
var _ volume.Mounter = &sioVolume{}
// CanMount checks to verify that the volume can be mounted prior to Setup.
// A nil error indicates that the volume is ready for mounitnig.
func (v *sioVolume) CanMount() error {
return nil
}
func (v *sioVolume) SetUp(mounterArgs volume.MounterArgs) error {
return v.SetUpAt(v.GetPath(), mounterArgs)
}
// SetUp bind mounts the disk global mount to the volume path.
func (v *sioVolume) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
v.plugin.volumeMtx.LockKey(v.volSpecName)
defer v.plugin.volumeMtx.UnlockKey(v.volSpecName)
klog.V(4).Info(log("setting up volume for PV.spec %s", v.volSpecName))
if err := v.setSioMgr(); err != nil {
klog.Error(log("setup failed to create scalio manager: %v", err))
return err
}
mounter := v.plugin.host.GetMounter(v.plugin.GetPluginName())
notDevMnt, err := mounter.IsLikelyNotMountPoint(dir)
if err != nil && !os.IsNotExist(err) {
klog.Error(log("IsLikelyNotMountPoint test failed for dir %v", dir))
return err
}
if !notDevMnt {
klog.V(4).Info(log("skipping setup, dir %s already a mount point", v.volName))
return nil
}
// should multiple-mapping be enabled
enableMultiMaps := false
isROM := false
if v.spec.PersistentVolume != nil {
ams := v.spec.PersistentVolume.Spec.AccessModes
for _, am := range ams {
if am == api.ReadOnlyMany {
enableMultiMaps = true
isROM = true
}
}
}
klog.V(4).Info(log("multiple mapping enabled = %v", enableMultiMaps))
volName := v.volName
devicePath, err := v.sioMgr.AttachVolume(volName, enableMultiMaps)
if err != nil {
klog.Error(log("setup of volume %v: %v", v.volSpecName, err))
return err
}
options := []string{}
switch {
default:
options = append(options, "rw")
case isROM && !v.readOnly:
options = append(options, "rw")
case isROM:
options = append(options, "ro")
case v.readOnly:
options = append(options, "ro")
}
klog.V(4).Info(log("mounting device %s -> %s", devicePath, dir))
if err := os.MkdirAll(dir, 0750); err != nil {
klog.Error(log("failed to create dir %#v: %v", dir, err))
return err
}
klog.V(4).Info(log("setup created mount point directory %s", dir))
diskMounter := util.NewSafeFormatAndMountFromHost(v.plugin.GetPluginName(), v.plugin.host)
err = diskMounter.FormatAndMount(devicePath, dir, v.fsType, options)
if err != nil {
klog.Error(log("mount operation failed during setup: %v", err))
if err := os.Remove(dir); err != nil && !os.IsNotExist(err) {
klog.Error(log("failed to remove dir %s during a failed mount at setup: %v", dir, err))
return err
}
return err
}
if !v.readOnly && mounterArgs.FsGroup != nil {
klog.V(4).Info(log("applying value FSGroup ownership"))
volume.SetVolumeOwnership(v, mounterArgs.FsGroup, mounterArgs.FSGroupChangePolicy, util.FSGroupCompleteHook(v.plugin, v.spec))
}
klog.V(4).Info(log("successfully setup PV %s: volume %s mapped as %s mounted at %s", v.volSpecName, v.volName, devicePath, dir))
return nil
}
func (v *sioVolume) GetAttributes() volume.Attributes {
return volume.Attributes{
ReadOnly: v.readOnly,
Managed: !v.readOnly,
SupportsSELinux: true,
}
}
// **********************
// volume.Unmounter Impl
// *********************
var _ volume.Unmounter = &sioVolume{}
// TearDownAt unmounts the bind mount
func (v *sioVolume) TearDown() error {
return v.TearDownAt(v.GetPath())
}
// TearDown unmounts and remove the volume
func (v *sioVolume) TearDownAt(dir string) error {
v.plugin.volumeMtx.LockKey(v.volSpecName)
defer v.plugin.volumeMtx.UnlockKey(v.volSpecName)
mounter := v.plugin.host.GetMounter(v.plugin.GetPluginName())
dev, _, err := mount.GetDeviceNameFromMount(mounter, dir)
if err != nil {
klog.Errorf(log("failed to get reference count for volume: %s", dir))
return err
}
klog.V(4).Info(log("attempting to unmount %s", dir))
if err := mount.CleanupMountPoint(dir, mounter, false); err != nil {
klog.Error(log("teardown failed while unmounting dir %s: %v ", dir, err))
return err
}
klog.V(4).Info(log("dir %s unmounted successfully", dir))
// detach/unmap
kvh, ok := v.plugin.host.(volume.KubeletVolumeHost)
if !ok {
return fmt.Errorf("plugin volume host does not implement KubeletVolumeHost interface")
}
hu := kvh.GetHostUtil()
deviceBusy, err := hu.DeviceOpened(dev)
if err != nil {
klog.Error(log("teardown unable to get status for device %s: %v", dev, err))
return err
}
// Detach volume from node:
// use "last attempt wins" strategy to detach volume from node
// only allow volume to detach when it is not busy (not being used by other pods)
if !deviceBusy {
klog.V(4).Info(log("teardown is attempting to detach/unmap volume for PV %s", v.volSpecName))
if err := v.resetSioMgr(); err != nil {
klog.Error(log("teardown failed, unable to reset scalio mgr: %v", err))
}
volName := v.volName
if err := v.sioMgr.DetachVolume(volName); err != nil {
klog.Warning(log("warning: detaching failed for volume %s: %v", volName, err))
return nil
}
klog.V(4).Infof(log("teardown of volume %v detached successfully", volName))
}
return nil
}
// ********************
// volume.Deleter Impl
// ********************
var _ volume.Deleter = &sioVolume{}
func (v *sioVolume) Delete() error {
klog.V(4).Info(log("deleting pvc %s", v.volSpecName))
if err := v.setSioMgrFromSpec(); err != nil {
klog.Error(log("delete failed while setting sio manager: %v", err))
return err
}
err := v.sioMgr.DeleteVolume(v.volName)
if err != nil {
klog.Error(log("failed to delete volume %s: %v", v.volName, err))
return err
}
klog.V(4).Info(log("successfully deleted PV %s with volume %s", v.volSpecName, v.volName))
return nil
}
// ************************
// volume.Provisioner Impl
// ************************
var _ volume.Provisioner = &sioVolume{}
func (v *sioVolume) Provision(selectedNode *api.Node, allowedTopologies []api.TopologySelectorTerm) (*api.PersistentVolume, error) {
klog.V(4).Info(log("attempting to dynamically provision pvc %v", v.options.PVC.Name))
if !util.AccessModesContainedInAll(v.plugin.GetAccessModes(), v.options.PVC.Spec.AccessModes) {
return nil, fmt.Errorf("invalid AccessModes %v: only AccessModes %v are supported", v.options.PVC.Spec.AccessModes, v.plugin.GetAccessModes())
}
if util.CheckPersistentVolumeClaimModeBlock(v.options.PVC) {
return nil, fmt.Errorf("%s does not support block volume provisioning", v.plugin.GetPluginName())
}
// setup volume attrributes
genName := v.generateName("k8svol", 11)
capacity := v.options.PVC.Spec.Resources.Requests[api.ResourceName(api.ResourceStorage)]
volSizeGiB, err := volumehelpers.RoundUpToGiB(capacity)
if err != nil {
return nil, err
}
if volSizeGiB < minimumVolumeSizeGiB {
volSizeGiB = minimumVolumeSizeGiB
klog.V(4).Info(log("capacity less than 8Gi found, adjusted to %dGi", volSizeGiB))
}
// create sio manager
if err := v.setSioMgrFromConfig(); err != nil {
klog.Error(log("provision failed while setting up sio mgr: %v", err))
return nil, err
}
// create volume
volName := genName
vol, err := v.sioMgr.CreateVolume(volName, volSizeGiB)
if err != nil {
klog.Error(log("provision failed while creating volume: %v", err))
return nil, err
}
// prepare data for pv
v.configData[confKey.volumeName] = volName
sslEnabled, err := strconv.ParseBool(v.configData[confKey.sslEnabled])
if err != nil {
klog.Warning(log("failed to parse parameter sslEnabled, setting to false"))
sslEnabled = false
}
readOnly, err := strconv.ParseBool(v.configData[confKey.readOnly])
if err != nil {
klog.Warning(log("failed to parse parameter readOnly, setting it to false"))
readOnly = false
}
// describe created pv
pvName := genName
pv := &api.PersistentVolume{
ObjectMeta: meta.ObjectMeta{
Name: pvName,
Namespace: v.options.PVC.Namespace,
Labels: map[string]string{},
Annotations: map[string]string{
util.VolumeDynamicallyCreatedByKey: "scaleio-dynamic-provisioner",
},
},
Spec: api.PersistentVolumeSpec{
PersistentVolumeReclaimPolicy: v.options.PersistentVolumeReclaimPolicy,
AccessModes: v.options.PVC.Spec.AccessModes,
Capacity: api.ResourceList{
api.ResourceName(api.ResourceStorage): resource.MustParse(
fmt.Sprintf("%dGi", volSizeGiB),
),
},
PersistentVolumeSource: api.PersistentVolumeSource{
ScaleIO: &api.ScaleIOPersistentVolumeSource{
Gateway: v.configData[confKey.gateway],
SSLEnabled: sslEnabled,
SecretRef: &api.SecretReference{Name: v.secretName, Namespace: v.secretNamespace},
System: v.configData[confKey.system],
ProtectionDomain: v.configData[confKey.protectionDomain],
StoragePool: v.configData[confKey.storagePool],
StorageMode: v.configData[confKey.storageMode],
VolumeName: volName,
FSType: v.configData[confKey.fsType],
ReadOnly: readOnly,
},
},
},
}
if len(v.options.PVC.Spec.AccessModes) == 0 {
pv.Spec.AccessModes = v.plugin.GetAccessModes()
}
klog.V(4).Info(log("provisioner created pv %v and volume %s successfully", pvName, vol.Name))
return pv, nil
}
// setSioMgr creates scaleio mgr from cached config data if found
// otherwise, setups new config data and create mgr
func (v *sioVolume) setSioMgr() error {
klog.V(4).Info(log("setting up sio mgr for spec %s", v.volSpecName))
podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName)
configName := filepath.Join(podDir, sioConfigFileName)
if v.sioMgr == nil {
configData, err := loadConfig(configName) // try to load config if exist
if err != nil {
if !os.IsNotExist(err) {
klog.Error(log("failed to load config %s : %v", configName, err))
return err
}
klog.V(4).Info(log("previous config file not found, creating new one"))
// prepare config data
configData = make(map[string]string)
mapVolumeSpec(configData, v.spec)
// additional config data
configData[confKey.secretNamespace] = v.secretNamespace
configData[confKey.secretName] = v.secretName
configData[confKey.volSpecName] = v.volSpecName
if err := validateConfigs(configData); err != nil {
klog.Error(log("config setup failed: %s", err))
return err
}
// persist config
if err := saveConfig(configName, configData); err != nil {
klog.Error(log("failed to save config data: %v", err))
return err
}
}
// merge in secret
if err := attachSecret(v.plugin, v.secretNamespace, configData); err != nil {
klog.Error(log("failed to load secret: %v", err))
return err
}
// merge in Sdc Guid label value
if err := attachSdcGUID(v.plugin, configData); err != nil {
klog.Error(log("failed to retrieve sdc guid: %v", err))
return err
}
mgr, err := newSioMgr(configData, v.plugin.host, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
klog.Error(log("failed to reset sio manager: %v", err))
return err
}
v.sioMgr = mgr
}
return nil
}
// resetSioMgr creates scaleio manager from existing (cached) config data
func (v *sioVolume) resetSioMgr() error {
podDir := v.plugin.host.GetPodPluginDir(v.podUID, sioPluginName)
configName := filepath.Join(podDir, sioConfigFileName)
if v.sioMgr == nil {
// load config data from disk
configData, err := loadConfig(configName)
if err != nil {
klog.Error(log("failed to load config data: %v", err))
return err
}
v.secretName = configData[confKey.secretName]
v.secretNamespace = configData[confKey.secretNamespace]
v.volName = configData[confKey.volumeName]
v.volSpecName = configData[confKey.volSpecName]
// attach secret
if err := attachSecret(v.plugin, v.secretNamespace, configData); err != nil {
klog.Error(log("failed to load secret: %v", err))
return err
}
// merge in Sdc Guid label value
if err := attachSdcGUID(v.plugin, configData); err != nil {
klog.Error(log("failed to retrieve sdc guid: %v", err))
return err
}
mgr, err := newSioMgr(configData, v.plugin.host, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
klog.Error(log("failed to reset scaleio mgr: %v", err))
return err
}
v.sioMgr = mgr
}
return nil
}
// setSioFromConfig sets up scaleio mgr from an available config data map
// designed to be called from dynamic provisioner
func (v *sioVolume) setSioMgrFromConfig() error {
klog.V(4).Info(log("setting scaleio mgr from available config"))
if v.sioMgr == nil {
applyConfigDefaults(v.configData)
v.configData[confKey.volSpecName] = v.volSpecName
if err := validateConfigs(v.configData); err != nil {
klog.Error(log("config data setup failed: %s", err))
return err
}
// copy config and attach secret
data := map[string]string{}
for k, v := range v.configData {
data[k] = v
}
if err := attachSecret(v.plugin, v.secretNamespace, data); err != nil {
klog.Error(log("failed to load secret: %v", err))
return err
}
mgr, err := newSioMgr(data, v.plugin.host, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
klog.Error(log("failed while setting scaleio mgr from config: %v", err))
return err
}
v.sioMgr = mgr
}
return nil
}
// setSioMgrFromSpec sets the scaleio manager from a spec object.
// The spec may be complete or incomplete depending on lifecycle phase.
func (v *sioVolume) setSioMgrFromSpec() error {
klog.V(4).Info(log("setting sio manager from spec"))
if v.sioMgr == nil {
// get config data form spec volume source
configData := map[string]string{}
mapVolumeSpec(configData, v.spec)
// additional config
configData[confKey.secretNamespace] = v.secretNamespace
configData[confKey.secretName] = v.secretName
configData[confKey.volSpecName] = v.volSpecName
if err := validateConfigs(configData); err != nil {
klog.Error(log("config setup failed: %s", err))
return err
}
// attach secret object to config data
if err := attachSecret(v.plugin, v.secretNamespace, configData); err != nil {
klog.Error(log("failed to load secret: %v", err))
return err
}
mgr, err := newSioMgr(configData, v.plugin.host, v.plugin.host.GetExec(v.plugin.GetPluginName()))
if err != nil {
klog.Error(log("failed to reset sio manager: %v", err))
return err
}
v.sioMgr = mgr
}
return nil
}
func (v *sioVolume) generateName(prefix string, size int) string {
return fmt.Sprintf("%s-%s", prefix, strings.Replace(string(uuid.NewUUID()), "-", "", -1)[0:size])
}

View File

@ -1,549 +0,0 @@
/*
Copyright 2017 The Kubernetes Authors.
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 scaleio
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
volumehelpers "k8s.io/cloud-provider/volume/helpers"
"k8s.io/klog/v2"
api "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
fakeclient "k8s.io/client-go/kubernetes/fake"
utiltesting "k8s.io/client-go/util/testing"
"k8s.io/kubernetes/pkg/volume"
volumetest "k8s.io/kubernetes/pkg/volume/testing"
)
var (
testSioSystem = "sio"
testSioPD = "default"
testSioVol = "vol-0001"
testns = "default"
testSecret = "sio-secret"
testSioVolName = fmt.Sprintf("%s%s%s", testns, "-", testSioVol)
podUID = types.UID("sio-pod")
)
func newPluginMgr(t *testing.T, apiObject runtime.Object) (*volume.VolumePluginMgr, string) {
tmpDir, err := utiltesting.MkTmpdir("scaleio-test")
if err != nil {
t.Fatalf("can't make a temp dir: %v", err)
}
fakeClient := fakeclient.NewSimpleClientset(apiObject)
host := volumetest.NewFakeKubeletVolumeHostWithNodeLabels(t,
tmpDir,
fakeClient,
ProbeVolumePlugins(),
map[string]string{sdcGUIDLabelName: "abc-123"},
)
plugMgr := host.GetPluginMgr()
return plugMgr, tmpDir
}
func makeScaleIOSecret(name, namespace string) *api.Secret {
return &api.Secret{
ObjectMeta: meta.ObjectMeta{
Name: name,
Namespace: namespace,
UID: "1234567890",
},
Type: api.SecretType("kubernetes.io/scaleio"),
Data: map[string][]byte{
"username": []byte("username"),
"password": []byte("password"),
},
}
}
func TestVolumeCanSupport(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Errorf("Can't find the plugin %s by name", sioPluginName)
}
if plug.GetPluginName() != "kubernetes.io/scaleio" {
t.Errorf("Wrong name: %s", plug.GetPluginName())
}
if !plug.CanSupport(
&volume.Spec{
Volume: &api.Volume{
VolumeSource: api.VolumeSource{
ScaleIO: &api.ScaleIOVolumeSource{},
},
},
},
) {
t.Errorf("Expected true for CanSupport LibStorage VolumeSource")
}
if !plug.CanSupport(
&volume.Spec{
PersistentVolume: &api.PersistentVolume{
Spec: api.PersistentVolumeSpec{
PersistentVolumeSource: api.PersistentVolumeSource{
ScaleIO: &api.ScaleIOPersistentVolumeSource{},
},
},
},
},
) {
t.Errorf("Expected true for CanSupport LibStorage PersistentVolumeSource")
}
}
func TestVolumeGetAccessModes(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPersistentPluginByName(sioPluginName)
if err != nil {
t.Errorf("Can't find the plugin %v", sioPluginName)
}
if !containsMode(plug.GetAccessModes(), api.ReadWriteOnce) {
t.Errorf("Expected two AccessModeTypes: %s or %s", api.ReadWriteOnce, api.ReadOnlyMany)
}
}
func containsMode(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeAccessMode) bool {
for _, m := range modes {
if m == mode {
return true
}
}
return false
}
func TestVolumeMounterUnmounter(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Errorf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Errorf("Cannot assert plugin to be type sioPlugin")
}
vol := &api.Volume{
Name: testSioVolName,
VolumeSource: api.VolumeSource{
ScaleIO: &api.ScaleIOVolumeSource{
Gateway: "http://test.scaleio:1111",
System: testSioSystem,
ProtectionDomain: testSioPD,
StoragePool: "default",
VolumeName: testSioVol,
FSType: "ext4",
SecretRef: &api.LocalObjectReference{Name: testSecret},
ReadOnly: false,
},
},
}
sioMounter, err := sioPlug.NewMounter(
volume.NewSpecFromVolume(vol),
&api.Pod{ObjectMeta: meta.ObjectMeta{UID: podUID, Namespace: testns}},
volume.VolumeOptions{},
)
if err != nil {
t.Fatalf("Failed to make a new Mounter: %v", err)
}
if sioMounter == nil {
t.Fatal("Got a nil Mounter")
}
sio := newFakeSio()
sioVol := sioMounter.(*sioVolume)
if err := sioVol.setSioMgr(); err != nil {
t.Fatalf("failed to create sio mgr: %v", err)
}
sioVol.sioMgr.client = sio
sioVol.sioMgr.CreateVolume(testSioVol, 8) //create vol ahead of time
volPath := filepath.Join(tmpDir, fmt.Sprintf("pods/%s/volumes/kubernetes.io~scaleio/%s", podUID, testSioVolName))
path := sioMounter.GetPath()
if path != volPath {
t.Errorf("Got unexpected path: %s", path)
}
if err := sioMounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Expected success, got: %v", err)
}
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
t.Errorf("SetUp() failed, volume path not created: %s", path)
} else {
t.Errorf("SetUp() failed: %v", err)
}
}
if sio.isMultiMap {
t.Errorf("SetUp() - expecting multiple volume disabled by default")
}
// did we read sdcGUID label
if _, ok := sioVol.sioMgr.configData[confKey.sdcGUID]; !ok {
t.Errorf("Expected to find node label scaleio.sdcGUID, but did not find it")
}
// rebuild spec
builtSpec, err := sioPlug.ConstructVolumeSpec(volume.NewSpecFromVolume(vol).Name(), path)
if err != nil {
t.Errorf("ConstructVolumeSpec failed %v", err)
}
if builtSpec.Name() != vol.Name {
t.Errorf("Unexpected spec name %s", builtSpec.Name())
}
// unmount
sioUnmounter, err := sioPlug.NewUnmounter(volume.NewSpecFromVolume(vol).Name(), podUID)
if err != nil {
t.Fatalf("Failed to make a new Unmounter: %v", err)
}
if sioUnmounter == nil {
t.Fatal("Got a nil Unmounter")
}
sioVol = sioUnmounter.(*sioVolume)
if err := sioVol.resetSioMgr(); err != nil {
t.Fatalf("failed to reset sio mgr: %v", err)
}
sioVol.sioMgr.client = sio
if err := sioUnmounter.TearDown(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
// is mount point gone ?
if _, err := os.Stat(path); err == nil {
t.Errorf("TearDown() failed, volume path still exists: %s", path)
} else if !os.IsNotExist(err) {
t.Errorf("TearDown() failed: %v", err)
}
// are we still mapped
if sio.volume.MappedSdcInfo != nil {
t.Errorf("expected SdcMappedInfo to be nil, volume may still be mapped")
}
}
func TestVolumeProvisioner(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Name = "testpvc"
options.PVC.Namespace = testns
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadOnlyMany,
}
options.Parameters = map[string]string{
confKey.gateway: "http://test.scaleio:11111",
confKey.system: "sio",
confKey.protectionDomain: testSioPD,
confKey.storagePool: "default",
confKey.secretName: testSecret,
}
provisioner, err := sioPlug.NewProvisioner(options)
if err != nil {
t.Fatalf("failed to create new provisioner: %v", err)
}
if provisioner == nil {
t.Fatal("got a nil provisioner")
}
sio := newFakeSio()
sioVol := provisioner.(*sioVolume)
if err := sioVol.setSioMgrFromConfig(); err != nil {
t.Fatalf("failed to create scaleio mgr from config: %v", err)
}
sioVol.sioMgr.client = sio
spec, err := provisioner.Provision(nil, nil)
if err != nil {
t.Fatalf("call to Provision() failed: %v", err)
}
if spec.Namespace != testns {
t.Fatalf("unexpected namespace %v", spec.Namespace)
}
if spec.Spec.ScaleIO.SecretRef == nil {
t.Fatalf("unexpected nil value for spec.SecretRef")
}
if spec.Spec.ScaleIO.SecretRef.Name != testSecret ||
spec.Spec.ScaleIO.SecretRef.Namespace != testns {
t.Fatalf("spec.SecretRef is not being set properly")
}
spec.Spec.ClaimRef = &api.ObjectReference{Namespace: testns}
// validate provision
actualSpecName := spec.Name
actualVolName := spec.Spec.PersistentVolumeSource.ScaleIO.VolumeName
if !strings.HasPrefix(actualSpecName, "k8svol-") {
t.Errorf("expecting volume name to start with k8svol-, got %s", actualSpecName)
}
vol, err := sio.FindVolume(actualVolName)
if err != nil {
t.Fatalf("failed getting volume %v: %v", actualVolName, err)
}
if vol.Name != actualVolName {
t.Errorf("expected volume name to be %s, got %s", actualVolName, vol.Name)
}
if vol.SizeInKb != 8*1024*1024 {
klog.V(4).Info(log("unexpected volume size"))
}
// mount dynamic vol
sioMounter, err := sioPlug.NewMounter(
volume.NewSpecFromPersistentVolume(spec, false),
&api.Pod{ObjectMeta: meta.ObjectMeta{UID: podUID, Namespace: testns}},
volume.VolumeOptions{},
)
if err != nil {
t.Fatalf("Failed to make a new Mounter: %v", err)
}
sioVol = sioMounter.(*sioVolume)
if err := sioVol.setSioMgr(); err != nil {
t.Fatalf("failed to create sio mgr: %v", err)
}
sioVol.sioMgr.client = sio
if err := sioMounter.SetUp(volume.MounterArgs{}); err != nil {
t.Fatalf("Expected success, got: %v", err)
}
// did we read sdcGUID label
if _, ok := sioVol.sioMgr.configData[confKey.sdcGUID]; !ok {
t.Errorf("Expected to find node label scaleio.sdcGUID, but did not find it")
}
// isMultiMap applied
if !sio.isMultiMap {
t.Errorf("SetUp() expecting attached volume with multi-mapping")
}
// teardown dynamic vol
sioUnmounter, err := sioPlug.NewUnmounter(spec.Name, podUID)
if err != nil {
t.Fatalf("Failed to make a new Unmounter: %v", err)
}
sioVol = sioUnmounter.(*sioVolume)
if err := sioVol.resetSioMgr(); err != nil {
t.Fatalf("failed to reset sio mgr: %v", err)
}
sioVol.sioMgr.client = sio
if err := sioUnmounter.TearDown(); err != nil {
t.Errorf("Expected success, got: %v", err)
}
// test deleter
deleter, err := sioPlug.NewDeleter(volume.NewSpecFromPersistentVolume(spec, false))
if err != nil {
t.Fatalf("failed to create a deleter %v", err)
}
sioVol = deleter.(*sioVolume)
if err := sioVol.setSioMgrFromSpec(); err != nil {
t.Fatalf("failed to set sio mgr: %v", err)
}
sioVol.sioMgr.client = sio
if err := deleter.Delete(); err != nil {
t.Fatalf("failed while deleting vol: %v", err)
}
path := deleter.GetPath()
if _, err := os.Stat(path); err == nil {
t.Errorf("TearDown() failed, volume path still exists: %s", path)
} else if !os.IsNotExist(err) {
t.Errorf("Deleter did not delete path %v: %v", path, err)
}
}
func TestVolumeProvisionerWithIncompleteConfig(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Namespace = testns
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
}
// incomplete options, test should fail
_, err = sioPlug.NewProvisioner(options)
if err == nil {
t.Fatal("expected failure due to incomplete options")
}
}
func TestVolumeProvisionerWithMinimumCapacity(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret(testSecret, testns))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Namespace = testns
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
}
options.Parameters = map[string]string{
confKey.gateway: "http://test.scaleio:11111",
confKey.system: "sio",
confKey.protectionDomain: testSioPD,
confKey.storagePool: "default",
confKey.secretName: "sio-secret",
}
provisioner, _ := sioPlug.NewProvisioner(options)
sio := newFakeSio()
sioVol := provisioner.(*sioVolume)
if err := sioVol.setSioMgrFromConfig(); err != nil {
t.Fatalf("failed to create scaleio mgr from config: %v", err)
}
sioVol.sioMgr.client = sio
pv, err :=
provisioner.Provision(nil, nil)
if err != nil {
t.Fatalf("call to Provision() failed %v", err)
}
pvSize := pv.Spec.Capacity.Storage()
if pvSize == nil {
t.Fatalf("unexpected pv size: nil")
}
gibSize, err := volumehelpers.RoundUpToGiB(*pvSize)
if err != nil {
t.Fatalf("unexpected error while converting size to GiB: %v", err)
}
if gibSize != minimumVolumeSizeGiB {
t.Fatalf("expected GiB size to be %v got %v", minimumVolumeSizeGiB, gibSize)
}
}
func TestVolumeProvisionerWithSecretNamespace(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t, makeScaleIOSecret("sio-sec", "sio-ns"))
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
}
options.PVC.Namespace = "pvc-ns"
options.Parameters = map[string]string{
confKey.gateway: "http://test.scaleio:11111",
confKey.system: "sio",
confKey.protectionDomain: testSioPD,
confKey.storagePool: "default",
confKey.secretName: "sio-sec",
confKey.secretNamespace: "sio-ns",
}
provisioner, _ := sioPlug.NewProvisioner(options)
sio := newFakeSio()
sioVol := provisioner.(*sioVolume)
if err := sioVol.setSioMgrFromConfig(); err != nil {
t.Fatalf("failed to create scaleio mgr from config: %v", err)
}
sioVol.sioMgr.client = sio
spec, err := sioVol.Provision(nil, nil)
if err != nil {
t.Fatalf("call to Provision() failed: %v", err)
}
if spec.GetObjectMeta().GetNamespace() != "pvc-ns" {
t.Fatalf("unexpected spec.namespace %s", spec.GetObjectMeta().GetNamespace())
}
if spec.Spec.ScaleIO.SecretRef.Name != "sio-sec" {
t.Fatalf("unexpected spec.ScaleIOPersistentVolume.SecretRef.Name %v", spec.Spec.ScaleIO.SecretRef.Name)
}
if spec.Spec.ScaleIO.SecretRef.Namespace != "sio-ns" {
t.Fatalf("unexpected spec.ScaleIOPersistentVolume.SecretRef.Namespace %v", spec.Spec.ScaleIO.SecretRef.Namespace)
}
}

View File

@ -1,17 +0,0 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib
# Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
# A macOS metadata file
.DS_Store

View File

@ -1,11 +0,0 @@
go_import_path: github.com/thecodeteam/goscaleio
language: go
go:
- 1.8.3
- 1.9.1
os:
- linux
install: true
script: go build

View File

@ -1,27 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/sirupsen/logrus"
packages = ["."]
revision = "f006c2ac4710855cf0f916dd6b77acf6b048dc6e"
version = "v1.0.3"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = ["ssh/terminal"]
revision = "2509b142fb2b797aa7587dad548f113b2c0f20ce"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix","windows"]
revision = "164713f0dfcec4e80be8b53e1f0811f5f0d84578"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "9a4df6c2b9cbc7b6a8c1f52444dc0bace4dc5e03a39109d0e2f7956c62319982"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,4 +0,0 @@
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# Refer to https://github.com/toml-lang/toml for detailed TOML docs.

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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.

View File

@ -1,81 +0,0 @@
# Goscaleio
The *Goscaleio* project represents API bindings that can be used to provide ScaleIO functionality into other Go applications.
- [Current State](#state)
- [Usage](#usage)
- [Licensing](#licensing)
- [Support](#support)
## Use Cases
Any application written in Go can take advantage of these bindings. Specifically, things that are involved in monitoring, management, and more specifically infrastructrue as code would find these bindings relevant.
## <a id="state">Current State</a>
Early build-out and pre-documentation stages. The basics around authentication and object models are there.
## <a id="usage">Usage</a>
### Logging in
client, err := goscaleio.NewClient()
if err != nil {
log.Fatalf("err: %v", err)
}
_, err = client.Authenticate(&goscaleio.ConfigConnect{endpoint, username, password})
if err != nil {
log.Fatalf("error authenticating: %v", err)
}
fmt.Println("Successfuly logged in to ScaleIO Gateway at", client.SIOEndpoint.String())
### Reusing the authentication token
Once a client struct is created via the ```NewClient()``` function, you can replace the ```Token``` with the saved token.
client, err := goscaleio.NewClient()
if err != nil {
log.Fatalf("error with NewClient: %s", err)
}
client.Token = oldToken
### Get Systems
Retrieving systems is the first step after authentication which enables you to work with other necessary methods.
#### All Systems
systems, err := client.GetInstance()
if err != nil {
log.Fatalf("err: problem getting instance %v", err)
}
#### Find a System
system, err := client.FindSystem(systemid,"","")
if err != nil {
log.Fatalf("err: problem getting instance %v", err)
}
### Get Protection Domains
Once you have a ```System``` struct you can then get other things like ```Protection Domains```.
protectiondomains, err := system.GetProtectionDomain()
if err != nil {
log.Fatalf("error getting protection domains: %v", err)
}
<a id="licensing">Licensing</a>
---------
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.
<a id="support">Support</a>
-------
Please file bugs and issues on the Github issues page for this project. This is to help keep track and document everything related to this repo. For general discussions and further support you can join the [EMC {code} Community slack channel](http://community.emccode.com/). Lastly, for questions asked on [Stackoverflow.com](https://stackoverflow.com) please tag them with **EMC**. The code and documentation are released with no warranties or SLAs and are intended to be supported through a community driven process.

View File

@ -1 +0,0 @@
0.1.0

View File

@ -1,401 +0,0 @@
package goscaleio
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"time"
types "github.com/thecodeteam/goscaleio/types/v1"
log "github.com/sirupsen/logrus"
)
type Client struct {
Token string
SIOEndpoint url.URL
Http http.Client
Insecure string
ShowBody bool
configConnect *ConfigConnect
}
type Cluster struct {
}
type ConfigConnect struct {
Endpoint string
Version string
Username string
Password string
}
type ClientPersistent struct {
configConnect *ConfigConnect
client *Client
}
func (client *Client) getVersion() (string, error) {
endpoint := client.SIOEndpoint
endpoint.Path = "/api/version"
req := client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", client.Token)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return "", fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
version := string(bs)
if client.ShowBody {
log.WithField("body", version).Debug(
"printing version message body")
}
version = strings.TrimRight(version, `"`)
version = strings.TrimLeft(version, `"`)
versionRX := regexp.MustCompile(`^(\d+?\.\d+?).*$`)
if m := versionRX.FindStringSubmatch(version); len(m) > 0 {
return m[1], nil
}
return version, nil
}
func (client *Client) updateVersion() error {
version, err := client.getVersion()
if err != nil {
return err
}
client.configConnect.Version = version
return nil
}
func (client *Client) Authenticate(configConnect *ConfigConnect) (Cluster, error) {
configConnect.Version = client.configConnect.Version
client.configConnect = configConnect
endpoint := client.SIOEndpoint
endpoint.Path += "/login"
req := client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth(configConnect.Username, configConnect.Password)
httpClient := &client.Http
resp, errBody, err := client.checkResp(httpClient.Do(req))
if errBody == nil && err != nil {
return Cluster{}, err
} else if errBody != nil && err != nil {
if resp == nil {
return Cluster{}, errors.New("Problem getting response from endpoint")
}
return Cluster{}, errors.New(errBody.Message)
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return Cluster{}, errors.New("error reading body")
}
token := string(bs)
if client.ShowBody {
log.WithField("body", token).Debug(
"printing authentication message body")
}
token = strings.TrimRight(token, `"`)
token = strings.TrimLeft(token, `"`)
client.Token = token
if client.configConnect.Version == "" {
err = client.updateVersion()
if err != nil {
return Cluster{}, errors.New("error getting version of ScaleIO")
}
}
return Cluster{}, nil
}
//https://github.com/chrislusf/teeproxy/blob/master/teeproxy.go
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
func DuplicateRequest(request *http.Request) (request1 *http.Request, request2 *http.Request) {
request1 = &http.Request{
Method: request.Method,
URL: request.URL,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: request.Header,
Host: request.Host,
ContentLength: request.ContentLength,
}
request2 = &http.Request{
Method: request.Method,
URL: request.URL,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: request.Header,
Host: request.Host,
ContentLength: request.ContentLength,
}
if request.Body != nil {
b1 := new(bytes.Buffer)
b2 := new(bytes.Buffer)
w := io.MultiWriter(b1, b2)
io.Copy(w, request.Body)
request1.Body = nopCloser{b1}
request2.Body = nopCloser{b2}
defer request.Body.Close()
}
return
}
func (client *Client) retryCheckResp(httpClient *http.Client, req *http.Request) (*http.Response, error) {
req1, req2 := DuplicateRequest(req)
resp, errBody, err := client.checkResp(httpClient.Do(req1))
if errBody == nil && err != nil {
return &http.Response{}, err
} else if errBody != nil && err != nil {
if resp == nil {
return nil, errors.New("Problem getting response from endpoint")
}
if resp.StatusCode == 401 && errBody.MajorErrorCode == 0 {
_, err := client.Authenticate(client.configConnect)
if err != nil {
return nil, fmt.Errorf("Error re-authenticating: %s", err)
}
ioutil.ReadAll(resp.Body)
resp.Body.Close()
req2.SetBasicAuth("", client.Token)
resp, errBody, err = client.checkResp(httpClient.Do(req2))
if err != nil {
return &http.Response{}, errors.New(errBody.Message)
}
} else {
return &http.Response{}, errors.New(errBody.Message)
}
}
return resp, nil
}
func (client *Client) checkResp(resp *http.Response, err error) (*http.Response, *types.Error, error) {
if err != nil {
return resp, &types.Error{}, err
}
switch i := resp.StatusCode; {
// Valid request, return the response.
case i == 200 || i == 201 || i == 202 || i == 204:
return resp, &types.Error{}, nil
// Invalid request, parse the XML error returned and return it.
case i == 400 || i == 401 || i == 403 || i == 404 || i == 405 || i == 406 || i == 409 || i == 415 || i == 500 || i == 503 || i == 504:
errBody, err := client.parseErr(resp)
return resp, errBody, err
// Unhandled response.
default:
return nil, &types.Error{}, fmt.Errorf("unhandled API response, please report this issue, status code: %s", resp.Status)
}
}
func (client *Client) decodeBody(resp *http.Response, out interface{}) error {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
if client.ShowBody {
var prettyJSON bytes.Buffer
_ = json.Indent(&prettyJSON, body, "", " ")
log.WithField("body", prettyJSON.String()).Debug(
"print decoded body")
}
if err = json.Unmarshal(body, &out); err != nil {
return err
}
return nil
}
func (client *Client) parseErr(resp *http.Response) (*types.Error, error) {
errBody := new(types.Error)
// if there was an error decoding the body, just return that
if err := client.decodeBody(resp, errBody); err != nil {
return &types.Error{}, fmt.Errorf("error parsing error body for non-200 request: %s", err)
}
return errBody, fmt.Errorf("API (%d) Error: %d: %s", resp.StatusCode, errBody.MajorErrorCode, errBody.Message)
}
func (c *Client) NewRequest(params map[string]string, method string, u url.URL, body io.Reader) *http.Request {
if log.GetLevel() == log.DebugLevel && c.ShowBody && body != nil {
buf := new(bytes.Buffer)
buf.ReadFrom(body)
log.WithField("body", buf.String()).Debug("print new request body")
}
p := url.Values{}
for k, v := range params {
p.Add(k, v)
}
u.RawQuery = p.Encode()
req, _ := http.NewRequest(method, u.String(), body)
return req
}
func NewClient() (client *Client, err error) {
return NewClientWithArgs(
os.Getenv("GOSCALEIO_ENDPOINT"),
os.Getenv("GOSCALEIO_VERSION"),
os.Getenv("GOSCALEIO_INSECURE") == "true",
os.Getenv("GOSCALEIO_USECERTS") == "true")
}
func NewClientWithArgs(
endpoint string,
version string,
insecure,
useCerts bool) (client *Client, err error) {
fields := map[string]interface{}{
"endpoint": endpoint,
"insecure": insecure,
"useCerts": useCerts,
"version": version,
}
var uri *url.URL
if endpoint != "" {
uri, err = url.ParseRequestURI(endpoint)
if err != nil {
return &Client{},
withFieldsE(fields, "error parsing endpoint", err)
}
} else {
return &Client{},
withFields(fields, "endpoint is required")
}
client = &Client{
SIOEndpoint: *uri,
Http: http.Client{
Transport: &http.Transport{
TLSHandshakeTimeout: 120 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: insecure,
},
},
},
}
if useCerts {
pool := x509.NewCertPool()
pool.AppendCertsFromPEM(pemCerts)
client.Http.Transport = &http.Transport{
TLSHandshakeTimeout: 120 * time.Second,
TLSClientConfig: &tls.Config{
RootCAs: pool,
InsecureSkipVerify: insecure,
},
}
}
client.configConnect = &ConfigConnect{
Version: version,
}
return client, nil
}
func GetLink(links []*types.Link, rel string) (*types.Link, error) {
for _, link := range links {
if link.Rel == rel {
return link, nil
}
}
return &types.Link{}, errors.New("Couldn't find link")
}
func withFields(fields map[string]interface{}, message string) error {
return withFieldsE(fields, message, nil)
}
func withFieldsE(
fields map[string]interface{}, message string, inner error) error {
if fields == nil {
fields = make(map[string]interface{})
}
if inner != nil {
fields["inner"] = inner
}
x := 0
l := len(fields)
var b bytes.Buffer
for k, v := range fields {
if x < l-1 {
b.WriteString(fmt.Sprintf("%s=%v,", k, v))
} else {
b.WriteString(fmt.Sprintf("%s=%v", k, v))
}
x = x + 1
}
return newf("%s %s", message, b.String())
}
func newf(format string, a ...interface{}) error {
return errors.New(fmt.Sprintf(format, a))
}

File diff suppressed because it is too large Load Diff

View File

@ -1,110 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"reflect"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type Device struct {
Device *types.Device
client *Client
}
func NewDevice(client *Client) *Device {
return &Device{
Device: new(types.Device),
client: client,
}
}
func NewDeviceEx(client *Client, device *types.Device) *Device {
return &Device{
Device: device,
client: client,
}
}
func (storagePool *StoragePool) AttachDevice(path string, sdsID string) (string, error) {
endpoint := storagePool.client.SIOEndpoint
deviceParam := &types.DeviceParam{}
deviceParam.Name = path
deviceParam.DeviceCurrentPathname = path
deviceParam.StoragePoolID = storagePool.StoragePool.ID
deviceParam.SdsID = sdsID
deviceParam.TestMode = "testAndActivate"
jsonOutput, err := json.Marshal(&deviceParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/Device/instances")
req := storagePool.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
var dev types.DeviceResp
err = json.Unmarshal(bs, &dev)
if err != nil {
return "", err
}
return dev.ID, nil
}
func (storagePool *StoragePool) GetDevice() (devices []types.Device, err error) {
endpoint := storagePool.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/StoragePool::%v/relationships/Device", storagePool.StoragePool.ID)
req := storagePool.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return []types.Device{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = storagePool.client.decodeBody(resp, &devices); err != nil {
return []types.Device{}, fmt.Errorf("error decoding instances response: %s", err)
}
return devices, nil
}
func (storagePool *StoragePool) FindDevice(field, value string) (device *types.Device, err error) {
devices, err := storagePool.GetDevice()
if err != nil {
return &types.Device{}, nil
}
for _, device := range devices {
valueOf := reflect.ValueOf(device)
switch {
case reflect.Indirect(valueOf).FieldByName(field).String() == value:
return &device, nil
}
}
return &types.Device{}, errors.New("Couldn't find DEV")
}

View File

@ -1,228 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strings"
types "github.com/thecodeteam/goscaleio/types/v1"
)
func (client *Client) GetInstance(systemhref string) (systems []*types.System, err error) {
endpoint := client.SIOEndpoint
if systemhref == "" {
endpoint.Path += "/types/System/instances"
} else {
endpoint.Path = systemhref
}
req := client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", client.Token)
req.Header.Add("Accept", "application/json;version="+client.configConnect.Version)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return []*types.System{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if systemhref == "" {
if err = client.decodeBody(resp, &systems); err != nil {
return []*types.System{}, fmt.Errorf("error decoding instances response: %s", err)
}
} else {
system := &types.System{}
if err = client.decodeBody(resp, &system); err != nil {
return []*types.System{}, fmt.Errorf("error decoding instances response: %s", err)
}
systems = append(systems, system)
}
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return types.Systems{}, errors.New("error reading body")
// }
return systems, nil
}
func (client *Client) GetVolume(volumehref, volumeid, ancestorvolumeid, volumename string, getSnapshots bool) (volumes []*types.Volume, err error) {
endpoint := client.SIOEndpoint
if volumename != "" {
volumeid, err = client.FindVolumeID(volumename)
if err != nil && err.Error() == "Not found" {
return nil, nil
}
if err != nil {
return []*types.Volume{}, fmt.Errorf("Error: problem finding volume: %s", err)
}
}
if volumeid != "" {
endpoint.Path = fmt.Sprintf("/api/instances/Volume::%s", volumeid)
} else if volumehref == "" {
endpoint.Path = "/api/types/Volume/instances"
} else {
endpoint.Path = volumehref
}
req := client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", client.Token)
req.Header.Add("Accept", "application/json;version="+client.configConnect.Version)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return []*types.Volume{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if volumehref == "" && volumeid == "" {
if err = client.decodeBody(resp, &volumes); err != nil {
return []*types.Volume{}, fmt.Errorf("error decoding storage pool response: %s", err)
}
var volumesNew []*types.Volume
for _, volume := range volumes {
if (!getSnapshots && volume.AncestorVolumeID == ancestorvolumeid) || (getSnapshots && volume.AncestorVolumeID != "") {
volumesNew = append(volumesNew, volume)
}
}
volumes = volumesNew
} else {
volume := &types.Volume{}
if err = client.decodeBody(resp, &volume); err != nil {
return []*types.Volume{}, fmt.Errorf("error decoding instances response: %s", err)
}
volumes = append(volumes, volume)
}
return volumes, nil
}
func (client *Client) FindVolumeID(volumename string) (volumeID string, err error) {
endpoint := client.SIOEndpoint
volumeQeryIdByKeyParam := &types.VolumeQeryIdByKeyParam{}
volumeQeryIdByKeyParam.Name = volumename
jsonOutput, err := json.Marshal(&volumeQeryIdByKeyParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/Volume/instances/action/queryIdByKey")
req := client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", client.Token)
req.Header.Add("Accept", "application/json;version="+client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+client.configConnect.Version)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
volumeID = string(bs)
volumeID = strings.TrimRight(volumeID, `"`)
volumeID = strings.TrimLeft(volumeID, `"`)
return volumeID, nil
}
func (client *Client) CreateVolume(volume *types.VolumeParam, storagePoolName string) (volumeResp *types.VolumeResp, err error) {
endpoint := client.SIOEndpoint
endpoint.Path = "/api/types/Volume/instances"
storagePool, err := client.FindStoragePool("", storagePoolName, "")
if err != nil {
return nil, err
}
volume.StoragePoolID = storagePool.ID
volume.ProtectionDomainID = storagePool.ProtectionDomainID
jsonOutput, err := json.Marshal(&volume)
if err != nil {
return &types.VolumeResp{}, fmt.Errorf("error marshaling: %s", err)
}
req := client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", client.Token)
req.Header.Add("Accept", "application/json;version="+client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+client.configConnect.Version)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return &types.VolumeResp{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = client.decodeBody(resp, &volumeResp); err != nil {
return &types.VolumeResp{}, fmt.Errorf("error decoding volume creation response: %s", err)
}
return volumeResp, nil
}
func (client *Client) GetStoragePool(storagepoolhref string) (storagePools []*types.StoragePool, err error) {
endpoint := client.SIOEndpoint
if storagepoolhref == "" {
endpoint.Path = "/api/types/StoragePool/instances"
} else {
endpoint.Path = storagepoolhref
}
req := client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", client.Token)
req.Header.Add("Accept", "application/json;version="+client.configConnect.Version)
resp, err := client.retryCheckResp(&client.Http, req)
if err != nil {
return []*types.StoragePool{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if storagepoolhref == "" {
if err = client.decodeBody(resp, &storagePools); err != nil {
return []*types.StoragePool{}, fmt.Errorf("error decoding storage pool response: %s", err)
}
} else {
storagePool := &types.StoragePool{}
if err = client.decodeBody(resp, &storagePool); err != nil {
return []*types.StoragePool{}, fmt.Errorf("error decoding instances response: %s", err)
}
storagePools = append(storagePools, storagePool)
}
return storagePools, nil
}
func (client *Client) FindStoragePool(id, name, href string) (storagePool *types.StoragePool, err error) {
storagePools, err := client.GetStoragePool(href)
if err != nil {
return &types.StoragePool{}, fmt.Errorf("Error getting storage pool %s", err)
}
for _, storagePool = range storagePools {
if storagePool.ID == id || storagePool.Name == name || href != "" {
return storagePool, nil
}
}
return &types.StoragePool{}, errors.New("Couldn't find storage pool")
}

View File

@ -1,131 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type ProtectionDomain struct {
ProtectionDomain *types.ProtectionDomain
client *Client
}
func NewProtectionDomain(client *Client) *ProtectionDomain {
return &ProtectionDomain{
ProtectionDomain: new(types.ProtectionDomain),
client: client,
}
}
func NewProtectionDomainEx(client *Client, pd *types.ProtectionDomain) *ProtectionDomain {
return &ProtectionDomain{
ProtectionDomain: pd,
client: client,
}
}
func (system *System) CreateProtectionDomain(name string) (string, error) {
endpoint := system.client.SIOEndpoint
protectionDomainParam := &types.ProtectionDomainParam{}
protectionDomainParam.Name = name
jsonOutput, err := json.Marshal(&protectionDomainParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/ProtectionDomain/instances")
req := system.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
var pd types.ProtectionDomainResp
err = json.Unmarshal(bs, &pd)
if err != nil {
return "", err
}
return pd.ID, nil
}
func (system *System) GetProtectionDomain(protectiondomainhref string) (protectionDomains []*types.ProtectionDomain, err error) {
endpoint := system.client.SIOEndpoint
if protectiondomainhref == "" {
link, err := GetLink(system.System.Links, "/api/System/relationship/ProtectionDomain")
if err != nil {
return []*types.ProtectionDomain{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
} else {
endpoint.Path = protectiondomainhref
}
req := system.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return []*types.ProtectionDomain{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if protectiondomainhref == "" {
if err = system.client.decodeBody(resp, &protectionDomains); err != nil {
return []*types.ProtectionDomain{}, fmt.Errorf("error decoding instances response: %s", err)
}
} else {
protectionDomain := &types.ProtectionDomain{}
if err = system.client.decodeBody(resp, &protectionDomain); err != nil {
return []*types.ProtectionDomain{}, fmt.Errorf("error decoding instances response: %s", err)
}
protectionDomains = append(protectionDomains, protectionDomain)
}
//
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return []types.ProtectionDomain{}, errors.New("error reading body")
// }
//
// fmt.Println(string(bs))
// log.Fatalf("here")
// return []types.ProtectionDomain{}, nil
return protectionDomains, nil
}
func (system *System) FindProtectionDomain(id, name, href string) (protectionDomain *types.ProtectionDomain, err error) {
protectionDomains, err := system.GetProtectionDomain(href)
if err != nil {
return &types.ProtectionDomain{}, fmt.Errorf("Error getting protection domains %s", err)
}
for _, protectionDomain = range protectionDomains {
if protectionDomain.ID == id || protectionDomain.Name == name || href != "" {
return protectionDomain, nil
}
}
return &types.ProtectionDomain{}, errors.New("Couldn't find protection domain")
}

View File

@ -1,35 +0,0 @@
package goscaleio
import (
"fmt"
types "github.com/thecodeteam/goscaleio/types/v1"
)
func (system *System) GetScsiInitiator() (scsiInitiators []types.ScsiInitiator, err error) {
endpoint := system.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/System::%v/relationships/ScsiInitiator", system.System.ID)
req := system.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return []types.ScsiInitiator{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = system.client.decodeBody(resp, &scsiInitiators); err != nil {
return []types.ScsiInitiator{}, fmt.Errorf("error decoding instances response: %s", err)
}
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return types.ScsiInitiator{}, errors.New("error reading body")
// }
//
// log.Fatalf("here")
// return types.ScsiInitiator{}, nil
return scsiInitiators, nil
}

View File

@ -1,188 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"os/exec"
"reflect"
"strings"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type Sdc struct {
Sdc *types.Sdc
client *Client
}
func NewSdc(client *Client, sdc *types.Sdc) *Sdc {
return &Sdc{
Sdc: sdc,
client: client,
}
}
func (system *System) GetSdc() (sdcs []types.Sdc, err error) {
endpoint := system.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/System::%v/relationships/Sdc", system.System.ID)
req := system.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return []types.Sdc{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = system.client.decodeBody(resp, &sdcs); err != nil {
return []types.Sdc{}, fmt.Errorf("error decoding instances response: %s", err)
}
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return []types.Sdc{}, errors.New("error reading body")
// }
//
// fmt.Println(string(bs))
// log.Fatalf("here")
// return []types.Sdc{}, nil
return sdcs, nil
}
func (system *System) FindSdc(field, value string) (sdc *Sdc, err error) {
sdcs, err := system.GetSdc()
if err != nil {
return &Sdc{}, nil
}
for _, sdc := range sdcs {
valueOf := reflect.ValueOf(sdc)
switch {
case reflect.Indirect(valueOf).FieldByName(field).String() == value:
return NewSdc(system.client, &sdc), nil
}
}
return &Sdc{}, errors.New("Couldn't find SDC")
}
func (sdc *Sdc) GetStatistics() (statistics *types.Statistics, err error) {
endpoint := sdc.client.SIOEndpoint
link, err := GetLink(sdc.Sdc.Links, "/api/Sdc/relationship/Statistics")
if err != nil {
return &types.Statistics{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
req := sdc.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", sdc.client.Token)
req.Header.Add("Accept", "application/json;version="+sdc.client.configConnect.Version)
resp, err := sdc.client.retryCheckResp(&sdc.client.Http, req)
if err != nil {
return &types.Statistics{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = sdc.client.decodeBody(resp, &statistics); err != nil {
return &types.Statistics{}, fmt.Errorf("error decoding instances response: %s", err)
}
return statistics, nil
}
func (sdc *Sdc) GetVolume() (volumes []*types.Volume, err error) {
endpoint := sdc.client.SIOEndpoint
link, err := GetLink(sdc.Sdc.Links, "/api/Sdc/relationship/Volume")
if err != nil {
return []*types.Volume{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
req := sdc.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", sdc.client.Token)
req.Header.Add("Accept", "application/json;version="+sdc.client.configConnect.Version)
resp, err := sdc.client.retryCheckResp(&sdc.client.Http, req)
if err != nil {
return []*types.Volume{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = sdc.client.decodeBody(resp, &volumes); err != nil {
return []*types.Volume{}, fmt.Errorf("error decoding instances response: %s", err)
}
return volumes, nil
}
func GetSdcLocalGUID() (sdcGUID string, err error) {
// get sdc kernel guid
// /bin/emc/scaleio/drv_cfg --query_guid
// sdcKernelGuid := "271bad82-08ee-44f2-a2b1-7e2787c27be1"
out, err := exec.Command("/opt/emc/scaleio/sdc/bin/drv_cfg", "--query_guid").Output()
if err != nil {
return "", fmt.Errorf("GetSdcLocalGUID: query vols failed: %v", err)
}
sdcGUID = strings.Replace(string(out), "\n", "", -1)
return sdcGUID, nil
}
func (volume *Volume) MapVolumeSdc(mapVolumeSdcParam *types.MapVolumeSdcParam) (err error) {
endpoint := volume.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/Volume::%s/action/addMappedSdc", volume.Volume.ID)
jsonOutput, err := json.Marshal(&mapVolumeSdcParam)
if err != nil {
log.Fatalf("error marshaling: %s", err)
}
req := volume.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", volume.client.Token)
req.Header.Add("Accept", "application/json;version="+volume.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+volume.client.configConnect.Version)
resp, err := volume.client.retryCheckResp(&volume.client.Http, req)
if err != nil {
return fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
return nil
}
func (volume *Volume) UnmapVolumeSdc(unmapVolumeSdcParam *types.UnmapVolumeSdcParam) (err error) {
endpoint := volume.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/Volume::%s/action/removeMappedSdc", volume.Volume.ID)
jsonOutput, err := json.Marshal(&unmapVolumeSdcParam)
if err != nil {
return fmt.Errorf("error marshaling: %s", err)
}
req := volume.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", volume.client.Token)
req.Header.Add("Accept", "application/json;version="+volume.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+volume.client.configConnect.Version)
resp, err := volume.client.retryCheckResp(&volume.client.Http, req)
if err != nil {
return fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
return nil
}

View File

@ -1,122 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"reflect"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type Sds struct {
Sds *types.Sds
client *Client
}
func NewSds(client *Client) *Sds {
return &Sds{
Sds: new(types.Sds),
client: client,
}
}
func NewSdsEx(client *Client, sds *types.Sds) *Sds {
return &Sds{
Sds: sds,
client: client,
}
}
func (protectionDomain *ProtectionDomain) CreateSds(name string, ipList []string) (string, error) {
endpoint := protectionDomain.client.SIOEndpoint
sdsParam := &types.SdsParam{}
sdsParam.Name = name
sdsParam.ProtectionDomainID = protectionDomain.ProtectionDomain.ID
if len(ipList) == 0 {
return "", fmt.Errorf("Must provide at least 1 SDS IP")
} else if len(ipList) == 1 {
sdsIP := types.SdsIp{IP: ipList[0], Role: "all"}
sdsIPList := &types.SdsIpList{SdsIP: sdsIP}
sdsParam.IPList = append(sdsParam.IPList, sdsIPList)
} else if len(ipList) >= 2 {
sdsIP1 := types.SdsIp{IP: ipList[0], Role: "sdcOnly"}
sdsIP2 := types.SdsIp{IP: ipList[1], Role: "sdsOnly"}
sdsIPList1 := &types.SdsIpList{SdsIP: sdsIP1}
sdsIPList2 := &types.SdsIpList{SdsIP: sdsIP2}
sdsParam.IPList = append(sdsParam.IPList, sdsIPList1)
sdsParam.IPList = append(sdsParam.IPList, sdsIPList2)
}
jsonOutput, err := json.Marshal(&sdsParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/Sds/instances")
req := protectionDomain.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", protectionDomain.client.Token)
req.Header.Add("Accept", "application/json;version="+protectionDomain.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+protectionDomain.client.configConnect.Version)
resp, err := protectionDomain.client.retryCheckResp(&protectionDomain.client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
var sds types.SdsResp
err = json.Unmarshal(bs, &sds)
if err != nil {
return "", err
}
return sds.ID, nil
}
func (protectionDomain *ProtectionDomain) GetSds() (sdss []types.Sds, err error) {
endpoint := protectionDomain.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/ProtectionDomain::%v/relationships/Sds", protectionDomain.ProtectionDomain.ID)
req := protectionDomain.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", protectionDomain.client.Token)
req.Header.Add("Accept", "application/json;version="+protectionDomain.client.configConnect.Version)
resp, err := protectionDomain.client.retryCheckResp(&protectionDomain.client.Http, req)
if err != nil {
return []types.Sds{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = protectionDomain.client.decodeBody(resp, &sdss); err != nil {
return []types.Sds{}, fmt.Errorf("error decoding instances response: %s", err)
}
return sdss, nil
}
func (protectionDomain *ProtectionDomain) FindSds(field, value string) (sds *types.Sds, err error) {
sdss, err := protectionDomain.GetSds()
if err != nil {
return &types.Sds{}, nil
}
for _, sds := range sdss {
valueOf := reflect.ValueOf(sds)
switch {
case reflect.Indirect(valueOf).FieldByName(field).String() == value:
return &sds, nil
}
}
return &types.Sds{}, errors.New("Couldn't find SDS")
}

View File

@ -1,148 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type StoragePool struct {
StoragePool *types.StoragePool
client *Client
}
func NewStoragePool(client *Client) *StoragePool {
return &StoragePool{
StoragePool: new(types.StoragePool),
client: client,
}
}
func NewStoragePoolEx(client *Client, pool *types.StoragePool) *StoragePool {
return &StoragePool{
StoragePool: pool,
client: client,
}
}
func (protectionDomain *ProtectionDomain) CreateStoragePool(name string) (string, error) {
endpoint := protectionDomain.client.SIOEndpoint
storagePoolParam := &types.StoragePoolParam{}
storagePoolParam.Name = name
storagePoolParam.ProtectionDomainID = protectionDomain.ProtectionDomain.ID
jsonOutput, err := json.Marshal(&storagePoolParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/StoragePool/instances")
req := protectionDomain.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", protectionDomain.client.Token)
req.Header.Add("Accept", "application/json;version="+protectionDomain.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+protectionDomain.client.configConnect.Version)
resp, err := protectionDomain.client.retryCheckResp(&protectionDomain.client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
var sp types.StoragePoolResp
err = json.Unmarshal(bs, &sp)
if err != nil {
return "", err
}
return sp.ID, nil
}
func (protectionDomain *ProtectionDomain) GetStoragePool(storagepoolhref string) (storagePools []*types.StoragePool, err error) {
endpoint := protectionDomain.client.SIOEndpoint
if storagepoolhref == "" {
link, err := GetLink(protectionDomain.ProtectionDomain.Links, "/api/ProtectionDomain/relationship/StoragePool")
if err != nil {
return []*types.StoragePool{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
} else {
endpoint.Path = storagepoolhref
}
req := protectionDomain.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", protectionDomain.client.Token)
req.Header.Add("Accept", "application/json;version="+protectionDomain.client.configConnect.Version)
resp, err := protectionDomain.client.retryCheckResp(&protectionDomain.client.Http, req)
if err != nil {
return []*types.StoragePool{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if storagepoolhref == "" {
if err = protectionDomain.client.decodeBody(resp, &storagePools); err != nil {
return []*types.StoragePool{}, fmt.Errorf("error decoding storage pool response: %s", err)
}
} else {
storagePool := &types.StoragePool{}
if err = protectionDomain.client.decodeBody(resp, &storagePool); err != nil {
return []*types.StoragePool{}, fmt.Errorf("error decoding instances response: %s", err)
}
storagePools = append(storagePools, storagePool)
}
return storagePools, nil
}
func (protectionDomain *ProtectionDomain) FindStoragePool(id, name, href string) (storagePool *types.StoragePool, err error) {
storagePools, err := protectionDomain.GetStoragePool(href)
if err != nil {
return &types.StoragePool{}, fmt.Errorf("Error getting protection domains %s", err)
}
for _, storagePool = range storagePools {
if storagePool.ID == id || storagePool.Name == name || href != "" {
return storagePool, nil
}
}
return &types.StoragePool{}, errors.New("Couldn't find protection domain")
}
func (storagePool *StoragePool) GetStatistics() (statistics *types.Statistics, err error) {
link, err := GetLink(storagePool.StoragePool.Links, "/api/StoragePool/relationship/Statistics")
if err != nil {
return &types.Statistics{}, errors.New("Error: problem finding link")
}
endpoint := storagePool.client.SIOEndpoint
endpoint.Path = link.HREF
req := storagePool.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return &types.Statistics{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = storagePool.client.decodeBody(resp, &statistics); err != nil {
return &types.Statistics{}, fmt.Errorf("error decoding instances response: %s", err)
}
return statistics, nil
}

View File

@ -1,106 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type System struct {
System *types.System
client *Client
}
func NewSystem(client *Client) *System {
return &System{
System: new(types.System),
client: client,
}
}
func (client *Client) FindSystem(instanceID, name, href string) (*System, error) {
systems, err := client.GetInstance(href)
if err != nil {
return &System{}, fmt.Errorf("err: problem getting instances: %s", err)
}
for _, system := range systems {
if system.ID == instanceID || system.Name == name || href != "" {
outSystem := NewSystem(client)
outSystem.System = system
return outSystem, nil
}
}
return &System{}, fmt.Errorf("err: systemid or systemname not found")
}
func (system *System) GetStatistics() (statistics *types.Statistics, err error) {
endpoint := system.client.SIOEndpoint
// endpoint.Path = fmt.Sprintf("/api/instances/System::%v/relationships/Statistics", system.System.ID)
link, err := GetLink(system.System.Links, "/api/System/relationship/Statistics")
if err != nil {
return &types.Statistics{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
req := system.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return &types.Statistics{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = system.client.decodeBody(resp, &statistics); err != nil {
return &types.Statistics{}, fmt.Errorf("error decoding instances response: %s", err)
}
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return errors.New("error reading body")
// }
//
// fmt.Println(string(bs))
return statistics, nil
}
func (system *System) CreateSnapshotConsistencyGroup(snapshotVolumesParam *types.SnapshotVolumesParam) (snapshotVolumesResp *types.SnapshotVolumesResp, err error) {
endpoint := system.client.SIOEndpoint
link, err := GetLink(system.System.Links, "self")
if err != nil {
return &types.SnapshotVolumesResp{}, errors.New("Error: problem finding link")
}
endpoint.Path = fmt.Sprintf("%v/action/snapshotVolumes", link.HREF)
jsonOutput, err := json.Marshal(&snapshotVolumesParam)
if err != nil {
return &types.SnapshotVolumesResp{}, fmt.Errorf("error marshaling: %s", err)
}
req := system.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return &types.SnapshotVolumesResp{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = system.client.decodeBody(resp, &snapshotVolumesResp); err != nil {
return &types.SnapshotVolumesResp{}, fmt.Errorf("error decoding snapshotvolumes response: %s", err)
}
return snapshotVolumesResp, nil
}

View File

@ -1,388 +0,0 @@
package goscaleio
type Error struct {
Message string `xml:"message,attr"`
MajorErrorCode int `xml:"majorErrorCode,attr"`
MinorErrorCode string `xml:"minorErrorCode,attr"`
VendorSpecificErrorCode string `xml:"vendorSpecificErrorCode,attr,omitempty"`
StackTrace string `xml:"stackTrace,attr,omitempty"`
}
// type session struct {
// Link []*types.Link `xml:"Link"`
// }
type System struct {
MdmMode string `json:"mdmMode"`
MdmClusterState string `json:"mdmClusterState"`
SecondaryMdmActorIPList []string `json:"secondaryMdmActorIpList"`
InstallID string `json:"installId"`
PrimaryActorIPList []string `json:"primaryMdmActorIpList"`
SystemVersionName string `json:"systemVersionName"`
CapacityAlertHighThresholdPercent int `json:"capacityAlertHighThresholdPercent"`
CapacityAlertCriticalThresholdPercent int `json:"capacityAlertCriticalThresholdPercent"`
RemoteReadOnlyLimitState bool `json:"remoteReadOnlyLimitState"`
PrimaryMdmActorPort int `json:"primaryMdmActorPort"`
SecondaryMdmActorPort int `json:"secondaryMdmActorPort"`
TiebreakerMdmActorPort int `json:"tiebreakerMdmActorPort"`
MdmManagementPort int `json:"mdmManagementPort"`
TiebreakerMdmIPList []string `json:"tiebreakerMdmIpList"`
MdmManagementIPList []string `json:"mdmManagementIPList"`
DefaultIsVolumeObfuscated bool `json:"defaultIsVolumeObfuscated"`
RestrictedSdcModeEnabled bool `json:"restrictedSdcModeEnabled"`
Swid string `json:"swid"`
DaysInstalled int `json:"daysInstalled"`
MaxCapacityInGb string `json:"maxCapacityInGb"`
CapacityTimeLeftInDays string `json:"capacityTimeLeftInDays"`
EnterpriseFeaturesEnabled bool `json:"enterpriseFeaturesEnabled"`
IsInitialLicense bool `json:"isInitialLicense"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type Link struct {
Rel string `json:"rel"`
HREF string `json:"href"`
}
type BWC struct {
TotalWeightInKb int `json:"totalWeightInKb"`
NumOccured int `json:"numOccured"`
NumSeconds int `json:"numSeconds"`
}
type Statistics struct {
PrimaryReadFromDevBwc BWC `json:"primaryReadFromDevBwc"`
NumOfStoragePools int `json:"numOfStoragePools"`
ProtectedCapacityInKb int `json:"protectedCapacityInKb"`
MovingCapacityInKb int `json:"movingCapacityInKb"`
SnapCapacityInUseOccupiedInKb int `json:"snapCapacityInUseOccupiedInKb"`
SnapCapacityInUseInKb int `json:"snapCapacityInUseInKb"`
ActiveFwdRebuildCapacityInKb int `json:"activeFwdRebuildCapacityInKb"`
DegradedHealthyVacInKb int `json:"degradedHealthyVacInKb"`
ActiveMovingRebalanceJobs int `json:"activeMovingRebalanceJobs"`
TotalReadBwc BWC `json:"totalReadBwc"`
MaxCapacityInKb int `json:"maxCapacityInKb"`
PendingBckRebuildCapacityInKb int `json:"pendingBckRebuildCapacityInKb"`
ActiveMovingOutFwdRebuildJobs int `json:"activeMovingOutFwdRebuildJobs"`
CapacityLimitInKb int `json:"capacityLimitInKb"`
SecondaryVacInKb int `json:"secondaryVacInKb"`
PendingFwdRebuildCapacityInKb int `json:"pendingFwdRebuildCapacityInKb"`
ThinCapacityInUseInKb int `json:"thinCapacityInUseInKb"`
AtRestCapacityInKb int `json:"atRestCapacityInKb"`
ActiveMovingInBckRebuildJobs int `json:"activeMovingInBckRebuildJobs"`
DegradedHealthyCapacityInKb int `json:"degradedHealthyCapacityInKb"`
NumOfScsiInitiators int `json:"numOfScsiInitiators"`
NumOfUnmappedVolumes int `json:"numOfUnmappedVolumes"`
FailedCapacityInKb int `json:"failedCapacityInKb"`
SecondaryReadFromDevBwc BWC `json:"secondaryReadFromDevBwc"`
NumOfVolumes int `json:"numOfVolumes"`
SecondaryWriteBwc BWC `json:"secondaryWriteBwc"`
ActiveBckRebuildCapacityInKb int `json:"activeBckRebuildCapacityInKb"`
FailedVacInKb int `json:"failedVacInKb"`
PendingMovingCapacityInKb int `json:"pendingMovingCapacityInKb"`
ActiveMovingInRebalanceJobs int `json:"activeMovingInRebalanceJobs"`
PendingMovingInRebalanceJobs int `json:"pendingMovingInRebalanceJobs"`
BckRebuildReadBwc BWC `json:"bckRebuildReadBwc"`
DegradedFailedVacInKb int `json:"degradedFailedVacInKb"`
NumOfSnapshots int `json:"numOfSnapshots"`
RebalanceCapacityInKb int `json:"rebalanceCapacityInKb"`
fwdRebuildReadBwc BWC `json:"fwdRebuildReadBwc"`
NumOfSdc int `json:"numOfSdc"`
ActiveMovingInFwdRebuildJobs int `json:"activeMovingInFwdRebuildJobs"`
NumOfVtrees int `json:"numOfVtrees"`
ThickCapacityInUseInKb int `json:"thickCapacityInUseInKb"`
ProtectedVacInKb int `json:"protectedVacInKb"`
PendingMovingInBckRebuildJobs int `json:"pendingMovingInBckRebuildJobs"`
CapacityAvailableForVolumeAllocationInKb int `json:"capacityAvailableForVolumeAllocationInKb"`
PendingRebalanceCapacityInKb int `json:"pendingRebalanceCapacityInKb"`
PendingMovingRebalanceJobs int `json:"pendingMovingRebalanceJobs"`
NumOfProtectionDomains int `json:"numOfProtectionDomains"`
NumOfSds int `json:"numOfSds"`
CapacityInUseInKb int `json:"capacityInUseInKb"`
BckRebuildWriteBwc BWC `json:"bckRebuildWriteBwc"`
DegradedFailedCapacityInKb int `json:"degradedFailedCapacityInKb"`
NumOfThinBaseVolumes int `json:"numOfThinBaseVolumes"`
PendingMovingOutFwdRebuildJobs int `json:"pendingMovingOutFwdRebuildJobs"`
SecondaryReadBwc BWC `json:"secondaryReadBwc"`
PendingMovingOutBckRebuildJobs int `json:"pendingMovingOutBckRebuildJobs"`
RebalanceWriteBwc BWC `json:"rebalanceWriteBwc"`
PrimaryReadBwc BWC `json:"primaryReadBwc"`
NumOfVolumesInDeletion int `json:"numOfVolumesInDeletion"`
NumOfDevices int `json:"numOfDevices"`
RebalanceReadBwc BWC `json:"rebalanceReadBwc"`
InUseVacInKb int `json:"inUseVacInKb"`
UnreachableUnusedCapacityInKb int `json:"unreachableUnusedCapacityInKb"`
TotalWriteBwc BWC `json:"totalWriteBwc"`
SpareCapacityInKb int `json:"spareCapacityInKb"`
ActiveMovingOutBckRebuildJobs int `json:"activeMovingOutBckRebuildJobs"`
PrimaryVacInKb int `json:"primaryVacInKb"`
NumOfThickBaseVolumes int `json:"numOfThickBaseVolumes"`
BckRebuildCapacityInKb int `json:"bckRebuildCapacityInKb"`
NumOfMappedToAllVolumes int `json:"numOfMappedToAllVolumes"`
ActiveMovingCapacityInKb int `json:"activeMovingCapacityInKb"`
PendingMovingInFwdRebuildJobs int `json:"pendingMovingInFwdRebuildJobs"`
ActiveRebalanceCapacityInKb int `json:"activeRebalanceCapacityInKb"`
RmcacheSizeInKb int `json:"rmcacheSizeInKb"`
FwdRebuildCapacityInKb int `json:"fwdRebuildCapacityInKb"`
FwdRebuildWriteBwc BWC `json:"fwdRebuildWriteBwc"`
PrimaryWriteBwc BWC `json:"primaryWriteBwc"`
}
type User struct {
SystemID string `json:"systemId"`
UserRole string `json:"userRole"`
PasswordChangeRequire bool `json:"passwordChangeRequired"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type ScsiInitiator struct {
Name string `json:"name"`
IQN string `json:"iqn"`
SystemID string `json:"systemID"`
Links []*Link `json:"links"`
}
type ProtectionDomain struct {
SystemID string `json:"systemId"`
RebuildNetworkThrottlingInKbps int `json:"rebuildNetworkThrottlingInKbps"`
RebalanceNetworkThrottlingInKbps int `json:"rebalanceNetworkThrottlingInKbps"`
OverallIoNetworkThrottlingInKbps int `json:"overallIoNetworkThrottlingInKbps"`
OverallIoNetworkThrottlingEnabled bool `json:"overallIoNetworkThrottlingEnabled"`
RebuildNetworkThrottlingEnabled bool `json:"rebuildNetworkThrottlingEnabled"`
RebalanceNetworkThrottlingEnabled bool `json:"rebalanceNetworkThrottlingEnabled"`
ProtectionDomainState string `json:"protectionDomainState"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type ProtectionDomainParam struct {
Name string `json:"name"`
}
type ProtectionDomainResp struct {
ID string `json:"id"`
}
type Sdc struct {
SystemID string `json:"systemId"`
SdcApproved bool `json:"sdcApproved"`
SdcIp string `json:"SdcIp"`
OnVmWare bool `json:"onVmWare"`
SdcGuid string `json:"sdcGuid"`
MdmConnectionState string `json:"mdmConnectionState"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type SdsIp struct {
IP string `json:"ip"`
Role string `json:"role"`
}
type SdsIpList struct {
SdsIP SdsIp `json:"SdsIp"`
}
type Sds struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
ProtectionDomainID string `json:"protectionDomainId"`
IPList []*SdsIpList `json:"ipList"`
Port int `json:"port,omitempty"`
SdsState string `json:"sdsState"`
MembershipState string `json:"membershipState"`
MdmConnectionState string `json:"mdmConnectionState"`
DrlMode string `json:"drlMode,omitempty"`
RmcacheEnabled bool `json:"rmcacheEnabled,omitempty"`
RmcacheSizeInKb int `json:"rmcacheSizeInKb,omitempty"`
RmcacheFrozen bool `json:"rmcacheFrozen,omitempty"`
IsOnVMware bool `json:"isOnVmWare,omitempty"`
FaultSetID string `json:"faultSetId,omitempty"`
NumOfIoBuffers int `json:"numOfIoBuffers,omitempty"`
RmcacheMemoryAllocationState string `json:"RmcacheMemoryAllocationState,omitempty"`
}
type DeviceInfo struct {
DevicePath string `json:"devicePath"`
StoragePoolID string `json:"storagePoolId"`
DeviceName string `json:"deviceName,omitempty"`
}
type SdsParam struct {
Name string `json:"name,omitempty"`
IPList []*SdsIpList `json:"sdsIpList"`
Port int `json:"sdsPort,omitempty"`
DrlMode string `json:"drlMode,omitempty"`
RmcacheEnabled bool `json:"rmcacheEnabled,omitempty"`
RmcacheSizeInKb int `json:"rmcacheSizeInKb,omitempty"`
RmcacheFrozen bool `json:"rmcacheFrozen,omitempty"`
ProtectionDomainID string `json:"protectionDomainId"`
FaultSetID string `json:"faultSetId,omitempty"`
NumOfIoBuffers int `json:"numOfIoBuffers,omitempty"`
DeviceInfoList []*DeviceInfo `json:"deviceInfoList,omitempty"`
ForceClean bool `json:"forceClean,omitempty"`
DeviceTestTimeSecs int `json:"deviceTestTimeSecs ,omitempty"`
DeviceTestMode string `json:"deviceTestMode,omitempty"`
}
type SdsResp struct {
ID string `json:"id"`
}
type Device struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
DeviceCurrentPathname string `json:"deviceCurrentPathname"`
DeviceOriginalPathname string `json:"deviceOriginalPathname,omitempty"`
DeviceState string `json:"deviceState,omitempty"`
ErrorState string `json:"errorState,omitempty"`
CapacityLimitInKb int `json:"capacityLimitInKb,omitempty"`
MaxCapacityInKb int `json:"maxCapacityInKb,omitempty"`
StoragePoolID string `json:"storagePoolId"`
SdsID string `json:"sdsId"`
}
type DeviceParam struct {
Name string `json:"name,omitempty"`
DeviceCurrentPathname string `json:"deviceCurrentPathname"`
CapacityLimitInKb int `json:"capacityLimitInKb,omitempty"`
StoragePoolID string `json:"storagePoolId"`
SdsID string `json:"sdsId"`
TestTimeSecs int `json:"testTimeSecs,omitempty"`
TestMode string `json:"testMode,omitempty"`
}
type DeviceResp struct {
ID string `json:"id"`
}
type StoragePool struct {
ProtectionDomainID string `json:"protectionDomainId"`
RebalanceioPriorityPolicy string `json:"rebalanceIoPriorityPolicy"`
RebuildioPriorityPolicy string `json:"rebuildIoPriorityPolicy"`
RebuildioPriorityBwLimitPerDeviceInKbps int `json:"rebuildIoPriorityBwLimitPerDeviceInKbps"`
RebuildioPriorityNumOfConcurrentIosPerDevice int `json:"rebuildIoPriorityNumOfConcurrentIosPerDevice"`
RebalanceioPriorityNumOfConcurrentIosPerDevice int `json:"rebalanceIoPriorityNumOfConcurrentIosPerDevice"`
RebalanceioPriorityBwLimitPerDeviceInKbps int `json:"rebalanceIoPriorityBwLimitPerDeviceInKbps"`
RebuildioPriorityAppIopsPerDeviceThreshold int `json:"rebuildIoPriorityAppIopsPerDeviceThreshold"`
RebalanceioPriorityAppIopsPerDeviceThreshold int `json:"rebalanceIoPriorityAppIopsPerDeviceThreshold"`
RebuildioPriorityAppBwPerDeviceThresholdInKbps int `json:"rebuildIoPriorityAppBwPerDeviceThresholdInKbps"`
RebalanceioPriorityAppBwPerDeviceThresholdInKbps int `json:"rebalanceIoPriorityAppBwPerDeviceThresholdInKbps"`
RebuildioPriorityQuietPeriodInMsec int `json:"rebuildIoPriorityQuietPeriodInMsec"`
RebalanceioPriorityQuietPeriodInMsec int `json:"rebalanceIoPriorityQuietPeriodInMsec"`
ZeroPaddingEnabled bool `json:"zeroPaddingEnabled"`
UseRmcache bool `json:"useRmcache"`
SparePercentage int `json:"sparePercentage"`
RmCacheWriteHandlingMode string `json:"rmcacheWriteHandlingMode"`
RebuildEnabled bool `json:"rebuildEnabled"`
RebalanceEnabled bool `json:"rebalanceEnabled"`
NumofParallelRebuildRebalanceJobsPerDevice int `json:"numOfParallelRebuildRebalanceJobsPerDevice"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type StoragePoolParam struct {
Name string `json:"name"`
SparePercentage int `json:"sparePercentage,omitempty"`
RebuildEnabled bool `json:"rebuildEnabled,omitempty"`
RebalanceEnabled bool `json:"rebalanceEnabled,omitempty"`
ProtectionDomainID string `json:"protectionDomainId"`
ZeroPaddingEnabled bool `json:"zeroPaddingEnabled,omitempty"`
UseRmcache bool `json:"useRmcache,omitempty"`
RmcacheWriteHandlingMode string `json:"rmcacheWriteHandlingMode,omitempty"`
}
type StoragePoolResp struct {
ID string `json:"id"`
}
type MappedSdcInfo struct {
SdcID string `json:"sdcId"`
SdcIP string `json:"sdcIp"`
LimitIops int `json:"limitIops"`
LimitBwInMbps int `json:"limitBwInMbps"`
}
type Volume struct {
StoragePoolID string `json:"storagePoolId"`
UseRmCache bool `json:"useRmcache"`
MappingToAllSdcsEnabled bool `json:"mappingToAllSdcsEnabled"`
MappedSdcInfo []*MappedSdcInfo `json:"mappedSdcInfo"`
IsObfuscated bool `json:"isObfuscated"`
VolumeType string `json:"volumeType"`
ConsistencyGroupID string `json:"consistencyGroupId"`
VTreeID string `json:"vtreeId"`
AncestorVolumeID string `json:"ancestorVolumeId"`
MappedScsiInitiatorInfo string `json:"mappedScsiInitiatorInfo"`
SizeInKb int `json:"sizeInKb"`
CreationTime int `json:"creationTime"`
Name string `json:"name"`
ID string `json:"id"`
Links []*Link `json:"links"`
}
type VolumeParam struct {
ProtectionDomainID string `json:"protectionDomainId,omitempty"`
StoragePoolID string `json:"storagePoolId,omitempty"`
UseRmCache string `json:"useRmcache,omitempty"`
VolumeType string `json:"volumeType,omitempty"`
VolumeSizeInKb string `json:"volumeSizeInKb,omitempty"`
Name string `json:"name,omitempty"`
}
type VolumeResp struct {
ID string `json:"id"`
}
type VolumeQeryIdByKeyParam struct {
Name string `json:"name"`
}
type VolumeQeryBySelectedIdsParam struct {
IDs []string `json:"ids"`
}
type MapVolumeSdcParam struct {
SdcID string `json:"sdcId,omitempty"`
AllowMultipleMappings string `json:"allowMultipleMappings,omitempty"`
AllSdcs string `json:"allSdcs,omitempty"`
}
type UnmapVolumeSdcParam struct {
SdcID string `json:"sdcId,omitempty"`
IgnoreScsiInitiators string `json:"ignoreScsiInitiators,omitempty"`
AllSdcs string `json:"allSdcs,omitempty"`
}
type SnapshotDef struct {
VolumeID string `json:"volumeId,omitempty"`
SnapshotName string `json:"snapshotName,omitempty"`
}
type SnapshotVolumesParam struct {
SnapshotDefs []*SnapshotDef `json:"snapshotDefs"`
}
type SnapshotVolumesResp struct {
VolumeIDList []string `json:"volumeIdList"`
SnapshotGroupID string `json:"snapshotGroupId"`
}
type VTree struct {
ID string `json:"id"`
Name string `json:"name"`
BaseVolumeID string `json:"baseVolumeId"`
StoragePoolID string `json:"storagePoolId"`
Links []*Link `json:"links"`
}
type RemoveVolumeParam struct {
RemoveMode string `json:"removeMode"`
}

View File

@ -1,35 +0,0 @@
package goscaleio
import (
"fmt"
types "github.com/thecodeteam/goscaleio/types/v1"
)
func (system *System) GetUser() (user []types.User, err error) {
endpoint := system.client.SIOEndpoint
endpoint.Path = fmt.Sprintf("/api/instances/System::%v/relationships/User", system.System.ID)
req := system.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", system.client.Token)
req.Header.Add("Accept", "application/json;version="+system.client.configConnect.Version)
resp, err := system.client.retryCheckResp(&system.client.Http, req)
if err != nil {
return []types.User{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = system.client.decodeBody(resp, &user); err != nil {
return []types.User{}, fmt.Errorf("error decoding instances response: %s", err)
}
// bs, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return types.User{}, errors.New("error reading body")
// }
//
// fmt.Println(string(bs))
// return types.User{}, nil
return user, nil
}

View File

@ -1,279 +0,0 @@
package goscaleio
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os/exec"
"path/filepath"
"regexp"
"sort"
"strings"
types "github.com/thecodeteam/goscaleio/types/v1"
)
type SdcMappedVolume struct {
MdmID string
VolumeID string
SdcDevice string
// Mounted bool
// MountPath bool
// Mapped bool
}
type Volume struct {
Volume *types.Volume
client *Client
}
func NewVolume(client *Client) *Volume {
return &Volume{
Volume: new(types.Volume),
client: client,
}
}
func (storagePool *StoragePool) GetVolume(volumehref, volumeid, ancestorvolumeid, volumename string, getSnapshots bool) (volumes []*types.Volume, err error) {
endpoint := storagePool.client.SIOEndpoint
if volumename != "" {
volumeid, err = storagePool.FindVolumeID(volumename)
if err != nil && err.Error() == "Not found" {
return nil, nil
}
if err != nil {
return []*types.Volume{}, fmt.Errorf("Error: problem finding volume: %s", err)
}
}
if volumeid != "" {
endpoint.Path = fmt.Sprintf("/api/instances/Volume::%s", volumeid)
} else if volumehref == "" {
link, err := GetLink(storagePool.StoragePool.Links, "/api/StoragePool/relationship/Volume")
if err != nil {
return []*types.Volume{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
} else {
endpoint.Path = volumehref
}
req := storagePool.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return []*types.Volume{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if volumehref == "" && volumeid == "" {
if err = storagePool.client.decodeBody(resp, &volumes); err != nil {
return []*types.Volume{}, fmt.Errorf("error decoding storage pool response: %s", err)
}
var volumesNew []*types.Volume
for _, volume := range volumes {
if (!getSnapshots && volume.AncestorVolumeID == ancestorvolumeid) || (getSnapshots && volume.AncestorVolumeID != "") {
volumesNew = append(volumesNew, volume)
}
}
volumes = volumesNew
} else {
volume := &types.Volume{}
if err = storagePool.client.decodeBody(resp, &volume); err != nil {
return []*types.Volume{}, fmt.Errorf("error decoding instances response: %s", err)
}
volumes = append(volumes, volume)
}
return volumes, nil
}
func (storagePool *StoragePool) FindVolumeID(volumename string) (volumeID string, err error) {
endpoint := storagePool.client.SIOEndpoint
volumeQeryIdByKeyParam := &types.VolumeQeryIdByKeyParam{}
volumeQeryIdByKeyParam.Name = volumename
jsonOutput, err := json.Marshal(&volumeQeryIdByKeyParam)
if err != nil {
return "", fmt.Errorf("error marshaling: %s", err)
}
endpoint.Path = fmt.Sprintf("/api/types/Volume/instances/action/queryIdByKey")
req := storagePool.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return "", err
}
defer resp.Body.Close()
bs, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.New("error reading body")
}
volumeID = string(bs)
volumeID = strings.TrimRight(volumeID, `"`)
volumeID = strings.TrimLeft(volumeID, `"`)
return volumeID, nil
}
func GetLocalVolumeMap() (mappedVolumes []*SdcMappedVolume, err error) {
// get sdc kernel guid
// /bin/emc/scaleio/drv_cfg --query_guid
// sdcKernelGuid := "271bad82-08ee-44f2-a2b1-7e2787c27be1"
mappedVolumesMap := make(map[string]*SdcMappedVolume)
out, err := exec.Command("/opt/emc/scaleio/sdc/bin/drv_cfg", "--query_vols").Output()
if err != nil {
return []*SdcMappedVolume{},
fmt.Errorf("GetLocalVolumeMap: query vols failed: %v", err)
}
result := string(out)
lines := strings.Split(result, "\n")
for _, line := range lines {
split := strings.Split(line, " ")
if split[0] == "VOL-ID" {
mappedVolume := &SdcMappedVolume{MdmID: split[3], VolumeID: split[1]}
mdmVolumeID := fmt.Sprintf("%s-%s", mappedVolume.MdmID, mappedVolume.VolumeID)
mappedVolumesMap[mdmVolumeID] = mappedVolume
}
}
diskIDPath := "/dev/disk/by-id"
files, _ := ioutil.ReadDir(diskIDPath)
r, _ := regexp.Compile(`^emc-vol-\w*-\w*$`)
for _, f := range files {
matched := r.MatchString(f.Name())
if matched {
mdmVolumeID := strings.Replace(f.Name(), "emc-vol-", "", 1)
devPath, _ := filepath.EvalSymlinks(fmt.Sprintf("%s/%s", diskIDPath, f.Name()))
if _, ok := mappedVolumesMap[mdmVolumeID]; ok {
mappedVolumesMap[mdmVolumeID].SdcDevice = devPath
}
}
}
keys := make([]string, 0, len(mappedVolumesMap))
for key := range mappedVolumesMap {
keys = append(keys, key)
}
sort.Strings(keys)
for _, key := range keys {
mappedVolumes = append(mappedVolumes, mappedVolumesMap[key])
}
return mappedVolumes, nil
}
func (storagePool *StoragePool) CreateVolume(volume *types.VolumeParam) (volumeResp *types.VolumeResp, err error) {
endpoint := storagePool.client.SIOEndpoint
endpoint.Path = "/api/types/Volume/instances"
volume.StoragePoolID = storagePool.StoragePool.ID
volume.ProtectionDomainID = storagePool.StoragePool.ProtectionDomainID
jsonOutput, err := json.Marshal(&volume)
if err != nil {
return &types.VolumeResp{}, fmt.Errorf("error marshaling: %s", err)
}
req := storagePool.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", storagePool.client.Token)
req.Header.Add("Accept", "application/json;version="+storagePool.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+storagePool.client.configConnect.Version)
resp, err := storagePool.client.retryCheckResp(&storagePool.client.Http, req)
if err != nil {
return &types.VolumeResp{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = storagePool.client.decodeBody(resp, &volumeResp); err != nil {
return &types.VolumeResp{}, fmt.Errorf("error decoding volume creation response: %s", err)
}
return volumeResp, nil
}
func (volume *Volume) GetVTree() (vtree *types.VTree, err error) {
endpoint := volume.client.SIOEndpoint
link, err := GetLink(volume.Volume.Links, "/api/parent/relationship/vtreeId")
if err != nil {
return &types.VTree{}, errors.New("Error: problem finding link")
}
endpoint.Path = link.HREF
req := volume.client.NewRequest(map[string]string{}, "GET", endpoint, nil)
req.SetBasicAuth("", volume.client.Token)
req.Header.Add("Accept", "application/json;version="+volume.client.configConnect.Version)
resp, err := volume.client.retryCheckResp(&volume.client.Http, req)
if err != nil {
return &types.VTree{}, fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
if err = volume.client.decodeBody(resp, &vtree); err != nil {
return &types.VTree{}, fmt.Errorf("error decoding vtree response: %s", err)
}
return vtree, nil
}
func (volume *Volume) RemoveVolume(removeMode string) (err error) {
endpoint := volume.client.SIOEndpoint
link, err := GetLink(volume.Volume.Links, "self")
if err != nil {
return errors.New("Error: problem finding link")
}
endpoint.Path = fmt.Sprintf("%v/action/removeVolume", link.HREF)
if removeMode == "" {
removeMode = "ONLY_ME"
}
removeVolumeParam := &types.RemoveVolumeParam{
RemoveMode: removeMode,
}
jsonOutput, err := json.Marshal(&removeVolumeParam)
if err != nil {
return fmt.Errorf("error marshaling: %s", err)
}
req := volume.client.NewRequest(map[string]string{}, "POST", endpoint, bytes.NewBufferString(string(jsonOutput)))
req.SetBasicAuth("", volume.client.Token)
req.Header.Add("Accept", "application/json;version="+volume.client.configConnect.Version)
req.Header.Add("Content-Type", "application/json;version="+volume.client.configConnect.Version)
resp, err := volume.client.retryCheckResp(&volume.client.Http, req)
if err != nil {
return fmt.Errorf("problem getting response: %v", err)
}
defer resp.Body.Close()
return nil
}

5
vendor/modules.txt vendored
View File

@ -760,10 +760,6 @@ github.com/stretchr/testify/require
github.com/subosito/gotenv
# github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 => github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
github.com/syndtr/gocapability/capability
# github.com/thecodeteam/goscaleio v0.1.0 => github.com/thecodeteam/goscaleio v0.1.0
## explicit
github.com/thecodeteam/goscaleio
github.com/thecodeteam/goscaleio/types/v1
# github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 => github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
github.com/tmc/grpc-websocket-proxy/wsproxy
# github.com/urfave/negroni v1.0.0 => github.com/urfave/negroni v1.0.0
@ -2614,7 +2610,6 @@ sigs.k8s.io/yaml
# github.com/stretchr/testify => github.com/stretchr/testify v1.7.0
# github.com/subosito/gotenv => github.com/subosito/gotenv v1.2.0
# github.com/syndtr/gocapability => github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
# github.com/thecodeteam/goscaleio => github.com/thecodeteam/goscaleio v0.1.0
# github.com/tidwall/pretty => github.com/tidwall/pretty v1.0.0
# github.com/tmc/grpc-websocket-proxy => github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
# github.com/urfave/cli => github.com/urfave/cli v1.22.2