-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add local attach support * use os.Mode* for backwards compatability * fix incorrect driver naming for attach local * fix some incorrect pointer references in log messages * log message tweaks for attach-local
- Loading branch information
1 parent
f8c1504
commit b73b9e9
Showing
9 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package api | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/kraken-hpc/imageapi/models" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func init() { | ||
AttachDrivers[models.AttachKindLocal] = &AttachDriverLocal{} | ||
} | ||
|
||
type AttachDriverLocal struct { | ||
log *logrus.Entry | ||
} | ||
|
||
func (a *AttachDriverLocal) Init(log *logrus.Entry) { | ||
a.log = log | ||
a.log.Trace("initialized") | ||
} | ||
|
||
func (a *AttachDriverLocal) Attach(att *Attach) (ret *Attach, err error) { | ||
// sanity check | ||
l := a.log.WithField("operation", "attach") | ||
if att.Local == nil { | ||
l.Trace("attempted to attach local with no local definition") | ||
return nil, ERRINVALDAT | ||
} | ||
l = l.WithField("path", *att.Local.Path) | ||
|
||
finfo, err := os.Stat(*att.Local.Path) | ||
if err != nil { | ||
l.WithError(err).Debug("failed to stat device file") | ||
return nil, ERRFAIL | ||
} | ||
|
||
if finfo.Mode()&os.ModeDevice == 0 { | ||
l.Trace("path is not a device file") | ||
return nil, ERRINVALDAT | ||
} | ||
|
||
if finfo.Mode()&os.ModeCharDevice != 0 { | ||
l.Trace("path points to character device") | ||
return nil, ERRINVALDAT | ||
} | ||
att.DeviceFile = *att.Local.Path | ||
|
||
l.Info("successfully attached") | ||
return att, nil | ||
} | ||
|
||
func (a *AttachDriverLocal) Detach(att *Attach) (ret *Attach, err error) { | ||
// this is a dummy operation | ||
l := a.log.WithFields(logrus.Fields{ | ||
"operation": "detach", | ||
"id": att.ID, | ||
"path": *att.Local.Path, | ||
}) | ||
l.Info("successfully detached") | ||
return att, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters