Refactor to add oci and util packages
Signed-off-by: Mrunal Patel <mrunalp@gmail.com> Change the sandbox directory path Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
839463d837
commit
ac1340488d
7 changed files with 101 additions and 76 deletions
60
oci/oci.go
Normal file
60
oci/oci.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package oci
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/mrunalp/ocid/utils"
|
||||
)
|
||||
|
||||
// New creates a new Runtime with options provided
|
||||
func New(runtimePath string, sandboxDir string) (*Runtime, error) {
|
||||
r := &Runtime{
|
||||
name: filepath.Base(runtimePath),
|
||||
path: runtimePath,
|
||||
sandboxDir: sandboxDir,
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
type Runtime struct {
|
||||
name string
|
||||
path string
|
||||
sandboxDir string
|
||||
containerDir string
|
||||
}
|
||||
|
||||
// Name returns the name of the OCI Runtime
|
||||
func (r *Runtime) Name() string {
|
||||
return r.name
|
||||
}
|
||||
|
||||
// Path returns the full path the OCI Runtime executable
|
||||
func (r *Runtime) Path() string {
|
||||
return r.path
|
||||
}
|
||||
|
||||
// SandboxDir returns the path to the base directory for storing sandbox configurations
|
||||
func (r *Runtime) SandboxDir() string {
|
||||
return r.sandboxDir
|
||||
}
|
||||
|
||||
// Version returns the version of the OCI Runtime
|
||||
func (r *Runtime) Version() (string, error) {
|
||||
runtimeVersion, err := getOCIVersion(r.path, "-v")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return runtimeVersion, nil
|
||||
}
|
||||
|
||||
func getOCIVersion(name string, args ...string) (string, error) {
|
||||
out, err := utils.ExecCmd(name, args...)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
firstLine := out[:strings.Index(out, "\n")]
|
||||
v := firstLine[strings.LastIndex(firstLine, " ")+1:]
|
||||
return v, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue