| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- // 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 (
- "os"
- "yunion.io/x/jsonutils"
- "yunion.io/x/pkg/errors"
- computeapi "yunion.io/x/onecloud/pkg/apis/compute"
- "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"`
- OrderByDiskName string
- }
- 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 DiskBackupDeleteOptions struct {
- DiskBackupIdOptions
- Force bool `help:"force delete"`
- }
- func (opts *DiskBackupDeleteOptions) QueryParams() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), nil
- }
- type DiskBackupCreateOptions struct {
- options.BaseCreateOptions
- AsTarContainerId string `help:"container id of tar process"`
- AsTarIncludeFile []string `help:"include file path of tar process"`
- AsTarIncludePattern []string `help:"include pattern of tar process"`
- AsTarExcludeFile []string `help:"exclude file path of tar process"`
- AsTarIgnoreNotExistFile bool `help:"ignore not exist file when using tar"`
- 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) {
- input := &computeapi.DiskBackupCreateInput{
- DiskId: opts.DISKID,
- BackupStorageId: opts.BACKUPSTORAGEID,
- BackupAsTar: new(computeapi.DiskBackupAsTarInput),
- }
- input.Name = opts.NAME
- input.Description = opts.Desc
- if opts.AsTarContainerId != "" {
- input.BackupAsTar.ContainerId = opts.AsTarContainerId
- }
- if len(opts.AsTarIncludeFile) > 0 {
- input.BackupAsTar.IncludeFiles = opts.AsTarIncludeFile
- }
- if len(opts.AsTarIncludePattern) > 0 {
- input.BackupAsTar.IncludePatterns = opts.AsTarIncludePattern
- }
- if len(opts.AsTarExcludeFile) > 0 {
- input.BackupAsTar.ExcludeFiles = opts.AsTarExcludeFile
- }
- if opts.AsTarIgnoreNotExistFile {
- input.BackupAsTar.IgnoreNotExistFile = opts.AsTarIgnoreNotExistFile
- }
- return jsonutils.Marshal(input), 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|object"`
- NfsHost string `help:"nfs host, required when storage_type is nfs"`
- NfsSharedDir string `help:"nfs shared dir, required when storage_type is nfs" `
- ObjectBucketUrl string `help:"object bucket url, required when storage_type is object"`
- ObjectAccessKey string `help:"object storage access key, required when storage_type is object"`
- ObjectSecret string `help:"object storage secret, required when storage_type is object"`
- ObjectSignVer string `help:"object storage signing alogirithm version, optional" choices:"v2|v4"`
- ObjectBucketUrlExt string `help:"object storage external access url, optional"`
- CapacityMb int `help:"capacity, unit mb"`
- }
- func (opts *BackupStorageCreateOptions) Params() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), nil
- }
- type BackupStorageUpdateOptions struct {
- options.BaseUpdateOptions
- NfsHost string `help:"nfs host, required when storage_type is nfs"`
- NfsSharedDir string `help:"nfs shared dir, required when storage_type is nfs" `
- ObjectBucketUrl string `help:"object bucket url, required when storage_type is object"`
- ObjectAccessKey string `help:"object storage access key, required when storage_type is object"`
- ObjectSecret string `help:"object storage secret, required when storage_type is object"`
- ObjectSignVer string `help:"object storage signing alogirithm version, optional" choices:"v2|v4"`
- ObjectBucketUrlExt string `help:"object storage external access url, optional"`
- }
- func (opts *BackupStorageUpdateOptions) Params() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), nil
- }
- type InstanceBackupListOptions struct {
- options.BaseListOptions
- OrderByGuest string
- }
- func (opts *InstanceBackupListOptions) Params() (jsonutils.JSONObject, error) {
- return options.ListStructToParams(opts)
- }
- type InstanceBackupIdOptions struct {
- ID string `help:"instance backup id" json:"-"`
- }
- func (opts *InstanceBackupIdOptions) GetId() string {
- return opts.ID
- }
- func (opts *InstanceBackupIdOptions) Params() (jsonutils.JSONObject, error) {
- return nil, nil
- }
- type InstanceBackupDeleteOptions struct {
- InstanceBackupIdOptions
- Force bool `help:"force delete"`
- }
- func (opts *InstanceBackupDeleteOptions) QueryParams() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), 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
- }
- type InstanceBackupPackOptions struct {
- DiskBackupIdOptions
- PackageName string `help:"package name" json:"package_name"`
- }
- func (opts *InstanceBackupPackOptions) Params() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), nil
- }
- type InstanceBackupManagerCreateFromPackageOptions struct {
- PackageName string `help:"package name" json:"package_name"`
- Name string `help:"instance backup name" json:"name"`
- BackupStorageId string `help:"backup storage id" json:"backup_storage_id"`
- ProjectId string `help:"target project id" json:"project_id"`
- }
- func (opts *InstanceBackupManagerCreateFromPackageOptions) Params() (jsonutils.JSONObject, error) {
- return jsonutils.Marshal(opts), nil
- }
- type HostBackupStorageListOptions struct {
- options.BaseListOptions
- Host string `json:"-" help:"filter by host"`
- Backupstorage string `json:"-" help:"filter by backupstorage"`
- }
- func (opts HostBackupStorageListOptions) GetMasterOpt() string {
- return opts.Host
- }
- func (opts HostBackupStorageListOptions) GetSlaveOpt() string {
- return opts.Backupstorage
- }
- func (opts *HostBackupStorageListOptions) Params() (jsonutils.JSONObject, error) {
- return options.ListStructToParams(opts)
- }
- type HostBackupStorageJoinOptions struct {
- HOST string `json:"-" help:"host id"`
- BACKUPSTORAGE string `json:"-" help:"backup storage id"`
- }
- func (opts HostBackupStorageJoinOptions) GetMasterId() string {
- return opts.HOST
- }
- func (opts HostBackupStorageJoinOptions) GetSlaveId() string {
- return opts.BACKUPSTORAGE
- }
- func (opts HostBackupStorageJoinOptions) Params() (jsonutils.JSONObject, error) {
- return jsonutils.NewDict(), nil
- }
- type DiskBackupExportOptions struct {
- DiskBackupIdOptions
- Output string `help:"output file path" json:"output"`
- }
- type DiskBackupImportOptions struct {
- NAME string `help:"backup name" json:"name"`
- BACKUPSTORAGEID string `help:"backup storage id" json:"backup_storage_id"`
- IMPORT string `help:"backup info" json:"-"`
- TenantId string `help:"tenant id" json:"tenant_id"`
- }
- func (opts *DiskBackupImportOptions) Params() (jsonutils.JSONObject, error) {
- content, err := os.ReadFile(opts.IMPORT)
- if err != nil {
- return nil, errors.Wrap(err, "os.ReadFile")
- }
- inputJson, err := jsonutils.Parse(content)
- if err != nil {
- return nil, errors.Wrap(err, "jsonutils.Parse")
- }
- info := &computeapi.DiskBackupImportInput{}
- err = inputJson.Unmarshal(info)
- if err != nil {
- return nil, errors.Wrap(err, "jsonutils.Unmarshal")
- }
- info.Name = opts.NAME
- info.BackupStorageId = opts.BACKUPSTORAGEID
- if len(opts.TenantId) > 0 {
- info.ProjectId = opts.TenantId
- }
- return jsonutils.Marshal(info), nil
- }
|