Skip to content

Commit

Permalink
Merge main onto improved-cli-completions
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Aug 29, 2024
2 parents ba1aaed + 4633da9 commit 4ddb7c5
Show file tree
Hide file tree
Showing 47 changed files with 19,539 additions and 2,059 deletions.
117 changes: 99 additions & 18 deletions client/lxd_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ func (r *ProtocolLXD) tryCreateInstance(req api.InstancesPost, urls []string, op
operation := req.Source.Operation

// Forward targetOp to remote op
chConnect := make(chan error, 1)
chWait := make(chan error, 1)

go func() {
success := false
var errors []remoteOperationResult
Expand Down Expand Up @@ -762,13 +765,35 @@ func (r *ProtocolLXD) tryCreateInstance(req api.InstancesPost, urls []string, op
break
}

if !success {
rop.err = remoteOperationError("Failed instance creation", errors)
if success {
chConnect <- nil
close(chConnect)
} else {
chConnect <- remoteOperationError("Failed instance creation", errors)
close(chConnect)

if op != nil {
_ = op.Cancel()
}
}
}()

if op != nil {
go func() {
chWait <- op.Wait()
close(chWait)
}()
}

go func() {
var err error

select {
case err = <-chConnect:
case err = <-chWait:
}

rop.err = err
close(rop.chDone)
}()

Expand Down Expand Up @@ -953,7 +978,12 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,

targetSecrets := map[string]string{}
for k, v := range opAPI.Metadata {
targetSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

targetSecrets[k] = vStr
}

// Prepare the source request
Expand Down Expand Up @@ -981,7 +1011,12 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,

sourceSecrets := map[string]string{}
for k, v := range opAPI.Metadata {
sourceSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

sourceSecrets[k] = vStr
}

// Relay mode migration
Expand All @@ -1001,7 +1036,12 @@ func (r *ProtocolLXD) CopyInstance(source InstanceServer, instance api.Instance,
// Extract the websockets
targetSecrets := map[string]string{}
for k, v := range targetOpAPI.Metadata {
targetSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

targetSecrets[k] = vStr
}

// Launch the relay
Expand Down Expand Up @@ -1243,9 +1283,16 @@ func (r *ProtocolLXD) ExecInstance(instanceName string, exec api.InstanceExecPos

value, ok := opAPI.Metadata["fds"]
if ok {
values := value.(map[string]any)
for k, v := range values {
fds[k] = v.(string)
values, ok := value.(map[string]any)
if ok {
for k, v := range values {
vStr, ok := v.(string)
if !ok {
continue
}

fds[k] = vStr
}
}
}

Expand All @@ -1260,7 +1307,12 @@ func (r *ProtocolLXD) ExecInstance(instanceName string, exec api.InstanceExecPos
outputs, ok := opAPI.Metadata["output"].(map[string]any)
if ok {
for k, v := range outputs {
outputFiles[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

outputFiles[k] = vStr
}
}

Expand Down Expand Up @@ -1992,7 +2044,12 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s

targetSecrets := map[string]string{}
for k, v := range opAPI.Metadata {
targetSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

targetSecrets[k] = vStr
}

// Prepare the source request
Expand Down Expand Up @@ -2020,7 +2077,12 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s

sourceSecrets := map[string]string{}
for k, v := range opAPI.Metadata {
sourceSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

sourceSecrets[k] = vStr
}

// Relay mode migration
Expand All @@ -2040,7 +2102,12 @@ func (r *ProtocolLXD) CopyInstanceSnapshot(source InstanceServer, instanceName s
// Extract the websockets
targetSecrets := map[string]string{}
for k, v := range targetOpAPI.Metadata {
targetSecrets[k] = v.(string)
vStr, ok := v.(string)
if !ok {
continue
}

targetSecrets[k] = vStr
}

// Launch the relay
Expand Down Expand Up @@ -2596,9 +2663,16 @@ func (r *ProtocolLXD) ConsoleInstance(instanceName string, console api.InstanceC

value, ok := opAPI.Metadata["fds"]
if ok {
values := value.(map[string]any)
for k, v := range values {
fds[k] = v.(string)
values, ok := value.(map[string]any)
if ok {
for k, v := range values {
vStr, ok := v.(string)
if !ok {
continue
}

fds[k] = vStr
}
}
}

Expand Down Expand Up @@ -2688,9 +2762,16 @@ func (r *ProtocolLXD) ConsoleInstanceDynamic(instanceName string, console api.In

value, ok := opAPI.Metadata["fds"]
if ok {
values := value.(map[string]any)
for k, v := range values {
fds[k] = v.(string)
values, ok := value.(map[string]any)
if ok {
for k, v := range values {
vStr, ok := v.(string)
if !ok {
continue
}

fds[k] = vStr
}
}
}

Expand Down
1 change: 1 addition & 0 deletions doc/.custom_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ SIGTERM
simplestreams
SKBPRIO
SLAAC
SLES
SMTP
Snapcraft
SoC
Expand Down
2 changes: 2 additions & 0 deletions doc/guest-os-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CentOS | CentOS 9-Stream | Supported | 🟢 [^3] | ✅
Red Hat | RHEL 7.9 | EOL | ❌ [^2] | ✅ | 🟢 | 🟢 | 🟢 | ✅ | ✅
Red Hat | RHEL 8.10 | Supported | 🟢 [^3] | ✅ | 🟢 | 🟢 | 🟢 | ✅ | ✅
Red Hat | RHEL 9.4 | Supported | 🟢 [^3] | ✅ | 🟢 | 🟢 | 🟢 | ✅ | ✅
SUSE | SLES 12 SP5 | Supported | ✅ | ✅ | 🟢 | 🟢 | 🟢 | ✅ | ✅
SUSE | SLES 15 SP6 | Supported | ✅ | ✅ | 🟢 | 🟢 | 🟢 | ✅ | ✅
Windows | Server 2012 | Supported | ➖ | ✅ | 🟢 | ❌ | 🟢 | ✅ | ✅
Windows | Server 2016 | Supported | ➖ | ✅ | 🟢 | 🟢 [^4] | ❌ [^6] | ✅ | ✅
Windows | Server 2019 | Supported | ➖ | ✅ | 🟢 | 🟢 | ❌ [^6] | ✅ | ✅
Expand Down
4 changes: 4 additions & 0 deletions lxc/network_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ func (c *cmdNetworkZoneCreate) command() *cobra.Command {
cmd.Use = usage("create", i18n.G("[<remote>:]<Zone> [key=value...]"))
cmd.Short = i18n.G("Create new network zones")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G("Create new network zones"))
cmd.Example = cli.FormatSection("", i18n.G(`lxc network zone create z1
lxc network zone create z1 < config.yaml
Create network zone z1 with configuration from config.yaml`))

cmd.RunE = c.run

Expand Down
5 changes: 5 additions & 0 deletions lxc/storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (c *cmdStorageBucketCreate) command() *cobra.Command {
cmd.Use = usage("create", i18n.G("[<remote>:]<pool> <bucket> [key=value...]"))
cmd.Short = i18n.G("Create new custom storage buckets")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(`Create new custom storage buckets`))
cmd.Example = cli.FormatSection("", i18n.G(`lxc storage bucket create p1 b01
Create a new storage bucket name b01 in storage pool p1
lxc storage bucket create p1 b01 < config.yaml
Create a new storage bucket name b01 in storage pool p1 using the content of config.yaml`))

cmd.Flags().StringVar(&c.storageBucket.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.RunE = c.run
Expand Down
5 changes: 5 additions & 0 deletions lxd/apparmor/instance_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ profile "{{ .name }}" flags=(attach_disconnected,mediate_deleted) {
### Configuration: unprivileged containers
pivot_root,
# We need to allow all these filesystems because they were allowed
# for years as a result of a https://bugs.launchpad.net/apparmor/+bug/1597017
# Now, when AppArmor is fixed, we start to get complaints that things which
# were working before stopped to work now.
mount fstype=devpts,
mount fstype=proc,
mount fstype=sysfs,
# Allow unlimited modification of mount propagation
mount options=(rw,slave) -> /{,**},
Expand Down
24 changes: 14 additions & 10 deletions lxd/storage_volumes_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/canonical/lxd/lxd/request"
"github.com/canonical/lxd/lxd/response"
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/entity"
Expand Down Expand Up @@ -121,7 +122,7 @@ func storagePoolVolumeTypeStateGet(d *Daemon, r *http.Request) response.Response
if volumeType == cluster.StoragePoolVolumeTypeCustom {
// Custom volumes.
usage, err = pool.GetCustomVolumeUsage(projectName, volumeName)
if err != nil {
if err != nil && err != storageDrivers.ErrNotSupported {
return response.SmartError(err)
}
} else {
Expand All @@ -141,23 +142,26 @@ func storagePoolVolumeTypeStateGet(d *Daemon, r *http.Request) response.Response
}

usage, err = pool.GetInstanceUsage(inst)
if err != nil {
if err != nil && err != storageDrivers.ErrNotSupported {
return response.SmartError(err)
}
}

// Prepare the state struct.
state := api.StorageVolumeState{}
state.Usage = &api.StorageVolumeStateUsage{}

// Only fill 'used' field if receiving a valid value.
if usage.Used >= 0 {
state.Usage.Used = uint64(usage.Used)
}
if usage != nil {
state.Usage = &api.StorageVolumeStateUsage{}

// Only fill 'total' field if receiving a valid value.
if usage.Total >= 0 {
state.Usage.Total = usage.Total
// Only fill 'used' field if receiving a valid value.
if usage.Used >= 0 {
state.Usage.Used = uint64(usage.Used)
}

// Only fill 'total' field if receiving a valid value.
if usage.Total >= 0 {
state.Usage.Total = usage.Total
}
}

return response.SyncResponse(true, state)
Expand Down
Loading

0 comments on commit 4ddb7c5

Please sign in to comment.