remove some dead code
This commit is contained in:
parent
fec402c2f8
commit
716d8b8293
|
@ -229,7 +229,7 @@ func (client *CloudstackClient) getZoneId() (string, error) {
|
|||
data := &responseWrapper.Response
|
||||
checkErrorInfo(&data.ErrorInfo)
|
||||
if data.Count != 1 {
|
||||
return "", errors.New(fmt.Sprintf("Expected 1 zone for '%s'; got %d", zoneName, data.Count))
|
||||
return "", fmt.Errorf("Expected 1 zone for '%s'; got %d", zoneName, data.Count)
|
||||
}
|
||||
zoneId := data.Zone[0].Id
|
||||
client.cachedZoneId = zoneId
|
||||
|
@ -261,7 +261,7 @@ func (client *CloudstackClient) getServiceOfferingId() (string, error) {
|
|||
data := &responseWrapper.Response
|
||||
checkErrorInfo(&data.ErrorInfo)
|
||||
if data.Count != 1 {
|
||||
return "", errors.New(fmt.Sprintf("Expected 1 service offering for '%s'; got %d", serviceOfferingName, data.Count))
|
||||
return "", fmt.Errorf("Expected 1 service offering for '%s'; got %d", serviceOfferingName, data.Count)
|
||||
}
|
||||
serviceOfferingId := data.ServiceOffering[0].Id
|
||||
client.cachedServiceOfferingId = serviceOfferingId
|
||||
|
@ -294,7 +294,7 @@ func (client *CloudstackClient) GetOsTypeId(osDescription string) (string, error
|
|||
data := &responseWrapper.Response
|
||||
checkErrorInfo(&data.ErrorInfo)
|
||||
if data.Count != 1 {
|
||||
return "", errors.New(fmt.Sprintf("Expected 1 OS type for '%s'; got %d", osDescription, data.Count))
|
||||
return "", fmt.Errorf("Expected 1 OS type for '%s'; got %d", osDescription, data.Count)
|
||||
}
|
||||
return data.OsType[0].Id, nil
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ func (mgr *AlmaLinuxTemplateManager) CommandToUpdatePackageCache() []string {
|
|||
}
|
||||
|
||||
var almaLinuxYumRepoBaseUrlPattern *regexp.Regexp = regexp.MustCompile(
|
||||
"^(?P<scheme>https?://)[A-Za-z0-9./-]+(?P<path>/almalinux/\\$releasever/[A-Za-z0-9./$-]+)$",
|
||||
`^(?P<scheme>https?://)[A-Za-z0-9./-]+(?P<path>/almalinux/\$releasever/[A-Za-z0-9./$-]+)$`,
|
||||
)
|
||||
|
||||
func (mgr *AlmaLinuxTemplateManager) transformAlmaLinuxYumRepoBaseUrl(url string) string {
|
||||
|
|
|
@ -35,7 +35,7 @@ func NewDebianTemplateManager(cfg *config.Config) *DebianTemplateManager {
|
|||
|
||||
func (mgr *DebianTemplateManager) GetLatestVersion() (version string, codename string, err error) {
|
||||
// We're only interested in the major version (integer part)
|
||||
versionPattern := regexp.MustCompile("^Version: (\\d+)(?:\\.\\d)?$")
|
||||
versionPattern := regexp.MustCompile(`^Version: (\d+)(?:\.\d+)?$`)
|
||||
codenamePattern := regexp.MustCompile("^Codename: ([a-z-]+)$")
|
||||
resp, err := http.Get("https://mirror.csclub.uwaterloo.ca/debian/dists/stable/InRelease")
|
||||
if err != nil {
|
||||
|
|
|
@ -33,7 +33,7 @@ func NewFedoraTemplateManager(cfg *config.Config) *FedoraTemplateManager {
|
|||
return &fedoraTemplateManager
|
||||
}
|
||||
|
||||
var numberSlashPattern *regexp.Regexp = regexp.MustCompile("^\\d+/$")
|
||||
var numberSlashPattern *regexp.Regexp = regexp.MustCompile(`^\d+/$`)
|
||||
|
||||
func isHyperlink(node *html.Node) bool {
|
||||
return node.Type == html.ElementNode && node.Data == "a" &&
|
||||
|
|
|
@ -7,9 +7,7 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"libguestfs.org/guestfs"
|
||||
|
@ -28,14 +26,6 @@ func getResource(filename string) []byte {
|
|||
return data
|
||||
}
|
||||
|
||||
func getTemplateResource(filename string) *template.Template {
|
||||
tmpl, err := template.ParseFS(res, "resources/"+filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tmpl
|
||||
}
|
||||
|
||||
// A TemplateManager downloads and modifies VM templates for a distro.
|
||||
type TemplateManager struct {
|
||||
cfg *config.Config
|
||||
|
@ -184,7 +174,7 @@ func (mgr *TemplateManager) getGuestfsMountedHandle(filename string) (handle *gu
|
|||
return
|
||||
}
|
||||
if len(partitions) != 1 {
|
||||
return nil, errors.New(fmt.Sprintf("Expected 1 root partition, found %d", len(partitions)))
|
||||
return nil, fmt.Errorf("Expected 1 root partition, found %d", len(partitions))
|
||||
}
|
||||
rootPartition := partitions[0]
|
||||
log.Debug().Msg(fmt.Sprintf("Mounting root filesystem %s on /", rootPartition))
|
||||
|
@ -215,7 +205,7 @@ func getSelinuxType(handle *guestfs.Guestfs) (selinuxType string, err error) {
|
|||
return
|
||||
}
|
||||
if len(lines) != 1 {
|
||||
err = errors.New(fmt.Sprintf("Expected 1 line containing SELINUXTYPE, found %d", len(lines)))
|
||||
err = fmt.Errorf("Expected 1 line containing SELINUXTYPE, found %d", len(lines))
|
||||
return
|
||||
}
|
||||
selinuxType = strings.Split(lines[0], "=")[1]
|
||||
|
@ -252,28 +242,6 @@ func (mgr *TemplateManager) selinuxRelabelDirectories(handle *guestfs.Guestfs) (
|
|||
return
|
||||
}
|
||||
|
||||
func (mgr *TemplateManager) maskSystemdUnit(handle *guestfs.Guestfs, unit string) error {
|
||||
mgr.logger.Debug().Msg("Masking systemd unit " + unit)
|
||||
return handle.Ln_sf("/dev/null", "/etc/systemd/system/"+unit)
|
||||
}
|
||||
|
||||
func isSameFile(handle *guestfs.Guestfs, path1, path2 string) (bool, error) {
|
||||
if path1 == path2 {
|
||||
return true, nil
|
||||
}
|
||||
stat1, err := handle.Stat(path1)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Could not stat %s: %w", path1, err)
|
||||
}
|
||||
stat2, err := handle.Stat(path2)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Could not stat %s: %w", path2, err)
|
||||
}
|
||||
return stat1.Ino == stat2.Ino, nil
|
||||
}
|
||||
|
||||
var systemdDirPrefixes = []string{"/etc", "/lib"}
|
||||
|
||||
func (mgr *TemplateManager) logAndRunCommand(handle *guestfs.Guestfs, args []string) (string, error) {
|
||||
mgr.logger.Debug().Msg("Running command `" + strings.Join(args, " ") + "`")
|
||||
return handle.Command(args)
|
||||
|
@ -604,37 +572,6 @@ func (mgr *TemplateManager) setDhclientOptions(handle *guestfs.Guestfs) (err err
|
|||
return
|
||||
}
|
||||
|
||||
func getNamedRegexGroup(re *regexp.Regexp, submatches []string, groupName string) string {
|
||||
var value string
|
||||
for i, subexpName := range re.SubexpNames() {
|
||||
if subexpName == groupName {
|
||||
value = submatches[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if value == "" {
|
||||
panic("Could not find regex group " + groupName)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func getNumAugeasComments(handle *guestfs.Guestfs, parentNode string) (numComments int, err error) {
|
||||
keyPaths, err := handle.Aug_ls(parentNode)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("aug_ls(%s) failed: %w", parentNode, err)
|
||||
}
|
||||
for _, keyPath := range keyPaths {
|
||||
key, err := handle.Aug_label(keyPath)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("aug_label(%s) failed: %w", keyPath, err)
|
||||
}
|
||||
if strings.HasPrefix(key, "#comment") {
|
||||
numComments += 1
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAugeasComment(
|
||||
handle *guestfs.Guestfs, numExistingComments int, parentNode string, comment string,
|
||||
) error {
|
||||
|
|
Loading…
Reference in New Issue