//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.
//
// Code generated by Alibaba Cloud SDK Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

package eci

import (
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
)

// CreateContainerGroup invokes the eci.CreateContainerGroup API synchronously
// api document: https://help.aliyun.com/api/eci/createcontainergroup.html
func (client *Client) CreateContainerGroup(request *CreateContainerGroupRequest) (response *CreateContainerGroupResponse, err error) {
	response = CreateCreateContainerGroupResponse()
	err = client.DoAction(request, response)
	return
}

// CreateContainerGroupWithChan invokes the eci.CreateContainerGroup API asynchronously
// api document: https://help.aliyun.com/api/eci/createcontainergroup.html
// asynchronous document: https://help.aliyun.com/document_detail/66220.html
func (client *Client) CreateContainerGroupWithChan(request *CreateContainerGroupRequest) (<-chan *CreateContainerGroupResponse, <-chan error) {
	responseChan := make(chan *CreateContainerGroupResponse, 1)
	errChan := make(chan error, 1)
	err := client.AddAsyncTask(func() {
		defer close(responseChan)
		defer close(errChan)
		response, err := client.CreateContainerGroup(request)
		if err != nil {
			errChan <- err
		} else {
			responseChan <- response
		}
	})
	if err != nil {
		errChan <- err
		close(responseChan)
		close(errChan)
	}
	return responseChan, errChan
}

// CreateContainerGroupWithCallback invokes the eci.CreateContainerGroup API asynchronously
// api document: https://help.aliyun.com/api/eci/createcontainergroup.html
// asynchronous document: https://help.aliyun.com/document_detail/66220.html
func (client *Client) CreateContainerGroupWithCallback(request *CreateContainerGroupRequest, callback func(response *CreateContainerGroupResponse, err error)) <-chan int {
	result := make(chan int, 1)
	err := client.AddAsyncTask(func() {
		var response *CreateContainerGroupResponse
		var err error
		defer close(result)
		response, err = client.CreateContainerGroup(request)
		callback(response, err)
		result <- 1
	})
	if err != nil {
		defer close(result)
		callback(nil, err)
		result <- 0
	}
	return result
}

// CreateContainerGroupRequest is the request struct for api CreateContainerGroup
type CreateContainerGroupRequest struct {
	*requests.RpcRequest
	Action                  string                                          `position:"Query" name:"Action"`
	OwnerId                 requests.Integer                                `position:"Query" name:"OwnerId"`
	ResourceOwnerAccount    string                                          `position:"Query" name:"ResourceOwnerAccount"`
	ResourceOwnerId         requests.Integer                                `position:"Query" name:"ResourceOwnerId"`
	OwnerAccount            string                                          `position:"Query" name:"OwnerAccount"`
	RegionId                string                                          `position:"Query" name:"RegionId"`
	ZoneId                  string                                          `position:"Query" name:"ZoneId"`
	SecurityGroupId         string                                          `position:"Query" name:"SecurityGroupId"`
	VSwitchId               string                                          `position:"Query" name:"VSwitchId"`
	ContainerGroupName      string                                          `position:"Query" name:"ContainerGroupName"`
	RestartPolicy           string                                          `position:"Query" name:"RestartPolicy"`
	Tag                     *[]CreateContainerGroup_Tag                     `position:"Query" name:"Tag"`
	ImageRegistryCredential *[]CreateContainerGroup_ImageRegistryCredential `position:"Query" name:"ImageRegistryCredential"`
	Container               *[]CreateContainerGroup_Container               `position:"Query" name:"Container"`
	Volume                  *[]CreateContainerGroup_Volume                  `position:"Query" name:"Volume"`
	EipInstanceId           string                                          `position:"Query" name:"EipInstanceId"`
	InitContainer           *[]CreateContainerGroup_InitContainer           `position:"Query" name:"InitContainer"`
	DnsConfig_NameServer    []string                                        `position:"Query" name:"DnsConfig.NameServer"`
	DnsConfig_Search        []string                                        `position:"Query" name:"DnsConfig.Search"`
	DnsConfig_Option        *[]CreateContainerGroup_DnsConfig_Option        `position:"Query" name:"DnsConfig.Option"`
	Cpu                     requests.Float                                  `position:"Query" name:"Cpu"`
	Memory                  requests.Float                                  `position:"Query" name:"Memory"`
}

type CreateContainerGroup_Tag struct {
	Key   string `json:"Key" xml:"Key"`
	Value string `json:"Value" xml:"Value"`
}

type CreateContainerGroup_ImageRegistryCredential struct {
	Server   string `json:"Server" xml:"Server"`
	UserName string `json:"UserName" xml:"UserName"`
	Password string `json:"Password" xml:"Password"`
}

type CreateContainerGroup_Container struct {
	Image                                  string                                 `json:"Image" xml:"Image"`
	Name                                   string                                 `json:"Name" xml:"Name"`
	Cpu                                    requests.Float                         `json:"Cpu" xml:"Cpu"`
	Memory                                 requests.Float                         `json:"Memory" xml:"Memory"`
	WorkingDir                             string                                 `json:"WorkingDir" xml:"WorkingDir"`
	ImagePullPolicy                        string                                 `json:"ImagePullPolicy" xml:"ImagePullPolicy"`
	Command                                []string                               `json:"Command" xml:"Command"`
	Arg                                    []string                               `json:"Arg" xml:"Arg"`
	VolumeMount                            *[]CreateContainerGroup_VolumeMount    `json:"VolumeMount" xml:"VolumeMount"`
	Port                                   *[]CreateContainerGroup_Port           `json:"Port" xml:"Port"`
	EnvironmentVar                         *[]CreateContainerGroup_EnvironmentVar `json:"EnvironmentVar" xml:"EnvironmentVar"`
	ReadinessProbe_HttpGet_Path            string                                 `json:"ReadinessProbe.HttpGet.Path" xml:"ReadinessProbe.HttpGet.Path"`
	ReadinessProbe_HttpGet_Port            requests.Integer                       `json:"ReadinessProbe.HttpGet.Port" xml:"ReadinessProbe.HttpGet.Port"`
	ReadinessProbe_HttpGet_Scheme          string                                 `json:"ReadinessProbe.HttpGet.Scheme" xml:"ReadinessProbe.HttpGet.Scheme"`
	ReadinessProbe_InitialDelaySeconds     requests.Integer                       `json:"ReadinessProbe.InitialDelaySeconds" xml:"ReadinessProbe.InitialDelaySeconds"`
	ReadinessProbe_PeriodSeconds           requests.Integer                       `json:"ReadinessProbe.PeriodSeconds" xml:"ReadinessProbe.PeriodSeconds"`
	ReadinessProbe_SuccessThreshold        requests.Integer                       `json:"ReadinessProbe.SuccessThreshold" xml:"ReadinessProbe.SuccessThreshold"`
	ReadinessProbe_FailureThreshold        requests.Integer                       `json:"ReadinessProbe.FailureThreshold" xml:"ReadinessProbe.FailureThreshold"`
	ReadinessProbe_TimeoutSeconds          requests.Integer                       `json:"ReadinessProbe.TimeoutSeconds" xml:"ReadinessProbe.TimeoutSeconds"`
	ReadinessProbe_Exec_Command            []string                               `json:"ReadinessProbe.Exec.Command" xml:"ReadinessProbe.Exec.Command"`
	LivenessProbe_HttpGet_Path             string                                 `json:"LivenessProbe.HttpGet.Path" xml:"LivenessProbe.HttpGet.Path"`
	LivenessProbe_HttpGet_Port             requests.Integer                       `json:"LivenessProbe.HttpGet.Port" xml:"LivenessProbe.HttpGet.Port"`
	LivenessProbe_HttpGet_Scheme           string                                 `json:"LivenessProbe.HttpGet.Scheme" xml:"LivenessProbe.HttpGet.Scheme"`
	LivenessProbe_InitialDelaySeconds      requests.Integer                       `json:"LivenessProbe.InitialDelaySeconds" xml:"LivenessProbe.InitialDelaySeconds"`
	LivenessProbe_PeriodSeconds            requests.Integer                       `json:"LivenessProbe.PeriodSeconds" xml:"LivenessProbe.PeriodSeconds"`
	LivenessProbe_SuccessThreshold         requests.Integer                       `json:"LivenessProbe.SuccessThreshold" xml:"LivenessProbe.SuccessThreshold"`
	LivenessProbe_FailureThreshold         requests.Integer                       `json:"LivenessProbe.FailureThreshold" xml:"LivenessProbe.FailureThreshold"`
	LivenessProbe_TimeoutSeconds           requests.Integer                       `json:"LivenessProbe.TimeoutSeconds" xml:"LivenessProbe.TimeoutSeconds"`
	LivenessProbe_Exec_Command             []string                               `json:"LivenessProbe.Exec.Command" xml:"LivenessProbe.Exec.Command"`
	SecurityContext_Capability_Add         []string                               `json:"SecurityContext.Capability.Add" xml:"SecurityContext.Capability.Add"`
	SecurityContext_ReadOnlyRootFilesystem requests.Boolean                       `json:"SecurityContext.ReadOnlyRootFilesystem" xml:"SecurityContext.ReadOnlyRootFilesystem"`
	SecurityContext_RunAsUser              requests.Integer                       `json:"SecurityContext.RunAsUser" xml:"SecurityContext.RunAsUser"`
	ReadinessProbe_TcpSocket_Port          requests.Integer                       `json:"ReadinessProbe.TcpSocket.Port" xml:"ReadinessProbe.TcpSocket.Port"`
	LivenessProbe_TcpSocket_Port           requests.Integer                       `json:"LivenessProbe.TcpSocket.Port" xml:"LivenessProbe.TcpSocket.Port"`
}

