Skip to content

Commit

Permalink
Merge pull request #192 from akutz/feature/gotil
Browse files Browse the repository at this point in the history
Goutil Integration
  • Loading branch information
akutz committed Dec 2, 2015
2 parents 30d426f + 1dfea5a commit 8919982
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 551 deletions.
8 changes: 4 additions & 4 deletions core/rexray.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
log "github.com/Sirupsen/logrus"

"github.com/akutz/gofig"
"github.com/emccode/rexray/util"
"github.com/akutz/gotil"
)

// RexRay is the library's entrance type and storage management platform.
Expand Down Expand Up @@ -61,7 +61,7 @@ func (r *RexRay) InitDrivers() error {
for n, d := range r.drivers {
switch td := d.(type) {
case OSDriver:
if util.StringInSlice(n, osDrivers) {
if gotil.StringInSlice(n, osDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
Expand All @@ -71,7 +71,7 @@ func (r *RexRay) InitDrivers() error {
od[n] = td
}
case VolumeDriver:
if util.StringInSlice(n, volDrivers) {
if gotil.StringInSlice(n, volDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
Expand All @@ -81,7 +81,7 @@ func (r *RexRay) InitDrivers() error {
vd[n] = td
}
case StorageDriver:
if util.StringInSlice(n, storDrivers) {
if gotil.StringInSlice(n, storDrivers) {
if err := d.Init(r); err != nil {
log.WithFields(log.Fields{
"driverName": n,
Expand Down
15 changes: 8 additions & 7 deletions daemon/module/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package admin
import (
"encoding/json"
"fmt"
log "github.com/Sirupsen/logrus"
"io/ioutil"
golog "log"
"net/http"
"os"
"strconv"
"time"

log "github.com/Sirupsen/logrus"
"github.com/akutz/gofig"
"github.com/emccode/rexray/daemon/module"
"github.com/emccode/rexray/util"
"github.com/akutz/gotil"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"

"github.com/emccode/rexray/daemon/module"
)

const (
Expand Down Expand Up @@ -64,20 +65,20 @@ func loadAsset(path, defaultValue string) string {
os.Getenv("GOPATH"),
path)

if util.FileExists(devPath) {
if gotil.FileExists(devPath) {
v, _ := ioutil.ReadFile(devPath)
log.Printf("Loaded %s from %s\n", path, devPath)
return string(v)
}

exeDir, _, _ := util.GetThisPathParts()
exeDir, _, _ := gotil.GetThisPathParts()

relPath := fmt.Sprintf(
"%s/html/%s",
exeDir,
path)

if util.FileExists(relPath) {
if gotil.FileExists(relPath) {
v, _ := ioutil.ReadFile(devPath)
log.Printf("Loaded %s from %s\n", path, relPath)
return string(v)
Expand Down Expand Up @@ -344,7 +345,7 @@ func (m *mod) Start() error {
r.Handle("/",
handlers.LoggingHandler(stdOut, http.HandlerFunc(indexHandler)))

_, addr, parseAddrErr := util.ParseAddress(m.Address())
_, addr, parseAddrErr := gotil.ParseAddress(m.Address())
if parseAddrErr != nil {
return parseAddrErr
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/module/docker/remotevolumedriver/remvoldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"github.com/akutz/gofig"
"github.com/akutz/goof"
"github.com/akutz/gotil"

"github.com/emccode/rexray/core"
"github.com/emccode/rexray/daemon/module"
"github.com/emccode/rexray/util"
)

const (
Expand All @@ -40,7 +40,7 @@ type mod struct {
func init() {
//tcpAddr := fmt.Sprintf("tcp://:%d", ModPort)

_, fsPath, parseAddrErr := util.ParseAddress(modAddress)
_, fsPath, parseAddrErr := gotil.ParseAddress(modAddress)
if parseAddrErr != nil {
panic(parseAddrErr)
}
Expand Down Expand Up @@ -93,7 +93,7 @@ type pluginRequest struct {

func (m *mod) Start() error {

proto, addr, parseAddrErr := util.ParseAddress(m.Address())
proto, addr, parseAddrErr := gotil.ParseAddress(m.Address())
if parseAddrErr != nil {
return parseAddrErr
}
Expand Down
6 changes: 3 additions & 3 deletions daemon/module/docker/volumedriver/voldriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/akutz/gofig"
"github.com/akutz/goof"
"github.com/akutz/gotil"

"github.com/emccode/rexray/core"
"github.com/emccode/rexray/daemon/module"
"github.com/emccode/rexray/util"
)

const (
Expand All @@ -38,7 +38,7 @@ type mod struct {
func init() {
//tcpAddr := fmt.Sprintf("tcp://:%d", ModPort)

_, fsPath, parseAddrErr := util.ParseAddress(modAddress)
_, fsPath, parseAddrErr := gotil.ParseAddress(modAddress)
if parseAddrErr != nil {
panic(parseAddrErr)
}
Expand Down Expand Up @@ -83,7 +83,7 @@ type pluginRequest struct {

func (m *mod) Start() error {

proto, addr, parseAddrErr := util.ParseAddress(m.Address())
proto, addr, parseAddrErr := gotil.ParseAddress(m.Address())
if parseAddrErr != nil {
return parseAddrErr
}
Expand Down
3 changes: 3 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import:
- package: github.com/akutz/goof
ref: master
vcs: git
- package: github.com/akutz/gotil
ref: master
vcs: git
- package: github.com/go-yaml/yaml
ref: b4a9f8c4b84c6c4256d669c649837f1441e4b050
repo: https://github.com/akutz/yaml.git
Expand Down
7 changes: 3 additions & 4 deletions rexray/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (

log "github.com/Sirupsen/logrus"
glog "github.com/akutz/golf/logrus"
"github.com/akutz/gotil"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"gopkg.in/yaml.v1"

"github.com/emccode/rexray/core"
"github.com/emccode/rexray/rexray/cli/term"
"github.com/emccode/rexray/util"

"gopkg.in/yaml.v1"
)

func init() {
Expand Down Expand Up @@ -259,7 +258,7 @@ func (c *CLI) updateLogLevel() {

func (c *CLI) preRun(cmd *cobra.Command, args []string) {

if c.cfgFile != "" && util.FileExists(c.cfgFile) {
if c.cfgFile != "" && gotil.FileExists(c.cfgFile) {
if err := c.r.Config.ReadConfigFile(c.cfgFile); err != nil {
panic(err)
}
Expand Down
11 changes: 5 additions & 6 deletions rexray/cli/cmds_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import (
"net/url"

log "github.com/Sirupsen/logrus"
"github.com/akutz/gotil"
"github.com/spf13/cobra"

"github.com/emccode/rexray/util"
)

func (c *CLI) initModuleCmdsAndFlags() {
Expand All @@ -32,7 +31,7 @@ func (c *CLI) initModuleCmds() {
Short: "List the available module types and their IDs",
Run: func(cmd *cobra.Command, args []string) {

_, addr, addrErr := util.ParseAddress(c.host())
_, addr, addrErr := gotil.ParseAddress(c.host())
if addrErr != nil {
panic(addrErr)
}
Expand Down Expand Up @@ -71,7 +70,7 @@ func (c *CLI) initModuleCmds() {
Short: "List the running module instances",
Run: func(cmd *cobra.Command, args []string) {

_, addr, addrErr := util.ParseAddress(c.host())
_, addr, addrErr := gotil.ParseAddress(c.host())
if addrErr != nil {
panic(addrErr)
}
Expand Down Expand Up @@ -101,7 +100,7 @@ func (c *CLI) initModuleCmds() {
Short: "Create a new module instance",
Run: func(cmd *cobra.Command, args []string) {

_, addr, addrErr := util.ParseAddress(c.host())
_, addr, addrErr := gotil.ParseAddress(c.host())
if addrErr != nil {
panic(addrErr)
}
Expand Down Expand Up @@ -156,7 +155,7 @@ func (c *CLI) initModuleCmds() {
Short: "Starts a module instance",
Run: func(cmd *cobra.Command, args []string) {

_, addr, addrErr := util.ParseAddress(c.host())
_, addr, addrErr := gotil.ParseAddress(c.host())
if addrErr != nil {
panic(addrErr)
}
Expand Down
15 changes: 8 additions & 7 deletions rexray/cli/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"text/template"

log "github.com/Sirupsen/logrus"
"github.com/akutz/gotil"

"github.com/emccode/rexray/util"
)
Expand All @@ -25,7 +26,7 @@ const (
func install() {
checkOpPerms("installed")

_, _, exeFile := util.GetThisPathParts()
_, _, exeFile := gotil.GetThisPathParts()

if runtime.GOOS == "linux" {
switch getInitSystemType() {
Expand All @@ -52,7 +53,7 @@ func isRpmInstall(exePath string, pkgName *string) bool {
return false
}
log.WithField("output", soutput).Debug("rpm install query result")
*pkgName = util.Trim(soutput)
*pkgName = gotil.Trim(soutput)

log.WithFields(log.Fields{
"exePath": exePath,
Expand All @@ -74,7 +75,7 @@ func isDebInstall(exePath string, pkgName *string) bool {
return false
}
log.WithField("output", soutput).Debug("deb install query result")
*pkgName = strings.Split(util.Trim(soutput), ":")[0]
*pkgName = strings.Split(gotil.Trim(soutput), ":")[0]

log.WithFields(log.Fields{
"exePath": exePath,
Expand Down Expand Up @@ -110,7 +111,7 @@ func uninstallDeb(pkgName string) bool {
func uninstall(pkgManager bool) {
checkOpPerms("uninstalled")

_, _, binFile := util.GetThisPathParts()
_, _, binFile := gotil.GetThisPathParts()

// if the uninstall command was executed manually we should check to see
// if this file is owned by a package manager and remove it that way if so
Expand Down Expand Up @@ -164,15 +165,15 @@ func getInitSystemCmd() string {
}

func getInitSystemType() int {
if util.FileExistsInPath("systemctl") {
if gotil.FileExistsInPath("systemctl") {
return SystemD
}

if util.FileExistsInPath("update-rc.d") {
if gotil.FileExistsInPath("update-rc.d") {
return UpdateRcD
}

if util.FileExistsInPath("chkconfig") {
if gotil.FileExistsInPath("chkconfig") {
return ChkConfig
}

Expand Down
13 changes: 7 additions & 6 deletions rexray/cli/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/akutz/goof"
"github.com/akutz/gotil"

rrdaemon "github.com/emccode/rexray/daemon"
"github.com/emccode/rexray/util"
Expand All @@ -23,7 +24,7 @@ func (c *CLI) start() {

pidFile := util.PidFilePath()

if util.FileExists(pidFile) {
if gotil.FileExists(pidFile) {
pid, pidErr := util.ReadPidFile()
if pidErr != nil {
fmt.Printf("Error reading REX-Ray PID file at %s\n", pidFile)
Expand Down Expand Up @@ -139,12 +140,12 @@ func (c *CLI) startDaemon() {
}

func (c *CLI) tryToStartDaemon() {
_, _, thisAbsPath := util.GetThisPathParts()
_, _, thisAbsPath := gotil.GetThisPathParts()

fmt.Print("Starting REX-Ray...")

signal := make(chan byte)
client := fmt.Sprintf("%s/%s.sock", os.TempDir(), util.RandomString(32))
client := fmt.Sprintf("%s/%s.sock", os.TempDir(), gotil.RandomString(32))
log.WithField("client", client).Debug("trying to start service")

l, lErr := net.Listen("unix", client)
Expand Down Expand Up @@ -200,7 +201,7 @@ func (c *CLI) tryToStartDaemon() {
func stop() {
checkOpPerms("stopped")

if !util.FileExists(util.PidFilePath()) {
if !gotil.FileExists(util.PidFilePath()) {
fmt.Println("REX-Ray is already stopped")
panic(1)
}
Expand All @@ -220,7 +221,7 @@ func stop() {
}

func (c *CLI) status() {
if !util.FileExists(util.PidFilePath()) {
if !gotil.FileExists(util.PidFilePath()) {
fmt.Println("REX-Ray is stopped")
return
}
Expand All @@ -231,7 +232,7 @@ func (c *CLI) status() {
func (c *CLI) restart() {
checkOpPerms("restarted")

if util.FileExists(util.PidFilePath()) {
if gotil.FileExists(util.PidFilePath()) {
stop()
}

Expand Down
6 changes: 3 additions & 3 deletions rexray/cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
"text/template"

log "github.com/Sirupsen/logrus"
"github.com/emccode/rexray/util"
"github.com/akutz/gotil"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
)

func (c *CLI) initUsageTemplates() {

var ut string
utPath := fmt.Sprintf("%s/.rexray/usage.template", util.HomeDir())
utPath := fmt.Sprintf("%s/.rexray/usage.template", gotil.HomeDir())
log.WithField("path", utPath).Debug("usage template path")

if util.FileExists(utPath) {
if gotil.FileExists(utPath) {
dat, err := ioutil.ReadFile(utPath)
if err != nil {
panic(err)
Expand Down

0 comments on commit 8919982

Please sign in to comment.