feat(climc): add climc command for instance/disk backup

This commit is contained in:
rainzm
2022-01-19 11:31:24 +08:00
parent 0a18af0ed3
commit 56b2e3bed9
5 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import (
"yunion.io/x/onecloud/cmd/climc/shell"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/mcclient/options/compute"
)
func init() {
bsCmd := shell.NewResourceCmd(&modules.BackupStorages)
bsCmd.List(&compute.BackupStorageListOptions{})
bsCmd.Show(&compute.BackupStorageIdOptions{})
bsCmd.Create(&compute.BackupStorageCreateOptions{})
bsCmd.Delete(&compute.BackupStorageIdOptions{})
dbCmd := shell.NewResourceCmd(&modules.DiskBackups)
dbCmd.List(&compute.DiskBackupListOptions{})
dbCmd.Show(&compute.DiskBackupIdOptions{})
dbCmd.Delete(&compute.DiskBackupIdOptions{})
dbCmd.Create(&compute.DiskBackupCreateOptions{})
dbCmd.Perform("recovery", &compute.DiskBackupRecoveryOptions{})
dbCmd.Perform("syncstatus", &compute.DiskBackupSyncstatusOptions{})
ibCmd := shell.NewResourceCmd(&modules.InstanceBackups)
ibCmd.List(&compute.InstanceBackupListOptions{})
ibCmd.Show(&compute.InstanceBackupIdOptions{})
ibCmd.Delete(&compute.InstanceBackupIdOptions{})
ibCmd.Perform("recovery", &compute.InstanceBackupRecoveryOptions{})
}

View File