type CreateContainerGroup_Volume struct {
	Name                              string                                                    `json:"Name" xml:"Name"`
	NFSVolume_Server                  string                                                    `json:"NFSVolume.Server" xml:"NFSVolume.Server"`
	NFSVolume_Path                    string                                                    `json:"NFSVolume.Path" xml:"NFSVolume.Path"`
	NFSVolume_ReadOnly                requests.Boolean                                          `json:"NFSVolume.ReadOnly" xml:"NFSVolume.ReadOnly"`
	ConfigFileVolume_ConfigFileToPath *[]CreateContainerGroup_ConfigFileVolume_ConfigFileToPath `json:"ConfigFileVolume.ConfigFileToPath" xml:"ConfigFileVolume.ConfigFileToPath"`
	Type                              string                                                    `json:"Type" xml:"Type"`
}

type CreateContainerGroup_InitContainer struct {
	Name                                   string                                 `json:"Name" xml:"Name"`
	Image                                  string                                 `json:"Image" xml:"Image"`
	Cpu                                    requests.Float                         `json:"Cpu" xml:"Cpu"`
	Memory                                 requests.Float                         `json:"Memory" xml:"Memory"`
	WorkingDir                             string                                 `json:"WorkingDir" xml:"WorkingDir"`
	ImagePullPolicy                        string                                 `json:"ImagePullPolicy" xml:"ImagePullPolicy"`
	Command                                []string                               `json:"Command" xml:"Command"`
	Arg                                    []string                               `json:"Arg" xml:"Arg"`
	VolumeMount                            *[]CreateContainerGroup_VolumeMount    `json:"VolumeMount" xml:"VolumeMount"`
	Port                                   *[]CreateContainerGroup_Port           `json:"Port" xml:"Port"`
	EnvironmentVar                         *[]CreateContainerGroup_EnvironmentVar `json:"EnvironmentVar" xml:"EnvironmentVar"`
	SecurityContext_Capability_Add         []string                               `json:"SecurityContext.Capability.Add" xml:"SecurityContext.Capability.Add"`
	SecurityContext_ReadOnlyRootFilesystem requests.Boolean                       `json:"SecurityContext.ReadOnlyRootFilesystem" xml:"SecurityContext.ReadOnlyRootFilesystem"`
	SecurityContext_RunAsUser              requests.Integer                       `json:"SecurityContext.RunAsUser" xml:"SecurityContext.RunAsUser"`
}

type CreateContainerGroup_DnsConfig_Option struct {
	Name  string `json:"Name" xml:"Name"`
	Value string `json:"Value" xml:"Value"`
}

type CreateContainerGroup_VolumeMount struct {
	MountPath string           `json:"MountPath" xml:"MountPath"`
	ReadOnly  requests.Boolean `json:"ReadOnly" xml:"ReadOnly"`
	Name      string           `json:"Name" xml:"Name"`
}

type CreateContainerGroup_Port struct {
	Protocol string           `json:"Protocol" xml:"Protocol"`
	Port     requests.Integer `json:"Port" xml:"Port"`
}

type CreateContainerGroup_EnvironmentVar struct {
	Key   string `json:"Key" xml:"Key"`
	Value string `json:"Value" xml:"Value"`
}

type CreateContainerGroup_ConfigFileVolume_ConfigFileToPath struct {
	Content string `json:"Content" xml:"Content"`
	Path    string `json:"Path" xml:"Path"`
}

// CreateContainerGroupResponse is the response struct for api CreateContainerGroup
type CreateContainerGroupResponse struct {
	*responses.BaseResponse
	RequestId        string `json:"RequestId" xml:"RequestId"`
	ContainerGroupId string `json:"ContainerGroupId" xml:"ContainerGroupId"`
}

// CreateCreateContainerGroupRequest creates a request to invoke CreateContainerGroup API
func CreateCreateContainerGroupRequest() (request *CreateContainerGroupRequest) {
	request = &CreateContainerGroupRequest{
		RpcRequest: &requests.RpcRequest{},
	}
	request.InitWithApiInfo("Eci", "2018-08-08", "CreateContainerGroup", "eci", "openAPI")
	return
}

// CreateCreateContainerGroupResponse creates a response to parse from CreateContainerGroup response
func CreateCreateContainerGroupResponse() (response *CreateContainerGroupResponse) {
	response = &CreateContainerGroupResponse{
		BaseResponse: &responses.BaseResponse{},
	}
	return
}
