Skip to content

Commit

Permalink
Merge pull request #115 from opensds/development
Browse files Browse the repository at this point in the history
Merge from development to master to prepare for Bali milestone-1
  • Loading branch information
stmcginnis authored Aug 6, 2018
2 parents e2556a4 + b094404 commit 0a6ed16
Show file tree
Hide file tree
Showing 20 changed files with 1,164 additions and 407 deletions.
4 changes: 2 additions & 2 deletions client/iscsi/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func waitForPathToExistInternal(devicePath *string, maxRetries int, deviceTransp
}

func execCmd(name string, arg ...string) (string, error) {
log.Printf("Command: %s %s:\n", name, strings.Join(arg, " "))
log.Printf("Command: %s %s\n", name, strings.Join(arg, " "))
info, err := exec.Command(name, arg...).CombinedOutput()
return string(info), err
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func Mount(device string, mountpoint string) error {
}

// FormatandMount device
func FormatandMount(device string, fstype string, mountpoint string) error {
func FormatAndMount(device string, fstype string, mountpoint string) error {
log.Printf("FormatandMount device: %s fstype: %s mountpoint: %s", device, fstype, mountpoint)

// Format
Expand Down
117 changes: 117 additions & 0 deletions csi/client/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"io/ioutil"
"os"

"encoding/json"
"github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/golang/glog"
"github.com/opensds/nbp/csi/util"
)

const (
dbPath = "csi_client_db"
volumeFileName = "csi_client_db/volume"
publishVolumeFileName = "csi_client_db/publish_volume"
testStageFileName = "csi_client_db/stage"
)

const (
stageStart = "start"
stageVolume = "volume"
stageControllerPublish = "controllerPublish"
stageNodePublish = "nodePublish"
)

func init() {
if exist, _ := util.PathExists(dbPath); !exist {
os.MkdirAll(dbPath, 0755)
}
}

func readFile(fname string) ([]byte, error) {
b, err := ioutil.ReadFile(fname)
if err != nil {
glog.Error(err)
}
return b, err
}

func writeFile(fname string, data []byte) error {
return ioutil.WriteFile(fname, data, 0644)
}

func StoreVolume(vol *csi.Volume) error {
data, err := json.Marshal(vol)
if err != nil {
return err
}
return writeFile(volumeFileName, data)
}

func GetVolume() (*csi.Volume, error) {
vol := &csi.Volume{}
data, err := readFile(volumeFileName)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, vol)
return vol, err
}

func StorePublishVolume(publishVol map[string]string) error {
data, err := json.Marshal(publishVol)
if err != nil {
return err
}
return writeFile(publishVolumeFileName, data)
}

func GetPublishVolume() (map[string]string, error) {
publishVol := map[string]string{}
data, err := readFile(publishVolumeFileName)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, &publishVol)
return publishVol, err
}

func GetTestStage() (string, error) {
data, err := readFile(testStageFileName)
if err != nil {
if !os.IsExist(err) {
return stageStart, nil
} else {
return "", err
}
}
return string(data), nil
}

func SetTestStage(stage string) error {
err := writeFile(testStageFileName, []byte(stage))
if err != nil {
glog.Errorf("Set stage fail %v", err)
}
return err
}

func RemoveDbFile() {
os.RemoveAll(dbPath)
}
Loading

0 comments on commit 0a6ed16

Please sign in to comment.