@@ -731,6 +731,20 @@ func init() {
printObject(result)
return nil
})
type ServerCreateBackup struct {
ID string `help:"ID or name of VM" json:"-"`
BACKUP string `help:"Instance backup name" json:"name"`
BACKUPSTORAGEID string `help:"backup storage id" json:"backup_storage_id"`
}
R(&ServerCreateBackup{}, "instance-backup-create", "create instance backup", func(s *mcclient.ClientSession, opts *ServerCreateBackup) error {
params := jsonutils.Marshal(opts)
result, err := modules.Servers.PerformAction(s, opts.ID, "instance-backup", params)
if err != nil {
return err
}
printObject(result)
return nil
})
type ServerSnapshotAndClone struct {
ID string `help:"ID or name of VM" json:"-"`

View File

@@ -0,0 +1,46 @@
package compute
import "yunion.io/x/onecloud/pkg/apis"
const (
INSTANCE_BACKUP_STATUS_CREATING = "creating"
INSTANCE_BACKUP_STATUS_CREATE_FAILED = "create_failed"
INSTANCE_BACKUP_STATUS_DELETING = "deleting"
INSTANCE_BACKUP_STATUS_DELETE_FAILED = "delete_failed"
INSTANCE_BACKUP_STATUS_RECOVERY = "recovery"
INSTANCE_BACKUP_STATUS_RECOVERY_FAILED = "recovery_failed"
INSTANCE_BACKUP_STATUS_READY = "ready"
)
type InstanceBackupListInput struct {
apis.VirtualResourceListInput
apis.MultiArchResourceBaseListInput
ManagedResourceListInput
ServerFilterListInput
// 操作系统类型
OsType []string `json:"os_type"`
}
type InstanceBackupDetails struct {
apis.VirtualResourceDetails
ManagedResourceInfo
// 云主机状态
GuestStatus string `json:"guest_status"`
// 云主机名称
Guest string `json:"guest"`
// 存储类型
BackupStorageName string `json:"backup_storage_name"`
// 主机快照大小
Size int `json:"size"`
}
type InstanceBackupRecoveryInput struct {
// description: name of guest
Name string
}

View File

@@ -0,0 +1,64 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import (
"yunion.io/x/onecloud/pkg/mcclient/modulebase"
"yunion.io/x/onecloud/pkg/mcclient/modules"
)
type DiskBackupManager struct {
modulebase.ResourceManager
}
type BackupStorageManager struct {
modulebase.ResourceManager
}
type InstanceBackupManager struct {
modulebase.ResourceManager
}
var (
DiskBackups DiskBackupManager
BackupStorages BackupStorageManager
InstanceBackups InstanceBackupManager
)
func init() {
DiskBackups = DiskBackupManager{modules.NewComputeManager(
"diskbackup",
"diskbackups",
[]string{},
[]string{},
)}
modules.RegisterCompute(&DiskBackups)
BackupStorages = BackupStorageManager{modules.NewComputeManager(
"backupstorage",
"backupstorages",
[]string{},
[]string{},
)}
modules.RegisterCompute(&BackupStorages)
InstanceBackups = InstanceBackupManager{modules.NewComputeManager(
"instancebackup",
"instancebackups",
[]string{},
[]string{},
)}
modules.RegisterCompute(&InstanceBackups)
}

View File

@@ -0,0 +1,146 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package compute
import (
"yunion.io/x/jsonutils"
"yunion.io/x/onecloud/pkg/mcclient/options"
)
type DiskBackupListOptions struct {
options.BaseListOptions
DiskId string `help:"disk id" json:"disk_id"`
BackupStorageId string `help:"backup storage id" json:"backup_storage_id"`
IsInstanceBackup *bool `help:"if part of instance backup" json:"is_instance_backup"`
}
func (opts *DiskBackupListOptions) Params() (jsonutils.JSONObject, error) {
return options.ListStructToParams(opts)
}
type DiskBackupIdOptions struct {
ID string `help:"disk backup id" json:"-"`
}
func (opts *DiskBackupIdOptions) GetId() string {
return opts.ID
}
func (opts *DiskBackupIdOptions) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type DiskBackupCreateOptions struct {
options.BaseCreateOptions
DISKID string `help:"disk id" json:"disk_id"`
BACKUPSTORAGEID string `help:"back storage id" json:"backup_storage_id"`
}
func (opts *DiskBackupCreateOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
type DiskBackupRecoveryOptions struct {
DiskBackupIdOptions
Name string `help:"disk name" json:"name"`
}
func (opt *DiskBackupRecoveryOptions) GetId() string {
return opt.ID
}
func (opt *DiskBackupRecoveryOptions) Params() (jsonutils.JSONObject, error) {
params := jsonutils.NewDict()
params.Set("name", jsonutils.NewString(opt.Name))
return params, nil
}
type DiskBackupSyncstatusOptions struct {
DiskBackupIdOptions
}
func (opt *DiskBackupSyncstatusOptions) GetId() string {
return opt.ID
}
func (opt *DiskBackupSyncstatusOptions) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type BackupStorageListOptions struct {
options.BaseListOptions
}
func (opts *BackupStorageListOptions) Params() (jsonutils.JSONObject, error) {
return options.ListStructToParams(opts)
}
type BackupStorageIdOptions struct {
ID string `help:"backup storage id"`
}
func (opts *BackupStorageIdOptions) GetId() string {
return opts.ID
}
func (opts *BackupStorageIdOptions) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type BackupStorageCreateOptions struct {
options.BaseCreateOptions
StorageType string `help:"storage type" choices:"nfs"`
NfsHost string `help:"nfs host, required when storage_type is nfs"`
NfsSharedDir string `help:"nfs shared dir, required when storage_type is nfs" `
CapacityMb int `help:"capacity, unit mb"`
}
func (opts *BackupStorageCreateOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}
type InstanceBackupListOptions struct {
options.BaseListOptions
}
func (opts *InstanceBackupListOptions) Params() (jsonutils.JSONObject, error) {
return options.ListStructToParams(opts)
}
type InstanceBackupIdOptions struct {
ID string `help:"instance backup id"`
}
func (opts *InstanceBackupIdOptions) GetId() string {
return opts.ID
}
func (opts *InstanceBackupIdOptions) Params() (jsonutils.JSONObject, error) {
return nil, nil
}
type InstanceBackupRecoveryOptions struct {
DiskBackupIdOptions
Name string `help:"server name" json:"name"`
}
func (opts *InstanceBackupRecoveryOptions) GetId() string {
return opts.ID
}
func (opts *InstanceBackupRecoveryOptions) Params() (jsonutils.JSONObject, error) {
return jsonutils.Marshal(opts), nil
}