1package ecs
2
3//Licensed under the Apache License, Version 2.0 (the "License");
4//you may not use this file except in compliance with the License.
5//You may obtain a copy of the License at
6//
7//http://www.apache.org/licenses/LICENSE-2.0
8//
9//Unless required by applicable law or agreed to in writing, software
10//distributed under the License is distributed on an "AS IS" BASIS,
11//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//See the License for the specific language governing permissions and
13//limitations under the License.
14//
15// Code generated by Alibaba Cloud SDK Code Generator.
16// Changes may cause incorrect behavior and will be lost if the code is regenerated.
17
18import (
19	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
20	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
21)
22
23// AttachKeyPair invokes the ecs.AttachKeyPair API synchronously
24func (client *Client) AttachKeyPair(request *AttachKeyPairRequest) (response *AttachKeyPairResponse, err error) {
25	response = CreateAttachKeyPairResponse()
26	err = client.DoAction(request, response)
27	return
28}
29
30// AttachKeyPairWithChan invokes the ecs.AttachKeyPair API asynchronously
31func (client *Client) AttachKeyPairWithChan(request *AttachKeyPairRequest) (<-chan *AttachKeyPairResponse, <-chan error) {
32	responseChan := make(chan *AttachKeyPairResponse, 1)
33	errChan := make(chan error, 1)
34	err := client.AddAsyncTask(func() {
35		defer close(responseChan)
36		defer close(errChan)
37		response, err := client.AttachKeyPair(request)
38		if err != nil {
39			errChan <- err
40		} else {
41			responseChan <- response
42		}
43	})
44	if err != nil {
45		errChan <- err
46		close(responseChan)
47		close(errChan)
48	}
49	return responseChan, errChan
50}
51
52// AttachKeyPairWithCallback invokes the ecs.AttachKeyPair API asynchronously
53func (client *Client) AttachKeyPairWithCallback(request *AttachKeyPairRequest, callback func(response *AttachKeyPairResponse, err error)) <-chan int {
54	result := make(chan int, 1)
55	err := client.AddAsyncTask(func() {
56		var response *AttachKeyPairResponse
57		var err error
58		defer close(result)
59		response, err = client.AttachKeyPair(request)
60		callback(response, err)
61		result <- 1
62	})
63	if err != nil {
64		defer close(result)
65		callback(nil, err)
66		result <- 0
67	}
68	return result
69}
70
71// AttachKeyPairRequest is the request struct for api AttachKeyPair
72type AttachKeyPairRequest struct {
73	*requests.RpcRequest
74	ResourceOwnerId      requests.Integer `position:"Query" name:"ResourceOwnerId"`
75	KeyPairName          string           `position:"Query" name:"KeyPairName"`
76	ResourceOwnerAccount string           `position:"Query" name:"ResourceOwnerAccount"`
77	OwnerId              requests.Integer `position:"Query" name:"OwnerId"`
78	InstanceIds          string           `position:"Query" name:"InstanceIds"`
79}
80
81// AttachKeyPairResponse is the response struct for api AttachKeyPair
82type AttachKeyPairResponse struct {
83	*responses.BaseResponse
84	RequestId   string                 `json:"RequestId" xml:"RequestId"`
85	TotalCount  string                 `json:"TotalCount" xml:"TotalCount"`
86	FailCount   string                 `json:"FailCount" xml:"FailCount"`
87	KeyPairName string                 `json:"KeyPairName" xml:"KeyPairName"`
88	Results     ResultsInAttachKeyPair `json:"Results" xml:"Results"`
89}
90
91// CreateAttachKeyPairRequest creates a request to invoke AttachKeyPair API
92func CreateAttachKeyPairRequest() (request *AttachKeyPairRequest) {
93	request = &AttachKeyPairRequest{
94		RpcRequest: &requests.RpcRequest{},
95	}
96	request.InitWithApiInfo("Ecs", "2014-05-26", "AttachKeyPair", "ecs", "openAPI")
97	request.Method = requests.POST
98	return
99}
100
101// CreateAttachKeyPairResponse creates a response to parse from AttachKeyPair response
102func CreateAttachKeyPairResponse() (response *AttachKeyPairResponse) {
103	response = &AttachKeyPairResponse{
104		BaseResponse: &responses.BaseResponse{},
105	}
106	return
107}
108