github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/drs/v3/public/BatchTestConnections.go (about)

     1  package public
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type BatchTestConnectionOpts struct {
    10  	Jobs []TestEndPoint `json:"jobs"`
    11  }
    12  
    13  type TestEndPoint struct {
    14  	// Task ID.
    15  	Id string `json:"id" required:"true"`
    16  	// Network type.
    17  	// Value: vpn vpc eip
    18  	NetType string `json:"net_type" required:"true"`
    19  	// Database type.
    20  	// Value: mysql mongodb taurus postgresql
    21  	DbType string `json:"db_type" required:"true"`
    22  	// Database IP address.
    23  	Ip string `json:"ip" required:"true"`
    24  	// Database port number. This parameter must be set to 0 for the Mongo and DDS databases.
    25  	DbPort int `json:"db_port,omitempty"`
    26  	// The RDS or GaussDB(for MySQL) instance ID. This parameter is mandatory for RDS or GaussDB(for MySQL) instances.
    27  	InstId string `json:"inst_id,omitempty"`
    28  	// Database account.
    29  	DbUser string `json:"db_user" required:"true"`
    30  	// Database password.
    31  	DbPassword string `json:"db_password"`
    32  	// Whether SSL is enabled.
    33  	SslLink *bool `json:"ssl_link,omitempty"`
    34  	// The SSL certificate content, which is encrypted using Base64.
    35  	// This parameter is mandatory for secure connection to the source database.
    36  	SslCertKey string `json:"ssl_cert_key,omitempty"`
    37  	// The SSL certificate name. This parameter is mandatory for secure connection to the source database.
    38  	SslCertName string `json:"ssl_cert_name,omitempty"`
    39  	// The checksum value of the SSL certificate, which is used for backend verification.
    40  	// This parameter is mandatory for secure connection to the source database.
    41  	SslCertCheckSum string `json:"ssl_cert_check_sum,omitempty"`
    42  	// The SSL certificate password. The certificate file name extension is .p12 and requires a password.
    43  	SslCertPassword string `json:"ssl_cert_password,omitempty"`
    44  	// ID of the VPC where the instance is located.
    45  	VpcId string `json:"vpc_id,omitempty"`
    46  	// ID of the subnet where the instance is located.
    47  	SubnetId string `json:"subnet_id,omitempty"`
    48  	// Source database: so. Destination database: ta. Default value: so
    49  	// Values: so ta
    50  	EndPointType string `json:"end_point_type" required:"true"`
    51  	// Region of the RDS DB instance. This parameter is mandatory when the RDS DB instance is used.
    52  	Region string `json:"region,omitempty"`
    53  	// Project ID of the region where the user is located. This parameter is mandatory when the RDS DB instance is used.
    54  	ProjectId string `json:"project_id,omitempty"`
    55  	// Database username, which is the DDS authentication database or the service name of the Oracle database.
    56  	DbName string `json:"db_name,omitempty"`
    57  }
    58  
    59  func BatchTestConnections(client *golangsdk.ServiceClient, opts BatchTestConnectionOpts) (*BatchValidateConnectionsResponse, error) {
    60  	b, err := build.RequestBody(opts, "")
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	// POST /v3/{project_id}/jobs/batch-connection
    66  	raw, err := client.Post(client.ServiceURL("jobs", "batch-connection"), b, nil, &golangsdk.RequestOpts{
    67  		OkCodes:     []int{200},
    68  		MoreHeaders: map[string]string{"Content-Type": "application/json"},
    69  	})
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  
    74  	var res BatchValidateConnectionsResponse
    75  	err = extract.Into(raw.Body, &res)
    76  	return &res, err
    77  }
    78  
    79  type BatchValidateConnectionsResponse struct {
    80  	Results []CheckJobResp `json:"results,omitempty"`
    81  	Count   int            `json:"count,omitempty"`
    82  }
    83  
    84  type CheckJobResp struct {
    85  	// Task ID.
    86  	Id string `json:"id"`
    87  	// Test result. Value:
    88  	// success: indicates that the connection test is successful.
    89  	// failed: indicates that the connection test fails.
    90  	Status string `json:"status"`
    91  	// Error code, which is optional and indicates the returned information about the failure status.
    92  	ErrorCode string `json:"error_code,omitempty"`
    93  	// Error message, which is optional and indicates the returned information about the failure status.
    94  	ErrorMsg string `json:"error_msg,omitempty"`
    95  	// Whether the request is successful.
    96  	Success bool `json:"success,omitempty"`
    97  }