Better logging + runVM impl
This commit is contained in:
parent
b905244626
commit
a63030fd00
7 changed files with 192 additions and 74 deletions
|
|
@ -2,7 +2,11 @@ package vm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/AlexSSD7/vldisk/utils"
|
||||
"github.com/alessio/shellescape"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
|
@ -36,12 +40,12 @@ func (fm *FileManager) Init() error {
|
|||
}
|
||||
|
||||
func (fm *FileManager) Lsblk() ([]byte, error) {
|
||||
c, err := fm.vi.DialSSH()
|
||||
sc, err := fm.vi.DialSSH()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "dial vm ssh")
|
||||
}
|
||||
|
||||
sess, err := c.NewSession()
|
||||
sess, err := sc.NewSession()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "create new vm ssh session")
|
||||
}
|
||||
|
|
@ -57,3 +61,42 @@ func (fm *FileManager) Lsblk() ([]byte, error) {
|
|||
|
||||
return ret.Bytes(), nil
|
||||
}
|
||||
|
||||
type MountOptions struct {
|
||||
FSType string
|
||||
}
|
||||
|
||||
func (fm *FileManager) Mount(devName string, mo MountOptions) error {
|
||||
if devName == "" {
|
||||
return fmt.Errorf("device name is empty")
|
||||
}
|
||||
|
||||
// It does allow mapper/ prefix for mapped devices.
|
||||
// This is to enable the support for LVM and LUKS.
|
||||
if !utils.ValidateDevName(devName) {
|
||||
return fmt.Errorf("bad device name")
|
||||
}
|
||||
|
||||
fullDevPath := filepath.Clean("/dev/" + devName)
|
||||
|
||||
if mo.FSType == "" {
|
||||
return fmt.Errorf("fs type is empty")
|
||||
}
|
||||
|
||||
sc, err := fm.vi.DialSSH()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "dial vm ssh")
|
||||
}
|
||||
|
||||
sess, err := sc.NewSession()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "create new vm ssh session")
|
||||
}
|
||||
|
||||
err = sess.Run("mount -t " + shellescape.Quote(mo.FSType) + " " + shellescape.Quote(fullDevPath) + " /mnt")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "run mount cmd")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue