github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/cbr/v3/vaults/create.go (about)

     1  package vaults
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     7  )
     8  
     9  type BillingCreate struct {
    10  	// Cloud platform. Enumeration values:
    11  	//    public
    12  	//    hybrid
    13  	CloudType string `json:"cloud_type,omitempty"`
    14  	// Backup specifications. The default value is `crash_consistent`
    15  	ConsistentLevel string `json:"consistent_level"`
    16  	// Object type
    17  	ObjectType string `json:"object_type"`
    18  	// Operation type. Enumeration values:
    19  	//    backup
    20  	//    replication
    21  	ProtectType string `json:"protect_type"`
    22  	// Capacity, in GB. Minimum: `1`. Maximum: `10485760`
    23  	Size int `json:"size"`
    24  	// Billing mode. Possible values are `post_paid` (pay-per-use) or `pre_paid` (yearly/monthly packages).
    25  	// The value defaults to post_paid.
    26  	ChargingMode string `json:"charging_mode,omitempty"`
    27  	// Package type. This parameter is mandatory if charging_mode is set to pre_paid.
    28  	// Possible values are `year` (yearly) or `month`(monthly).
    29  	PeriodType string `json:"period_type,omitempty"`
    30  	// Required duration for the package. This parameter is mandatory if charging_mode is set to `pre_paid`.
    31  	PeriodNum int `json:"period_num,omitempty"`
    32  	// Whether to automatically renew the subscription after expiration. By default, it is not renewed.
    33  	IsAutoRenew bool `json:"is_auto_renew,omitempty"`
    34  	// Whether the fee is automatically deducted from the customer's account balance after an order is submitted.
    35  	// The non-automatic payment mode is used by default.
    36  	IsAutoPay bool `json:"is_auto_pay,omitempty"`
    37  	// Redirection URL
    38  	ConsoleURL string `json:"console_url,omitempty"`
    39  	// Extended information for creating a vault
    40  	ExtraInfo *BillingCreateExtraInfo `json:"extra_info,omitempty"`
    41  }
    42  
    43  type BillingCreateExtraInfo struct {
    44  	// ID of the application for creating vaults in combination.
    45  	// This parameter is mandatory when creating vaults in combination.
    46  	CombinedOrderID string `json:"combined_order_id,omitempty"`
    47  	// Number of items in the application for creating vaults in the combination mode.
    48  	// This parameter is mandatory when creating vaults in the combination mode.
    49  	CombinedOrderECSNum int `json:"combined_order_ecs_num,omitempty"`
    50  }
    51  
    52  type CreateOpts struct {
    53  	// Backup policy ID. If the value of this parameter is missing,
    54  	// automatic backup is not performed.
    55  	BackupPolicyID string `json:"backup_policy_id,omitempty"`
    56  	// Parameter information for billing creation
    57  	Billing *BillingCreate `json:"billing"`
    58  	// User-defined vault description
    59  	Description string `json:"description,omitempty"`
    60  	// Vault name
    61  	Name string `json:"name"`
    62  	// Associated resources. Set this parameter to [] if no resources are associated when creating a vault.
    63  	Resources []ResourceCreate `json:"resources"`
    64  	// Tags - Tag list.
    65  	// This list cannot be an empty list.
    66  	// The list can contain up to 10 keys.
    67  	// Keys in this list must be unique.
    68  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    69  	// Enterprise project ID. The default value is 0.
    70  	EnterpriseProjectID string `json:"enterprise_project_id,omitempty"`
    71  	// Whether automatic association is supported
    72  	AutoBind bool `json:"auto_bind,omitempty"`
    73  	// Rules for automatic association
    74  	BindRules *VaultBindRules `json:"bind_rules,omitempty"`
    75  	// Whether to automatically expand the vault capacity.
    76  	// Only pay-per-use vaults support this function.
    77  	AutoExpand bool `json:"auto_expand,omitempty"`
    78  }
    79  
    80  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Vault, error) {
    81  	reqBody, err := golangsdk.BuildRequestBody(opts, "vault")
    82  	if err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	raw, err := client.Post(client.ServiceURL("vaults"), reqBody, nil, &golangsdk.RequestOpts{
    87  		OkCodes: []int{200},
    88  	})
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  
    93  	var res Vault
    94  	return &res, extract.IntoStructPtr(raw.Body, &res, "vault")
    95  }