Skip to content

Commit

Permalink
Merge pull request #12740 from tomponline/tp-client-apache-2.0
Browse files Browse the repository at this point in the history
Removes AGPL imports from shared package
  • Loading branch information
tomponline authored Jan 18, 2024
2 parents a244911 + 51267fc commit 3f8e4f7
Show file tree
Hide file tree
Showing 144 changed files with 267 additions and 252 deletions.
15 changes: 9 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ update-schema:
.PHONY: update-api
update-api:
ifeq "$(LXD_OFFLINE)" ""
(cd / ; go install -v -x github.com/go-swagger/go-swagger/cmd/swagger@latest)
(cd / ; go install github.com/go-swagger/go-swagger/cmd/swagger@latest)
endif
swagger generate spec -o doc/rest-api.yaml -w ./lxd -m

Expand Down Expand Up @@ -213,9 +213,9 @@ endif
.PHONY: check
check: default
ifeq "$(LXD_OFFLINE)" ""
(cd / ; go install -v -x github.com/rogpeppe/godeps@latest)
(cd / ; go install -v -x github.com/tsenart/deadcode@latest)
(cd / ; go install -v -x golang.org/x/lint/golint@latest)
(cd / ; go install github.com/rogpeppe/godeps@latest)
(cd / ; go install github.com/tsenart/deadcode@latest)
(cd / ; go install golang.org/x/lint/golint@latest)
endif
CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" go test -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./...
cd test && ./main.sh
Expand Down Expand Up @@ -268,7 +268,7 @@ update-po:
.PHONY: update-pot
update-pot:
ifeq "$(LXD_OFFLINE)" ""
(cd / ; go install -v -x github.com/snapcore/snapd/i18n/[email protected])
(cd / ; go install github.com/snapcore/snapd/i18n/[email protected])
endif
xgettext-go -o po/$(DOMAIN).pot --add-comments-tag=TRANSLATORS: --sort-output --package-name=$(DOMAIN) [email protected] --keyword=i18n.G --keyword-plural=i18n.NG lxc/*.go lxc/*/*.go

Expand All @@ -277,6 +277,9 @@ build-mo: $(MOFILES)

.PHONY: static-analysis
static-analysis:
ifeq ($(shell command -v go-licenses),)
(cd / ; go install github.com/google/go-licenses@latest)
endif
ifeq ($(shell command -v golangci-lint),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin
endif
Expand All @@ -300,7 +303,7 @@ endif
.PHONY: staticcheck
staticcheck:
ifeq ($(shell command -v staticcheck),)
(cd / ; go install -v -x honnef.co/go/tools/cmd/staticcheck@latest)
(cd / ; go install honnef.co/go/tools/cmd/staticcheck@latest)
endif
# To get advance notice of deprecated function usage, consider running:
# sed -i 's/^go 1\.[0-9]\+$/go 1.18/' go.mod
Expand Down
2 changes: 1 addition & 1 deletion fuidshift/main_shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cobra"

"github.com/canonical/lxd/shared/idmap"
"github.com/canonical/lxd/lxd/idmap"
)

type cmdShift struct {
Expand Down
2 changes: 1 addition & 1 deletion lxc-to-lxd/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/google/uuid"
"github.com/gorilla/websocket"

"github.com/canonical/lxd/lxd/linux"
"github.com/canonical/lxd/lxd/migration"
"github.com/canonical/lxd/lxd/rsync"
"github.com/canonical/lxd/shared/linux"
"github.com/canonical/lxd/shared/ws"
)

Expand Down
15 changes: 8 additions & 7 deletions lxc/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxc/config"
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
Expand Down Expand Up @@ -204,7 +205,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
entry.Ephemeral = false
}

rootDiskDeviceKey, _, _ := shared.GetRootDiskDevice(entry.Devices)
rootDiskDeviceKey, _, _ := instancetype.GetRootDiskDevice(entry.Devices)
if err != nil {
return err
}
Expand All @@ -225,7 +226,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR

if !keepVolatile {
for k := range entry.Config {
if !shared.InstanceIncludeWhenCopying(k, true) {
if !instancetype.InstanceIncludeWhenCopying(k, true) {
delete(entry.Config, k)
}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
entry.Ephemeral = false
}

rootDiskDeviceKey, _, _ := shared.GetRootDiskDevice(entry.Devices)
rootDiskDeviceKey, _, _ := instancetype.GetRootDiskDevice(entry.Devices)
if rootDiskDeviceKey != "" && pool != "" {
entry.Devices[rootDiskDeviceKey]["pool"] = pool
} else if pool != "" {
Expand All @@ -309,7 +310,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
// Strip the volatile keys if requested
if !keepVolatile {
for k := range entry.Config {
if !shared.InstanceIncludeWhenCopying(k, true) {
if !instancetype.InstanceIncludeWhenCopying(k, true) {
delete(entry.Config, k)
}
}
Expand Down Expand Up @@ -366,8 +367,8 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
}

// Ensure we don't change the target's root disk pool.
srcRootDiskDeviceKey, _, _ := shared.GetRootDiskDevice(writable.Devices)
destRootDiskDeviceKey, destRootDiskDevice, _ := shared.GetRootDiskDevice(inst.Devices)
srcRootDiskDeviceKey, _, _ := instancetype.GetRootDiskDevice(writable.Devices)
destRootDiskDeviceKey, destRootDiskDevice, _ := instancetype.GetRootDiskDevice(inst.Devices)
if srcRootDiskDeviceKey != "" && srcRootDiskDeviceKey == destRootDiskDeviceKey {
writable.Devices[destRootDiskDeviceKey]["pool"] = destRootDiskDevice["pool"]
}
Expand Down Expand Up @@ -402,7 +403,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR
// Start the instance if needed
if start {
req := api.InstanceStatePut{
Action: string(shared.Start),
Action: string(instancetype.Start),
}

op, err := dest.UpdateInstanceState(destName, req, "")
Expand Down
4 changes: 2 additions & 2 deletions lxc/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) {

k := cc[0]
if colType == configColumnType {
_, err := shared.ConfigKeyChecker(k, instancetype.Any)
_, err := instancetype.ConfigKeyChecker(k, instancetype.Any)
if err != nil {
return nil, false, fmt.Errorf(i18n.G("Invalid config key '%s' in '%s'"), k, columnEntry)
}
Expand Down Expand Up @@ -848,7 +848,7 @@ func (c *cmdList) cpuUsageSecondsColumnData(cInfo api.InstanceFull) string {
}

func (c *cmdList) diskUsageColumnData(cInfo api.InstanceFull) string {
rootDisk, _, _ := shared.GetRootDiskDevice(cInfo.ExpandedDevices)
rootDisk, _, _ := instancetype.GetRootDiskDevice(cInfo.ExpandedDevices)

if cInfo.State != nil && cInfo.State.Disk != nil && cInfo.State.Disk[rootDisk].Usage > 0 {
return units.GetByteSizeStringIEC(cInfo.State.Disk[rootDisk].Usage, 2)
Expand Down
13 changes: 7 additions & 6 deletions lxc/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"testing"

"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
)
Expand Down Expand Up @@ -157,22 +158,22 @@ const shorthand = "46abcdDefFlmMnNpPsStuL"
const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

func TestColumns(t *testing.T) {
keys := make([]string, 0, len(shared.InstanceConfigKeysAny)+len(shared.InstanceConfigKeysContainer)+len(shared.InstanceConfigKeysVM))
for k := range shared.InstanceConfigKeysAny {
keys := make([]string, 0, len(instancetype.InstanceConfigKeysAny)+len(instancetype.InstanceConfigKeysContainer)+len(instancetype.InstanceConfigKeysVM))
for k := range instancetype.InstanceConfigKeysAny {
keys = append(keys, k)

// Test compatibility with 'config:' prefix.
keys = append(keys, "config:"+k)
}

for k := range shared.InstanceConfigKeysContainer {
for k := range instancetype.InstanceConfigKeysContainer {
keys = append(keys, k)

// Test compatibility with 'config:' prefix.
keys = append(keys, "config:"+k)
}

for k := range shared.InstanceConfigKeysVM {
for k := range instancetype.InstanceConfigKeysVM {
keys = append(keys, k)

// Test compatibility with 'config:' prefix.
Expand Down Expand Up @@ -215,11 +216,11 @@ func TestColumns(t *testing.T) {
randString(buffer)
case 3:
if rand.Intn(2) == 0 {
buffer.WriteString(shared.ConfigVolatilePrefix)
buffer.WriteString(instancetype.ConfigVolatilePrefix)
randString(buffer)
buffer.WriteString(".hwaddr")
} else {
buffer.WriteString(shared.ConfigVolatilePrefix)
buffer.WriteString(instancetype.ConfigVolatilePrefix)
randString(buffer)
buffer.WriteString(".name")
}
Expand Down
5 changes: 3 additions & 2 deletions lxc/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (c *cmdPublish) Run(cmd *cobra.Command, args []string) error {

// Stop the instance.
req := api.InstanceStatePut{
Action: string(shared.Stop),
Action: string(instancetype.Stop),
Timeout: -1,
Force: true,
}
Expand All @@ -143,7 +144,7 @@ func (c *cmdPublish) Run(cmd *cobra.Command, args []string) error {

// Start the instance back up on exit.
defer func() {
req.Action = string(shared.Start)
req.Action = string(instancetype.Start)
op, err = s.UpdateInstanceState(cName, req, "")
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion lxd-agent/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

deviceConfig "github.com/canonical/lxd/lxd/device/config"
"github.com/canonical/lxd/lxd/ip"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/revert"
)

// A variation of the standard tls.Listener that supports atomically swapping
Expand Down
2 changes: 1 addition & 1 deletion lxd-migrate/main_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"gopkg.in/yaml.v2"

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
cli "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/lxd/shared/osarch"
"github.com/canonical/lxd/shared/revert"
"github.com/canonical/lxd/shared/units"
"github.com/canonical/lxd/shared/version"
)
Expand Down
2 changes: 1 addition & 1 deletion lxd-migrate/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/google/uuid"
"github.com/gorilla/websocket"

"github.com/canonical/lxd/lxd/linux"
"github.com/canonical/lxd/lxd/migration"
"github.com/canonical/lxd/lxd/rsync"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/linux"
"github.com/canonical/lxd/shared/ws"
)

Expand Down
2 changes: 1 addition & 1 deletion lxd-user/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"strings"

"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/revert"
)

func lxdIsConfigured(client lxd.InstanceServer) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion lxd/api_1.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import (
"github.com/canonical/lxd/lxd/node"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/lxd/revert"
scriptletLoad "github.com/canonical/lxd/lxd/scriptlet/load"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/osarch"
"github.com/canonical/lxd/shared/revert"
"github.com/canonical/lxd/shared/version"
)

Expand Down
7 changes: 4 additions & 3 deletions lxd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import (
"github.com/canonical/lxd/lxd/db/warningtype"
"github.com/canonical/lxd/lxd/instance"
instanceDrivers "github.com/canonical/lxd/lxd/instance/drivers"
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/lxd/lifecycle"
"github.com/canonical/lxd/lxd/node"
"github.com/canonical/lxd/lxd/operations"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/lxd/scriptlet"
"github.com/canonical/lxd/lxd/state"
storagePools "github.com/canonical/lxd/lxd/storage"
Expand All @@ -47,6 +47,7 @@ import (
apiScriptlet "github.com/canonical/lxd/shared/api/scriptlet"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/osarch"
"github.com/canonical/lxd/shared/revert"
"github.com/canonical/lxd/shared/validate"
"github.com/canonical/lxd/shared/version"
)
Expand Down Expand Up @@ -245,7 +246,7 @@ func clusterGetMemberConfig(cluster *db.Cluster) ([]api.ClusterMemberConfigKey,

for pool, config := range pools {
for key := range config {
if strings.HasPrefix(key, shared.ConfigVolatilePrefix) {
if strings.HasPrefix(key, instancetype.ConfigVolatilePrefix) {
continue
}

Expand All @@ -262,7 +263,7 @@ func clusterGetMemberConfig(cluster *db.Cluster) ([]api.ClusterMemberConfigKey,

for network, config := range networks {
for key := range config {
if strings.HasPrefix(key, shared.ConfigVolatilePrefix) {
if strings.HasPrefix(key, instancetype.ConfigVolatilePrefix) {
continue
}

Expand Down
8 changes: 4 additions & 4 deletions lxd/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import (
"github.com/canonical/lxd/lxd/project"
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/lxd/state"
storagePools "github.com/canonical/lxd/lxd/storage"
storageDrivers "github.com/canonical/lxd/lxd/storage/drivers"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/osarch"
"github.com/canonical/lxd/shared/revert"
"github.com/canonical/lxd/shared/units"
)

Expand Down Expand Up @@ -909,19 +909,19 @@ func internalImportFromBackup(s *state.State, projectName string, instName strin
// device will be added, if the root disk config in the current profiles matches the effective backup.yaml config.
func internalImportRootDevicePopulate(instancePoolName string, localDevices map[string]map[string]string, expandedDevices map[string]map[string]string, profiles []api.Profile) {
// First, check if localDevices from backup.yaml has a root disk.
rootName, _, _ := shared.GetRootDiskDevice(localDevices)
rootName, _, _ := instancetype.GetRootDiskDevice(localDevices)
if rootName != "" {
localDevices[rootName]["pool"] = instancePoolName

return // Local root disk device has been set to target pool.
}

// Next check if expandedDevices from backup.yaml has a root disk.
expandedRootName, expandedRootConfig, _ := shared.GetRootDiskDevice(expandedDevices)
expandedRootName, expandedRootConfig, _ := instancetype.GetRootDiskDevice(expandedDevices)

// Extract root disk from expanded profile devices.
profileExpandedDevices := db.ExpandInstanceDevices(deviceConfig.NewDevices(localDevices), profiles)
profileExpandedRootName, profileExpandedRootConfig, _ := shared.GetRootDiskDevice(profileExpandedDevices.CloneNative())
profileExpandedRootName, profileExpandedRootConfig, _ := instancetype.GetRootDiskDevice(profileExpandedDevices.CloneNative())

// Record whether we need to add a new local disk device.
addLocalDisk := false
Expand Down
4 changes: 2 additions & 2 deletions lxd/api_internal_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
"github.com/canonical/lxd/lxd/instance/instancetype"
"github.com/canonical/lxd/lxd/project"
"github.com/canonical/lxd/lxd/response"
"github.com/canonical/lxd/lxd/revert"
"github.com/canonical/lxd/lxd/state"
storagePools "github.com/canonical/lxd/lxd/storage"
storageDrivers "github.com/canonical/lxd/lxd/storage/drivers"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/lxd/shared/osarch"
"github.com/canonical/lxd/shared/revert"
)

// Define API endpoints for recover actions.
Expand Down Expand Up @@ -477,7 +477,7 @@ func internalRecoverScan(s *state.State, userPools []api.StoragePoolsPost, valid

// Reinitialise the instance's root disk quota even if no size specified (allows the storage driver the
// opportunity to reinitialise the quota based on the new storage volume's DB ID).
_, rootConfig, err := shared.GetRootDiskDevice(inst.ExpandedDevices().CloneNative())
_, rootConfig, err := instancetype.GetRootDiskDevice(inst.ExpandedDevices().CloneNative())
if err == nil {
err = pool.SetInstanceQuota(inst, rootConfig["size"], rootConfig["size.state"], nil)
if err != nil {
Expand Down
Loading

0 comments on commit 3f8e4f7

Please sign in to comment.