Lots of cleanups, added vnfs package and utilizing config package for constants
This commit is contained in:
@@ -64,6 +64,7 @@ type NodeInfo struct {
|
||||
DomainName string
|
||||
Fqdn string
|
||||
Vnfs string
|
||||
VnfsDir string
|
||||
Ipxe string
|
||||
SystemOverlay string
|
||||
RuntimeOverlay string
|
||||
@@ -139,7 +140,9 @@ func FindAllNodes() ([]NodeInfo, error) {
|
||||
if strings.HasPrefix(n.Vnfs, "docker://") {
|
||||
//TODO: This is a kludge and shouldn't be done here. We need to go back
|
||||
// and do this from a "vnfs" interface or package
|
||||
n.Vnfs = LocalStateDir + "/oci/vnfs/name/" + path.Base(n.Vnfs)
|
||||
n.VnfsDir = LocalStateDir + "/oci/vnfs/name/" + path.Base(n.Vnfs)
|
||||
} else {
|
||||
n.VnfsDir = n.Vnfs
|
||||
}
|
||||
|
||||
ret = append(ret, n)
|
||||
|
||||
@@ -9,19 +9,22 @@ import (
|
||||
|
||||
// THIS IS NOT BEING USED YET AND IS THUS A WORK IN PROGRESS
|
||||
|
||||
const ConfigFile = "/etc/warewulf/warewulf.conf"
|
||||
const SysConfDir = "/etc/warewulf/"
|
||||
const LocalStateDir = "/var/warewulf"
|
||||
|
||||
type Config struct {
|
||||
Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"`
|
||||
Ipaddr string `yaml:"warewulfd ipaddr", envconfig:"WAREWULFD_IPADDR"`
|
||||
InsecureRuntime bool `yaml:"insecure runtime"`
|
||||
Debug bool `yaml:"debug"`
|
||||
Port int `yaml:"warewulfd port", envconfig:"WAREWULFD_PORT"`
|
||||
Ipaddr string `yaml:"warewulfd ipaddr", envconfig:"WAREWULFD_IPADDR"`
|
||||
InsecureRuntime bool `yaml:"insecure runtime"`
|
||||
Debug bool `yaml:"debug"`
|
||||
SysConfDir string `yaml:"system config dir"`
|
||||
LocalStateDir string `yaml:"local state dir"`
|
||||
}
|
||||
|
||||
func New() (Config, error) {
|
||||
var c Config
|
||||
|
||||
fd, err := ioutil.ReadFile(ConfigFile)
|
||||
fd, err := ioutil.ReadFile(SysConfDir + "warewulf.conf")
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
@@ -37,7 +40,14 @@ func New() (Config, error) {
|
||||
}
|
||||
|
||||
if c.Ipaddr == "" {
|
||||
fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in %s\n", ConfigFile)
|
||||
fmt.Printf("ERROR: 'warewulf ipaddr' has not been set in %s\n", SysConfDir+"warewulf.conf")
|
||||
}
|
||||
|
||||
if c.SysConfDir == "" {
|
||||
c.SysConfDir = SysConfDir
|
||||
}
|
||||
if c.LocalStateDir == "" {
|
||||
c.LocalStateDir = LocalStateDir
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
||||
@@ -126,8 +126,8 @@ func (p *puller) pull(ctx context.Context, uri, dst string) (err error) {
|
||||
|
||||
// copy to cache location
|
||||
_, err = copy.Image(ctx, policyCtx, cacheRef, srcRef, ©.Options{
|
||||
ReportWriter: os.Stdout,
|
||||
SourceCtx: p.sysCtx,
|
||||
//ReportWriter: os.Stdout,
|
||||
SourceCtx: p.sysCtx,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
51
internal/pkg/vnfs/vnfs.go
Normal file
51
internal/pkg/vnfs/vnfs.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package vnfs
|
||||
|
||||
import (
|
||||
"github.com/hpcng/warewulf/internal/pkg/config"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type VnfsObject struct {
|
||||
Source string
|
||||
RootPath string
|
||||
ImagePath string
|
||||
}
|
||||
|
||||
func New(s string) VnfsObject {
|
||||
var ret VnfsObject
|
||||
|
||||
ret.Source = s
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (self *VnfsObject) Name() string {
|
||||
if self.Source == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.HasPrefix(self.Source, "/") {
|
||||
return path.Base(self.Source)
|
||||
}
|
||||
|
||||
uri := strings.Split(self.Source, "://")
|
||||
|
||||
return strings.ReplaceAll(uri[0]+":"+uri[1], "/", "_")
|
||||
}
|
||||
|
||||
func (self *VnfsObject) Image() string {
|
||||
if self.Source == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return config.LocalStateDir + "/provision/vnfs/" + self.Name() + ".img.gz"
|
||||
}
|
||||
|
||||
func (self *VnfsObject) Root() string {
|
||||
if self.Source == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return config.LocalStateDir + "/chroots/" + self.Name()
|
||||
}
|
||||
Reference in New Issue
Block a user