add ncloud-sdk-go dependency to vendor

This commit is contained in:
유성덕 2018-01-11 19:41:47 +09:00
parent 5189d65467
commit 4f9754a75c
35 changed files with 2745 additions and 0 deletions

View File

@ -0,0 +1,7 @@
Copyright 2017 NAVER BUSINESS PLATFORM Corp.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,26 @@
ncp-sdk-go
This project contains subcomponents with separate copyright notices and license terms.
Your use of the source code for these subcomponents is subject to the terms and conditions of the following licenses.
=======================================================================
OAuth 1.0 Library for Go (https://github.com/mrjones/oauth/)
=======================================================================
Copyright (C) 2013 Matthew R. Jones
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,14 @@
package common
import "encoding/xml"
type CommonResponse struct {
RequestID string `xml:"requestId"`
ReturnCode int `xml:"returnCode"`
ReturnMessage string `xml:"returnMessage"`
}
type ResponseError struct {
ResponseError xml.Name `xml:"responseError"`
CommonResponse
}

View File

@ -0,0 +1,10 @@
package common
type CommonCode struct {
CodeKind string `xml:"codeKind"`
DetailCategorizeCode string `xml:"detailCategorizeCode"`
Code string `xml:"code"`
CodeName string `xml:"codeName"`
CodeOrder int `xml:"codeOrder"`
JavaConstantCode string `xml:"javaConstantCode"`
}

View File

@ -0,0 +1,20 @@
package common
import (
"encoding/xml"
"strings"
)
func ParseErrorResponse(bytes []byte) (*ResponseError, error) {
responseError := ResponseError{}
if err := xml.Unmarshal([]byte(bytes), &responseError); err != nil {
return nil, err
}
if responseError.ReturnMessage != "" {
responseError.ReturnMessage = strings.TrimSpace(responseError.ReturnMessage)
}
return &responseError, nil
}

View File

@ -0,0 +1,7 @@
package common
type Region struct {
RegionNo string `xml:"regionNo"`
RegionCode string `xml:"regionCode"`
RegionName string `xml:"regionName"`
}

View File

@ -0,0 +1,7 @@
package common
type Zone struct {
ZoneNo string `xml:"zoneNo"`
ZoneName string `xml:"zoneName"`
ZoneDescription string `xml:"zoneDescription"`
}

View File

@ -0,0 +1,370 @@
package oauth
import (
"crypto"
"crypto/hmac"
_ "crypto/sha1"
"encoding/base64"
"fmt"
"math/rand"
"net/url"
"os"
"sort"
"strconv"
"sync"
"time"
)
const (
OAUTH_VERSION = "1.0"
SIGNATURE_METHOD_HMAC = "HMAC-"
HTTP_AUTH_HEADER = "Authorization"
OAUTH_HEADER = "OAuth "
CONSUMER_KEY_PARAM = "oauth_consumer_key"
NONCE_PARAM = "oauth_nonce"
SIGNATURE_METHOD_PARAM = "oauth_signature_method"
SIGNATURE_PARAM = "oauth_signature"
TIMESTAMP_PARAM = "oauth_timestamp"
TOKEN_PARAM = "oauth_token"
TOKEN_SECRET_PARAM = "oauth_token_secret"
VERSION_PARAM = "oauth_version"
)
var HASH_METHOD_MAP = map[crypto.Hash]string{
crypto.SHA1: "SHA1",
crypto.SHA256: "SHA256",
}
// Creates a new Consumer instance, with a HMAC-SHA1 signer
func NewConsumer(consumerKey string, consumerSecret string, requestMethod string, requestURL string) *Consumer {
clock := &defaultClock{}
consumer := &Consumer{
consumerKey: consumerKey,
consumerSecret: consumerSecret,
requestMethod: requestMethod,
requestURL: requestURL,
clock: clock,
nonceGenerator: newLockedNonceGenerator(clock),
AdditionalParams: make(map[string]string),
}
consumer.signer = &HMACSigner{
consumerSecret: consumerSecret,
hashFunc: crypto.SHA1,
}
return consumer
}
// lockedNonceGenerator wraps a non-reentrant random number generator with alock
type lockedNonceGenerator struct {
nonceGenerator nonceGenerator
lock sync.Mutex
}
func newLockedNonceGenerator(c clock) *lockedNonceGenerator {
return &lockedNonceGenerator{
nonceGenerator: rand.New(rand.NewSource(c.Nanos())),
}
}
func (n *lockedNonceGenerator) Int63() int64 {
n.lock.Lock()
r := n.nonceGenerator.Int63()
n.lock.Unlock()
return r
}
type clock interface {
Seconds() int64
Nanos() int64
}
type nonceGenerator interface {
Int63() int64
}
type signer interface {
Sign(message string) (string, error)
Verify(message string, signature string) error
SignatureMethod() string
HashFunc() crypto.Hash
Debug(enabled bool)
}
type defaultClock struct{}
func (*defaultClock) Seconds() int64 {
return time.Now().Unix()
}
func (*defaultClock) Nanos() int64 {
return time.Now().UnixNano()
}
type Consumer struct {
AdditionalParams map[string]string
// The rest of this class is configured via the NewConsumer function.
consumerKey string
consumerSecret string
requestMethod string
requestURL string
debug bool
// Private seams for mocking dependencies when testing
clock clock
// Seeded generators are not reentrant
nonceGenerator nonceGenerator
signer signer
}
type HMACSigner struct {
consumerSecret string
hashFunc crypto.Hash
debug bool
}
func (s *HMACSigner) Debug(enabled bool) {
s.debug = enabled
}
func (s *HMACSigner) Sign(message string) (string, error) {
key := escape(s.consumerSecret)
if s.debug {
fmt.Println("Signing:", message)
fmt.Println("Key:", key)
}
h := hmac.New(s.HashFunc().New, []byte(key+"&"))
h.Write([]byte(message))
rawSignature := h.Sum(nil)
base64signature := base64.StdEncoding.EncodeToString(rawSignature)
if s.debug {
fmt.Println("Base64 signature:", base64signature)
}
return base64signature, nil
}
func (s *HMACSigner) Verify(message string, signature string) error {
if s.debug {
fmt.Println("Verifying Base64 signature:", signature)
}
validSignature, err := s.Sign(message)
if err != nil {
return err
}
if validSignature != signature {
decodedSigniture, _ := url.QueryUnescape(signature)
if validSignature != decodedSigniture {
return fmt.Errorf("signature did not match")
}
}
return nil
}
func (s *HMACSigner) SignatureMethod() string {
return SIGNATURE_METHOD_HMAC + HASH_METHOD_MAP[s.HashFunc()]
}
func (s *HMACSigner) HashFunc() crypto.Hash {
return s.hashFunc
}
func escape(s string) string {
t := make([]byte, 0, 3*len(s))
for i := 0; i < len(s); i++ {
c := s[i]
if isEscapable(c) {
t = append(t, '%')
t = append(t, "0123456789ABCDEF"[c>>4])
t = append(t, "0123456789ABCDEF"[c&15])
} else {
t = append(t, s[i])
}
}
return string(t)
}
func isEscapable(b byte) bool {
return !('A' <= b && b <= 'Z' || 'a' <= b && b <= 'z' || '0' <= b && b <= '9' || b == '-' || b == '.' || b == '_' || b == '~')
}
func (c *Consumer) Debug(enabled bool) {
c.debug = enabled
c.signer.Debug(enabled)
}
func (c *Consumer) GetRequestUrl() (loginUrl string, err error) {
if os.Getenv("GO_ENV") == "development" {
c.AdditionalParams["approachKey"] = c.consumerKey
c.AdditionalParams["secretKey"] = c.consumerSecret
}
c.AdditionalParams["responseFormatType"] = "xml"
params := c.baseParams(c.consumerKey, c.AdditionalParams)
if c.debug {
fmt.Println("params:", params)
}
req := &request{
method: c.requestMethod,
url: c.requestURL,
oauthParams: params,
}
signature, err := c.signRequest(req)
if err != nil {
return "", err
}
result := req.url + "?"
for pos, key := range req.oauthParams.Keys() {
for innerPos, value := range req.oauthParams.Get(key) {
if pos+innerPos != 0 {
result += "&"
}
result += fmt.Sprintf("%s=%s", key, value)
}
}
result += fmt.Sprintf("&%s=%s", SIGNATURE_PARAM, escape(signature))
if c.debug {
fmt.Println("req: ", result)
}
return result, nil
}
func (c *Consumer) baseParams(consumerKey string, additionalParams map[string]string) *OrderedParams {
params := NewOrderedParams()
params.Add(VERSION_PARAM, OAUTH_VERSION)
params.Add(SIGNATURE_METHOD_PARAM, c.signer.SignatureMethod())
params.Add(TIMESTAMP_PARAM, strconv.FormatInt(c.clock.Seconds(), 10))
params.Add(NONCE_PARAM, strconv.FormatInt(c.nonceGenerator.Int63(), 10))
params.Add(CONSUMER_KEY_PARAM, consumerKey)
for key, value := range additionalParams {
params.Add(key, value)
}
return params
}
func (c *Consumer) signRequest(req *request) (string, error) {
baseString := c.requestString(req.method, req.url, req.oauthParams)
if c.debug {
fmt.Println("baseString: ", baseString)
}
signature, err := c.signer.Sign(baseString)
if err != nil {
return "", err
}
return signature, nil
}
func (c *Consumer) requestString(method string, url string, params *OrderedParams) string {
result := method + "&" + escape(url)
for pos, key := range params.Keys() {
for innerPos, value := range params.Get(key) {
if pos+innerPos == 0 {
result += "&"
} else {
result += escape("&")
}
result += escape(fmt.Sprintf("%s=%s", key, value))
}
}
return result
}
type request struct {
method string
url string
oauthParams *OrderedParams
userParams map[string]string
}
//
// String Sorting helpers
//
type ByValue []string
func (a ByValue) Len() int {
return len(a)
}
func (a ByValue) Swap(i, j int) {
a[i], a[j] = a[j], a[i]
}
func (a ByValue) Less(i, j int) bool {
return a[i] < a[j]
}
//
// ORDERED PARAMS
//
type OrderedParams struct {
allParams map[string][]string
keyOrdering []string
}
func NewOrderedParams() *OrderedParams {
return &OrderedParams{
allParams: make(map[string][]string),
keyOrdering: make([]string, 0),
}
}
func (o *OrderedParams) Get(key string) []string {
sort.Sort(ByValue(o.allParams[key]))
return o.allParams[key]
}
func (o *OrderedParams) Keys() []string {
sort.Sort(o)
return o.keyOrdering
}
func (o *OrderedParams) Add(key, value string) {
o.AddUnescaped(key, escape(value))
}
func (o *OrderedParams) AddUnescaped(key, value string) {
if _, exists := o.allParams[key]; !exists {
o.keyOrdering = append(o.keyOrdering, key)
o.allParams[key] = make([]string, 1)
o.allParams[key][0] = value
} else {
o.allParams[key] = append(o.allParams[key], value)
}
}
func (o *OrderedParams) Len() int {
return len(o.keyOrdering)
}
func (o *OrderedParams) Less(i int, j int) bool {
return o.keyOrdering[i] < o.keyOrdering[j]
}
func (o *OrderedParams) Swap(i int, j int) {
o.keyOrdering[i], o.keyOrdering[j] = o.keyOrdering[j], o.keyOrdering[i]
}

View File

@ -0,0 +1,38 @@
package request
import (
"io/ioutil"
"net/http"
"github.com/NaverCloudPlatform/ncloud-sdk-go/oauth"
)
// NewRequest is http request with oauth
func NewRequest(accessKey string, secretKey string, method string, url string, params map[string]string) ([]byte, *http.Response, error) {
c := oauth.NewConsumer(accessKey, secretKey, method, url)
for k, v := range params {
c.AdditionalParams[k] = v
}
reqURL, err := c.GetRequestUrl()
if err != nil {
return nil, nil, err
}
req, err := http.NewRequest(method, reqURL, nil)
if err != nil {
return nil, nil, err
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, nil, err
}
defer resp.Body.Close()
bytes, _ := ioutil.ReadAll(resp.Body)
return bytes, resp, nil
}

View File

@ -0,0 +1,21 @@
package sdk
import (
"os"
)
// NewConnection create connection for server api
func NewConnection(accessKey string, secretKey string) *Conn {
conn := &Conn{
accessKey: accessKey,
secretKey: secretKey,
apiURL: "https://api.ncloud.com/",
}
// for other phase(dev, test, beta ...) test
if os.Getenv("NCLOUD_API_GW") != "" {
conn.apiURL = os.Getenv("NCLOUD_API_GW")
}
return conn
}

View File

@ -0,0 +1,87 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processCreateBlockStorageInstanceParams(reqParams *RequestBlockStorageInstance) (map[string]string, error) {
params := make(map[string]string)
if reqParams.BlockStorageName != "" {
if len := len(reqParams.BlockStorageName); len < 3 || len > 30 {
return nil, errors.New("Length of BlockStorageName should be min 3 or max 30")
}
params["blockStorageName"] = reqParams.BlockStorageName
}
if reqParams.BlockStorageSize < 10 || reqParams.BlockStorageSize > 2000 {
return nil, errors.New("BlockStorageSize should be min 10 or max 2000")
}
if reqParams.BlockStorageDescription != "" {
if len := len(reqParams.BlockStorageDescription); len > 1000 {
return nil, errors.New("Length of BlockStorageDescription should be max 1000")
}
params["blockStorageDescription"] = reqParams.BlockStorageDescription
}
if int(reqParams.BlockStorageSize/10)*10 != reqParams.BlockStorageSize {
return nil, errors.New("BlockStorageSize must be a multiple of 10 GB")
}
if reqParams.BlockStorageSize == 0 {
return nil, errors.New("BlockStorageSize field is required")
}
params["blockStorageSize"] = strconv.Itoa(reqParams.BlockStorageSize)
if reqParams.ServerInstanceNo == "" {
return nil, errors.New("ServerInstanceNo field is required")
}
params["serverInstanceNo"] = reqParams.ServerInstanceNo
return params, nil
}
// CreateBlockStorageInstance create block storage instance
func (s *Conn) CreateBlockStorageInstance(reqParams *RequestBlockStorageInstance) (*BlockStorageInstanceList, error) {
params, err := processCreateBlockStorageInstanceParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "createBlockStorageInstance"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := BlockStorageInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var blockStorageInstanceList = BlockStorageInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &blockStorageInstanceList); err != nil {
return nil, err
}
return &blockStorageInstanceList, nil
}

View File

@ -0,0 +1,64 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strings"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processCreateLoginKeyParams(keyName string) error {
if keyName == "" {
return errors.New("KeyName is required field")
}
if len := len(keyName); len < 3 || len > 30 {
return errors.New("Length of KeyName should be min 3 or max 30")
}
return nil
}
// CreateLoginKey create loginkey with keyName
func (s *Conn) CreateLoginKey(keyName string) (*PrivateKey, error) {
if err := processCreateLoginKeyParams(keyName); err != nil {
return nil, err
}
params := make(map[string]string)
params["keyName"] = keyName
params["action"] = "createLoginKey"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := PrivateKey{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
privateKey := PrivateKey{}
if err := xml.Unmarshal([]byte(bytes), &privateKey); err != nil {
return nil, err
}
if privateKey.PrivateKey != "" {
privateKey.PrivateKey = strings.TrimSpace(privateKey.PrivateKey)
}
return &privateKey, nil
}

View File

@ -0,0 +1,74 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processCreatePublicIPInstanceParams(reqParams *RequestCreatePublicIPInstance) (map[string]string, error) {
params := make(map[string]string)
if reqParams.ServerInstanceNo != "" {
params["serverInstanceNo"] = reqParams.ServerInstanceNo
}
if reqParams.PublicIPDescription != "" {
if len := len(reqParams.PublicIPDescription); len > 1000 {
return params, errors.New("Length of publicIpDescription should be max 1000")
}
params["publicIpDescription"] = reqParams.PublicIPDescription
}
if reqParams.InternetLineTypeCode != "" {
if reqParams.InternetLineTypeCode != "PUBLC" && reqParams.InternetLineTypeCode != "GLBL" {
return params, errors.New("InternetLineTypeCode should be PUBLC or GLBL")
}
params["internetLineTypeCode"] = reqParams.InternetLineTypeCode
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
return params, nil
}
// CreatePublicIPInstance create public ip instance and allocate it to server instance
func (s *Conn) CreatePublicIPInstance(reqParams *RequestCreatePublicIPInstance) (*PublicIPInstanceList, error) {
params, err := processCreatePublicIPInstanceParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "createPublicIpInstance"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := PublicIPInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var responseCreatePublicIPInstances = PublicIPInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &responseCreatePublicIPInstances); err != nil {
fmt.Println(err)
return nil, err
}
return &responseCreatePublicIPInstances, nil
}

View File

@ -0,0 +1,71 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processCreateMemberServerImageParams(reqParams *RequestCreateServerImage) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil || reqParams.ServerInstanceNo == "" {
return params, errors.New("ServerInstanceNo is required field")
}
if reqParams.MemberServerImageName != "" {
if len := len(reqParams.MemberServerImageName); len < 3 || len > 30 {
return nil, errors.New("Length of MemberServerImageName should be min 3 or max 30")
}
params["memberServerImageName"] = reqParams.MemberServerImageName
}
if reqParams.MemberServerImageDescription != "" {
if len := len(reqParams.MemberServerImageDescription); len > 1000 {
return nil, errors.New("Length of MemberServerImageDescription should be smaller than 1000")
}
params["memberServerImageDescription"] = reqParams.MemberServerImageDescription
}
params["serverInstanceNo"] = reqParams.ServerInstanceNo
return params, nil
}
// CreateMemberServerImage create member server image and retrun member server image list
func (s *Conn) CreateMemberServerImage(reqParams *RequestCreateServerImage) (*MemberServerImageList, error) {
params, err := processCreateMemberServerImageParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "createMemberServerImage"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := MemberServerImageList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var serverImageListsResp = MemberServerImageList{}
if err := xml.Unmarshal([]byte(bytes), &serverImageListsResp); err != nil {
return nil, err
}
return &serverImageListsResp, nil
}

View File

@ -0,0 +1,148 @@
package sdk
import (
"encoding/base64"
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processCreateServerInstancesParams(reqParams *RequestCreateServerInstance) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if reqParams.ServerImageProductCode != "" {
if len := len(reqParams.ServerImageProductCode); len > 20 {
return nil, errors.New("Length of ServerImageProductCode should be min 1 or max 20")
}
params["serverImageProductCode"] = reqParams.ServerImageProductCode
}
if reqParams.ServerProductCode != "" {
if len := len(reqParams.ServerProductCode); len > 20 {
return nil, errors.New("Length of ServerProductCode should be min 1 or max 20")
}
params["serverProductCode"] = reqParams.ServerProductCode
}
if reqParams.MemberServerImageNo != "" {
params["memberServerImageNo"] = reqParams.MemberServerImageNo
}
if reqParams.ServerName != "" {
if len := len(reqParams.ServerName); len < 3 || len > 30 {
return nil, errors.New("Length of ServerName should be min 3 or max 30")
}
params["serverName"] = reqParams.ServerName
}
if reqParams.ServerDescription != "" {
if len := len(reqParams.ServerDescription); len > 1000 {
return nil, errors.New("Length of ServerDescription should be min 1 or max 1000")
}
params["serverDescription"] = reqParams.ServerDescription
}
if reqParams.LoginKeyName != "" {
if len := len(reqParams.LoginKeyName); len < 3 || len > 30 {
return nil, errors.New("Length of LoginKeyName should be min 3 or max 30")
}
params["loginKeyName"] = reqParams.LoginKeyName
}
if reqParams.IsProtectServerTermination == true {
params["isProtectServerTermination"] = "true"
}
if reqParams.ServerCreateCount > 0 {
if reqParams.ServerCreateCount > 20 {
return nil, errors.New("ServerCreateCount should be min 1 or max 20")
}
params["serverCreateCount"] = strconv.Itoa(reqParams.ServerCreateCount)
}
if reqParams.ServerCreateStartNo > 0 {
if reqParams.ServerCreateCount+reqParams.ServerCreateStartNo > 1000 {
return nil, errors.New("Sum of ServerCreateCount and ServerCreateStartNo should be less than 1000")
}
params["serverCreateStartNo"] = strconv.Itoa(reqParams.ServerCreateStartNo)
}
if reqParams.InternetLineTypeCode != "" {
if reqParams.InternetLineTypeCode != "PUBLC" && reqParams.InternetLineTypeCode != "GLBL" {
return nil, errors.New("InternetLineTypeCode should be PUBLC or GLBL")
}
params["internetLineTypeCode"] = reqParams.InternetLineTypeCode
}
if reqParams.FeeSystemTypeCode != "" {
if reqParams.FeeSystemTypeCode != "FXSUM" && reqParams.FeeSystemTypeCode != "MTRAT" {
return nil, errors.New("FeeSystemTypeCode should be FXSUM or MTRAT")
}
params["feeSystemTypeCode"] = reqParams.FeeSystemTypeCode
}
if reqParams.UserData != "" {
if len := len(reqParams.UserData); len > 21847 {
return nil, errors.New("Length of UserData should be min 1 or max 21847")
}
params["userData"] = base64.StdEncoding.EncodeToString([]byte(reqParams.UserData))
}
if reqParams.ZoneNo != "" {
params["zoneNo"] = reqParams.ZoneNo
}
if len(reqParams.AccessControlGroupConfigurationNoList) > 0 {
for k, v := range reqParams.AccessControlGroupConfigurationNoList {
params[fmt.Sprintf("accessControlGroupConfigurationNoList.%d", k+1)] = v
}
}
return params, nil
}
// CreateServerInstances create server instances
func (s *Conn) CreateServerInstances(reqParams *RequestCreateServerInstance) (*ServerInstanceList, error) {
params, err := processCreateServerInstancesParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "createServerInstances"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ServerInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var responseCreateServerInstances = ServerInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &responseCreateServerInstances); err != nil {
fmt.Println(err)
return nil, err
}
return &responseCreateServerInstances, nil
}

View File

@ -0,0 +1,60 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processDeleteBlockStorageInstancesParams(blockStorageInstanceNoList []string) (map[string]string, error) {
params := make(map[string]string)
if len(blockStorageInstanceNoList) == 0 {
return params, errors.New("BlockStorageInstanceNoList field is Required")
}
for k, v := range blockStorageInstanceNoList {
params[fmt.Sprintf("blockStorageInstanceNoList.%d", k+1)] = v
}
return params, nil
}
// DeleteBlockStorageInstances delete block storage instances
func (s *Conn) DeleteBlockStorageInstances(blockStorageInstanceNoList []string) (*BlockStorageInstanceList, error) {
params, err := processDeleteBlockStorageInstancesParams(blockStorageInstanceNoList)
if err != nil {
return nil, err
}
params["action"] = "deleteBlockStorageInstances"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := BlockStorageInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var blockStorageInstanceList = BlockStorageInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &blockStorageInstanceList); err != nil {
fmt.Println(err)
return nil, err
}
return &blockStorageInstanceList, nil
}

View File

@ -0,0 +1,59 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processDeleteLoginKeyParams(keyName string) error {
if keyName == "" {
return errors.New("KeyName is required field")
}
if len := len(keyName); len < 3 || len > 30 {
return errors.New("Length of KeyName should be min 3 or max 30")
}
return nil
}
// DeleteLoginKey delete login key with keyName
func (s *Conn) DeleteLoginKey(keyName string) (*common.CommonResponse, error) {
if err := processDeleteLoginKeyParams(keyName); err != nil {
return nil, err
}
params := make(map[string]string)
params["keyName"] = keyName
params["action"] = "deleteLoginKey"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := common.CommonResponse{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var responseDeleteLoginKey = common.CommonResponse{}
if err := xml.Unmarshal([]byte(bytes), &responseDeleteLoginKey); err != nil {
return nil, err
}
return &responseDeleteLoginKey, nil
}

View File

@ -0,0 +1,62 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processDeletePublicIPInstancesParams(reqParams *RequestDeletePublicIPInstances) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil || len(reqParams.PublicIPInstanceNoList) == 0 {
return params, errors.New("Required field is not specified. location : publicIpInstanceNoList.N")
}
if len(reqParams.PublicIPInstanceNoList) > 0 {
for k, v := range reqParams.PublicIPInstanceNoList {
params[fmt.Sprintf("publicIpInstanceNoList.%d", k+1)] = v
}
}
return params, nil
}
// DeletePublicIPInstances delete public ip instances
func (s *Conn) DeletePublicIPInstances(reqParams *RequestDeletePublicIPInstances) (*PublicIPInstanceList, error) {
params, err := processDeletePublicIPInstancesParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "deletePublicIpInstances"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := PublicIPInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var publicIPInstanceList = PublicIPInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &publicIPInstanceList); err != nil {
fmt.Println(err)
return nil, err
}
return &publicIPInstanceList, nil
}

View File

@ -0,0 +1,54 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processDisassociatePublicIPParams(PublicIPInstanceNo string) error {
if PublicIPInstanceNo == "" {
return errors.New("Required field is not specified. location : publicIpInstanceNo")
}
return nil
}
// DisassociatePublicIP diassociate public ip from server instance
func (s *Conn) DisassociatePublicIP(PublicIPInstanceNo string) (*PublicIPInstanceList, error) {
if err := processDisassociatePublicIPParams(PublicIPInstanceNo); err != nil {
return nil, err
}
params := make(map[string]string)
params["publicIpInstanceNo"] = PublicIPInstanceNo
params["action"] = "disassociatePublicIpFromServerInstance"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := PublicIPInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var responseDisassociatePublicIPInstances = PublicIPInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &responseDisassociatePublicIPInstances); err != nil {
return nil, err
}
return &responseDisassociatePublicIPInstances, nil
}

View File

@ -0,0 +1,89 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetAccessControlGroupListParams(reqParams *RequestAccessControlGroupList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if len(reqParams.AccessControlGroupConfigurationNoList) > 0 {
for k, v := range reqParams.AccessControlGroupConfigurationNoList {
params[fmt.Sprintf("accessControlGroupConfigurationNoList.%d", k+1)] = v
}
}
if reqParams.IsDefault {
params["isDefault"] = "true"
}
if reqParams.AccessControlGroupName != "" {
if len(reqParams.AccessControlGroupName) < 3 || len(reqParams.AccessControlGroupName) > 30 {
return nil, errors.New("AccessControlGroupName must be between 3 and 30 characters in length")
}
params["accessControlGroupName"] = reqParams.AccessControlGroupName
}
if reqParams.PageNo != 0 {
if reqParams.PageNo > 2147483647 {
return nil, errors.New("PageNo should be up to 2147483647")
}
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize != 0 {
if reqParams.PageSize > 2147483647 {
return nil, errors.New("PageSize should be up to 2147483647")
}
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
return params, nil
}
// GetAccessControlGroupList get access control group list
func (s *Conn) GetAccessControlGroupList(reqParams *RequestAccessControlGroupList) (*AccessControlGroupList, error) {
params, err := processGetAccessControlGroupListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getAccessControlGroupList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := AccessControlGroupList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var AccessControlGroupList = AccessControlGroupList{}
if err := xml.Unmarshal([]byte(bytes), &AccessControlGroupList); err != nil {
return nil, err
}
return &AccessControlGroupList, nil
}

View File

@ -0,0 +1,61 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func checkGetAccessControlRuleListParams(accessControlGroupConfigurationNo string) error {
if accessControlGroupConfigurationNo == "" {
return errors.New("accessControlGroupConfigurationNo is required")
}
if no, err := strconv.Atoi(accessControlGroupConfigurationNo); err != nil {
return err
} else if no < 0 || no > 2147483647 {
return errors.New("accessControlGroupConfigurationNoeNo must be up to 2147483647")
}
return nil
}
// GetAccessControlRuleList get access control group list
func (s *Conn) GetAccessControlRuleList(accessControlGroupConfigurationNo string) (*AccessControlRuleList, error) {
if err := checkGetAccessControlRuleListParams(accessControlGroupConfigurationNo); err != nil {
return nil, err
}
params := make(map[string]string)
params["accessControlGroupConfigurationNo"] = accessControlGroupConfigurationNo
params["action"] = "getAccessControlRuleList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := AccessControlRuleList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var AccessControlRuleList = AccessControlRuleList{}
if err := xml.Unmarshal([]byte(bytes), &AccessControlRuleList); err != nil {
return nil, err
}
return &AccessControlRuleList, nil
}

View File

@ -0,0 +1,144 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
"strings"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetBlockStorageInstanceListParams(reqParams *RequestBlockStorageInstanceList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if reqParams.ServerInstanceNo != "" {
params["serverInstanceNo"] = reqParams.ServerInstanceNo
}
if len(reqParams.BlockStorageInstanceNoList) > 0 {
for k, v := range reqParams.BlockStorageInstanceNoList {
params[fmt.Sprintf("blockStorageInstanceNoList.%d", k+1)] = v
}
}
if reqParams.SearchFilterName != "" {
if reqParams.SearchFilterName != "blockStorageName" && reqParams.SearchFilterName != "attachmentInformation" {
return nil, errors.New("SearchFilterName should be blockStorageName or attachmentInformation")
}
params["searchFilterName"] = reqParams.SearchFilterName
}
if reqParams.SearchFilterValue == "" {
params["searchFilterValue"] = reqParams.SearchFilterValue
}
if len(reqParams.BlockStorageTypeCodeList) > 0 {
for k, v := range reqParams.BlockStorageTypeCodeList {
if v != "BASIC" && v != "SVRBS" {
return nil, errors.New("BlockStorageTypeCodeList value should be BASIC or SVRBS")
}
params[fmt.Sprintf("blockStorageTypeCodeList.%d", k+1)] = v
}
}
if reqParams.PageNo != 0 {
if reqParams.PageNo > 2147483647 {
return nil, errors.New("PageNo should be up to 2147483647")
}
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize != 0 {
if reqParams.PageSize > 2147483647 {
return nil, errors.New("PageSize should be up to 2147483647")
}
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
if reqParams.BlockStorageInstanceStatusCode != "" {
if reqParams.BlockStorageInstanceStatusCode != "ATTAC" && reqParams.BlockStorageInstanceStatusCode != "CRAET" {
return nil, errors.New("BlockStorageInstanceStatusCode should be ATTAC or CRAET")
}
params["blockStorageInstanceStatusCode"] = reqParams.BlockStorageInstanceStatusCode
}
if reqParams.DiskTypeCode != "" {
if reqParams.DiskTypeCode != "NET" && reqParams.DiskTypeCode != "LOCAL" {
return nil, errors.New("DiskTypeCode should be NET or LOCAL")
}
params["diskTypeCode"] = reqParams.DiskTypeCode
}
if reqParams.DiskDetailTypeCode != "" {
if reqParams.DiskDetailTypeCode != "HDD" && reqParams.DiskDetailTypeCode != "SSD" {
return nil, errors.New("DiskDetailTypeCode should be HDD or SSD")
}
params["diskDetailTypeCode"] = reqParams.DiskDetailTypeCode
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
if reqParams.SortedBy != "" {
if strings.EqualFold(reqParams.SortedBy, "blockStorageName") || strings.EqualFold(reqParams.SortedBy, "blockStorageInstanceNo") {
params["sortedBy"] = reqParams.SortedBy
} else {
return nil, errors.New("SortedBy should be blockStorageName or blockStorageInstanceNo")
}
}
if reqParams.SortingOrder != "" {
if strings.EqualFold(reqParams.SortingOrder, "ascending") || strings.EqualFold(reqParams.SortingOrder, "descending") {
params["sortingOrder"] = reqParams.SortingOrder
} else {
return nil, errors.New("SortingOrder should be ascending or descending")
}
}
return params, nil
}
// GetBlockStorageInstance Get block storage instance list
func (s *Conn) GetBlockStorageInstance(reqParams *RequestBlockStorageInstanceList) (*BlockStorageInstanceList, error) {
params, err := processGetBlockStorageInstanceListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getBlockStorageInstanceList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := BlockStorageInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var blockStorageInstanceList = BlockStorageInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &blockStorageInstanceList); err != nil {
return nil, err
}
return &blockStorageInstanceList, nil
}

View File

@ -0,0 +1,77 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetLoginKeyListParams(reqParams *RequestGetLoginKeyList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if reqParams.KeyName != "" {
if len := len(reqParams.KeyName); len < 3 || len > 20 {
return nil, errors.New("Length of KeyName should be min 3 or max 30")
}
params["keyName"] = reqParams.KeyName
}
if reqParams.PageNo > 0 {
if reqParams.PageNo > 2147483647 {
return nil, errors.New("PageNo should be min 0 or max 2147483647")
}
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize > 0 {
if reqParams.PageSize > 2147483647 {
return nil, errors.New("PageSize should be min 0 or max 2147483647")
}
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
return params, nil
}
// GetLoginKeyList get login key list
func (s *Conn) GetLoginKeyList(reqParams *RequestGetLoginKeyList) (*LoginKeyList, error) {
params, err := processGetLoginKeyListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getLoginKeyList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := LoginKeyList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
loginKeyList := LoginKeyList{}
if err := xml.Unmarshal([]byte(bytes), &loginKeyList); err != nil {
return nil, err
}
return &loginKeyList, nil
}

View File

@ -0,0 +1,87 @@
package sdk
import (
"encoding/xml"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetMemberServerImageListParams(reqParams *RequestServerImageList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if len(reqParams.MemberServerImageNoList) > 0 {
for k, v := range reqParams.MemberServerImageNoList {
params[fmt.Sprintf("memberServerImageNoList.%d", k+1)] = v
}
}
if len(reqParams.PlatformTypeCodeList) > 0 {
for k, v := range reqParams.PlatformTypeCodeList {
params[fmt.Sprintf("platformTypeCodeList.%d", k+1)] = v
}
}
if reqParams.PageNo != 0 {
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize != 0 {
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
if reqParams.SortedBy != "" {
params["sortedBy"] = reqParams.SortedBy
}
if reqParams.SortingOrder != "" {
params["sortingOrder"] = reqParams.SortingOrder
}
return params, nil
}
// GetMemberServerImageList get member server image list
func (s *Conn) GetMemberServerImageList(reqParams *RequestServerImageList) (*MemberServerImageList, error) {
params, err := processGetMemberServerImageListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getMemberServerImageList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := MemberServerImageList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var serverImageListsResp = MemberServerImageList{}
if err := xml.Unmarshal([]byte(bytes), &serverImageListsResp); err != nil {
return nil, err
}
return &serverImageListsResp, nil
}

View File

@ -0,0 +1,130 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
"strings"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetPublicIPInstanceListParams(reqParams *RequestPublicIPInstanceList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if reqParams.IsAssociated {
params["isAssociated"] = "true"
}
if len(reqParams.PublicIPInstanceNoList) > 0 {
for k, v := range reqParams.PublicIPInstanceNoList {
params[fmt.Sprintf("publicIpInstanceNoList.%d", k+1)] = v
}
}
if len(reqParams.PublicIPList) > 0 {
for k, v := range reqParams.PublicIPList {
if len(reqParams.PublicIPList) < 5 || len(reqParams.PublicIPList) > 15 {
return nil, errors.New("PublicIPList must be between 5 and 15 characters in length")
}
params[fmt.Sprintf("publicIpList.%d", k+1)] = v
}
}
if reqParams.SearchFilterName != "" {
if reqParams.SearchFilterName != "publicIp" && reqParams.SearchFilterName != "associatedServerName" {
return nil, errors.New("SearchFilterName must be publicIp or associatedServerName")
}
params["searchFilterName"] = reqParams.SearchFilterName
}
if reqParams.SearchFilterValue != "" {
params["searchFilterValue"] = reqParams.SearchFilterValue
}
if reqParams.InternetLineTypeCode != "" {
if reqParams.InternetLineTypeCode != "PUBLC" && reqParams.InternetLineTypeCode != "GLBL" {
return params, errors.New("InternetLineTypeCode must be PUBLC or GLBL")
}
params["internetLineTypeCode"] = reqParams.InternetLineTypeCode
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
if reqParams.PageNo != 0 {
if reqParams.PageNo > 2147483647 {
return nil, errors.New("PageNo must be up to 2147483647")
}
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize != 0 {
if reqParams.PageSize > 2147483647 {
return nil, errors.New("PageSize must be up to 2147483647")
}
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
if reqParams.SortedBy != "" {
if strings.EqualFold(reqParams.SortedBy, "publicIp") || strings.EqualFold(reqParams.SortedBy, "publicIpInstanceNo") {
params["sortedBy"] = reqParams.SortedBy
} else {
return nil, errors.New("SortedBy must be publicIp or publicIpInstanceNo")
}
}
if reqParams.SortingOrder != "" {
if strings.EqualFold(reqParams.SortingOrder, "ascending") || strings.EqualFold(reqParams.SortingOrder, "descending") {
params["sortingOrder"] = reqParams.SortingOrder
} else {
return nil, errors.New("SortingOrder must be ascending or descending")
}
}
return params, nil
}
// GetPublicIPInstanceList get public ip instance list
func (s *Conn) GetPublicIPInstanceList(reqParams *RequestPublicIPInstanceList) (*PublicIPInstanceList, error) {
params, err := processGetPublicIPInstanceListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getPublicIpInstanceList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := PublicIPInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var publicIPInstanceList = PublicIPInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &publicIPInstanceList); err != nil {
return nil, err
}
return &publicIPInstanceList, nil
}

View File

@ -0,0 +1,40 @@
package sdk
import (
"encoding/xml"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
// GetRegionList gets region list
func (s *Conn) GetRegionList() (*RegionList, error) {
params := make(map[string]string)
params["action"] = "getRegionList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := RegionList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
regionList := RegionList{}
if err := xml.Unmarshal([]byte(bytes), &regionList); err != nil {
return nil, err
}
return &regionList, nil
}

View File

@ -0,0 +1,67 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strings"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetRootPasswordParams(reqParams *RequestGetRootPassword) (map[string]string, error) {
params := make(map[string]string)
if reqParams.ServerInstanceNo == "" {
return params, errors.New("Required field is not specified. location : serverInstanceNo")
}
if reqParams.PrivateKey == "" {
return params, errors.New("Required field is not specified. location : privateKey")
}
params["serverInstanceNo"] = reqParams.ServerInstanceNo
params["privateKey"] = reqParams.PrivateKey
return params, nil
}
// GetRootPassword get root password from server instance
func (s *Conn) GetRootPassword(reqParams *RequestGetRootPassword) (*RootPassword, error) {
params, err := processGetRootPasswordParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getRootPassword"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := RootPassword{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
responseGetRootPassword := RootPassword{}
if err := xml.Unmarshal([]byte(bytes), &responseGetRootPassword); err != nil {
return nil, err
}
if responseGetRootPassword.RootPassword != "" {
responseGetRootPassword.RootPassword = strings.TrimSpace(responseGetRootPassword.RootPassword)
}
return &responseGetRootPassword, nil
}

View File

@ -0,0 +1,88 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetServerImageProductListParams(reqParams *RequestGetServerImageProductList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if reqParams.ExclusionProductCode != "" {
if len(reqParams.ExclusionProductCode) > 20 {
return params, errors.New("Length of exclusionProductCode should be max 20")
}
params["exclusionProductCode"] = reqParams.ExclusionProductCode
}
if reqParams.ProductCode != "" {
if len(reqParams.ProductCode) > 20 {
return params, errors.New("Length of productCode should be max 20")
}
params["productCode"] = reqParams.ProductCode
}
if len(reqParams.PlatformTypeCodeList) > 0 {
for k, v := range reqParams.PlatformTypeCodeList {
params[fmt.Sprintf("platformTypeCodeList.%d", k+1)] = v
}
}
if reqParams.BlockStorageSize > 0 {
if reqParams.BlockStorageSize != 50 && reqParams.BlockStorageSize != 100 {
return nil, errors.New("blockStorageSize should be null, 50 or 100")
}
params["blockStorageSize"] = strconv.Itoa(reqParams.BlockStorageSize)
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
return params, nil
}
// GetServerImageProductList gets server image product list
func (s *Conn) GetServerImageProductList(reqParams *RequestGetServerImageProductList) (*ProductList, error) {
params, err := processGetServerImageProductListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getServerImageProductList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ProductList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var productList = ProductList{}
if err := xml.Unmarshal([]byte(bytes), &productList); err != nil {
fmt.Println(err)
return nil, err
}
return &productList, nil
}

View File

@ -0,0 +1,133 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
"strconv"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetServerInstanceListParams(reqParams *RequestGetServerInstanceList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil {
return params, nil
}
if len(reqParams.ServerInstanceNoList) > 0 {
for k, v := range reqParams.ServerInstanceNoList {
params[fmt.Sprintf("serverInstanceNoList.%d", k+1)] = v
}
}
if reqParams.SearchFilterName != "" {
params["searchFilterName"] = reqParams.SearchFilterName
}
if reqParams.SearchFilterValue != "" {
params["searchFilterValue"] = reqParams.SearchFilterValue
}
if reqParams.PageNo > 0 {
if reqParams.PageNo > 2147483647 {
return nil, errors.New("PageNo should be less than 2147483647")
}
params["pageNo"] = strconv.Itoa(reqParams.PageNo)
}
if reqParams.PageSize > 0 {
if reqParams.PageSize > 2147483647 {
return nil, errors.New("PageSize should be less than 2147483647")
}
params["pageSize"] = strconv.Itoa(reqParams.PageSize)
}
if reqParams.ServerInstanceStatusCode != "" {
if reqParams.ServerInstanceStatusCode != "RUN" && reqParams.ServerInstanceStatusCode != "NSTOP" && reqParams.ServerInstanceStatusCode != "ING" {
return nil, errors.New("ServerInstanceStatusCode should be RUN, NSTOP or ING")
}
params["serverInstanceStatusCode"] = reqParams.ServerInstanceStatusCode
}
if reqParams.InternetLineTypeCode != "" {
if reqParams.InternetLineTypeCode != "PUBLC" && reqParams.InternetLineTypeCode != "GLBL" {
return nil, errors.New("InternetLineTypeCode should be PUBLC or GLBL")
}
params["internetLineTypeCode"] = reqParams.InternetLineTypeCode
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
if reqParams.BaseBlockStorageDiskTypeCode != "" {
if reqParams.BaseBlockStorageDiskTypeCode != "NET" && reqParams.BaseBlockStorageDiskTypeCode != "LOCAL" {
return nil, errors.New("BaseBlockStorageDiskTypeCode should be NET or LOCAL")
}
params["baseBlockStorageDiskTypeCode"] = reqParams.BaseBlockStorageDiskTypeCode
}
if reqParams.BaseBlockStorageDiskDetailTypeCode != "" {
if reqParams.BaseBlockStorageDiskDetailTypeCode != "HDD" && reqParams.BaseBlockStorageDiskDetailTypeCode != "SSD" {
return nil, errors.New("BaseBlockStorageDiskDetailTypeCode should be HDD or SSD")
}
params["baseBlockStorageDiskDetailTypeCode"] = reqParams.BaseBlockStorageDiskDetailTypeCode
}
if reqParams.SortedBy != "" {
if reqParams.SortedBy != "serverName" && reqParams.SortedBy != "serverInstanceNo" {
return nil, errors.New("SortedBy should be serverName or serverInstanceNo")
}
params["sortedBy"] = reqParams.SortedBy
}
if reqParams.SortingOrder != "" {
if reqParams.SortingOrder != "ascending" && reqParams.SortingOrder != "descending" {
return nil, errors.New("SortingOrder should be ascending or descending")
}
params["sortingOrder"] = reqParams.SortingOrder
}
return params, nil
}
// GetServerInstanceList get server instance list
func (s *Conn) GetServerInstanceList(reqParams *RequestGetServerInstanceList) (*ServerInstanceList, error) {
params, err := processGetServerInstanceListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getServerInstanceList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ServerInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var serverInstanceList = ServerInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &serverInstanceList); err != nil {
fmt.Println(err)
return nil, err
}
return &serverInstanceList, nil
}

View File

@ -0,0 +1,79 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processGetServerProductListParams(reqParams *RequestGetServerProductList) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil || reqParams.ServerImageProductCode == "" {
return params, errors.New("ServerImageProductCode field is required")
}
if len(reqParams.ServerImageProductCode) > 20 {
return params, errors.New("Length of serverImageProductCode should be max 20")
}
params["serverImageProductCode"] = reqParams.ServerImageProductCode
if reqParams.ExclusionProductCode != "" {
if len(reqParams.ExclusionProductCode) > 20 {
return params, errors.New("Length of exclusionProductCode should be max 20")
}
params["exclusionProductCode"] = reqParams.ExclusionProductCode
}
if reqParams.ProductCode != "" {
if len(reqParams.ProductCode) > 20 {
return params, errors.New("Length of productCode should be max 20")
}
params["productCode"] = reqParams.ProductCode
}
if reqParams.RegionNo != "" {
params["regionNo"] = reqParams.RegionNo
}
return params, nil
}
// GetServerProductList : Get Server product list with server image product code by default.
func (s *Conn) GetServerProductList(reqParams *RequestGetServerProductList) (*ProductList, error) {
params, err := processGetServerProductListParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "getServerProductList"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ProductList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var productListResp = ProductList{}
if err := xml.Unmarshal([]byte(bytes), &productListResp); err != nil {
return nil, err
}
return &productListResp, nil
}

View File

@ -0,0 +1,44 @@
package sdk
import (
"encoding/xml"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
// GetZoneList get zone list
func (s *Conn) GetZoneList(regionNo string) (*ZoneList, error) {
params := make(map[string]string)
params["action"] = "getZoneList"
if regionNo != "" {
params["regionNo"] = regionNo
}
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ZoneList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
ZoneList := ZoneList{}
if err := xml.Unmarshal([]byte(bytes), &ZoneList); err != nil {
return nil, err
}
return &ZoneList, nil
}

View File

@ -0,0 +1,359 @@
package sdk
import (
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
)
type Conn struct {
accessKey string
secretKey string
apiURL string
}
// ServerImage structures
type ServerImage struct {
MemberServerImageNo string `xml:"memberServerImageNo"`
MemberServerImageName string `xml:"memberServerImageName"`
MemberServerImageDescription string `xml:"memberServerImageDescription"`
OriginalServerInstanceNo string `xml:"originalServerInstanceNo"`
OriginalServerProductCode string `xml:"originalServerProductCode"`
OriginalServerName string `xml:"originalServerName"`
OriginalBaseBlockStorageDiskType common.CommonCode `xml:"originalBaseBlockStorageDiskType"`
OriginalServerImageProductCode string `xml:"originalServerImageProductCode"`
OriginalOsInformation string `xml:"originalOsInformation"`
OriginalServerImageName string `xml:"originalServerImageName"`
MemberServerImageStatusName string `xml:"memberServerImageStatusName"`
MemberServerImageStatus common.CommonCode `xml:"memberServerImageStatus"`
MemberServerImageOperation common.CommonCode `xml:"memberServerImageOperation"`
MemberServerImagePlatformType common.CommonCode `xml:"memberServerImagePlatformType"`
CreateDate string `xml:"createDate"`
Zone common.Zone `xml:"zone"`
Region common.Region `xml:"region"`
MemberServerImageBlockStorageTotalRows int `xml:"memberServerImageBlockStorageTotalRows"`
MemberServerImageBlockStorageTotalSize int `xml:"memberServerImageBlockStorageTotalSize"`
}
type MemberServerImageList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
MemberServerImageList []ServerImage `xml:"memberServerImageList>memberServerImage,omitempty"`
}
type RequestServerImageList struct {
MemberServerImageNoList []string
PlatformTypeCodeList []string
PageNo int
PageSize int
RegionNo string
SortedBy string
SortingOrder string
}
type RequestCreateServerImage struct {
MemberServerImageName string
MemberServerImageDescription string
ServerInstanceNo string
}
type RequestGetServerImageProductList struct {
ExclusionProductCode string
ProductCode string
PlatformTypeCodeList []string
BlockStorageSize int
RegionNo string
}
// ProductList : Response of server product list
type ProductList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
Product []Product `xml:"productList>product,omitempty"`
}
// Product : Product information of Server
type Product struct {
ProductCode string `xml:"productCode"`
ProductName string `xml:"productName"`
ProductType common.CommonCode `xml:"productType"`
ProductDescription string `xml:"productDescription"`
InfraResourceType common.CommonCode `xml:"infraResourceType"`
CPUCount int `xml:"cpuCount"`
MemorySize int `xml:"memorySize"`
BaseBlockStorageSize int `xml:"baseBlockStorageSize"`
PlatformType common.CommonCode `xml:"platformType"`
OsInformation string `xml:"osInformation"`
AddBlockStroageSize int `xml:"addBlockStroageSize"`
}
// RequestCreateServerInstance is Server Instances structures
type RequestCreateServerInstance struct {
ServerImageProductCode string
ServerProductCode string
MemberServerImageNo string
ServerName string
ServerDescription string
LoginKeyName string
IsProtectServerTermination bool
ServerCreateCount int
ServerCreateStartNo int
InternetLineTypeCode string
FeeSystemTypeCode string
UserData string
ZoneNo string
AccessControlGroupConfigurationNoList []string
}
type ServerInstanceList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
ServerInstanceList []ServerInstance `xml:"serverInstanceList>serverInstance,omitempty"`
}
type ServerInstance struct {
ServerInstanceNo string `xml:"serverInstanceNo"`
ServerName string `xml:"serverName"`
ServerDescription string `xml:"serverDescription"`
CPUCount int `xml:"cpuCount"`
MemorySize int `xml:"memorySize"`
BaseBlockStorageSize int `xml:"baseBlockStorageSize"`
PlatformType common.CommonCode `xml:"platformType"`
LoginKeyName string `xml:"loginKeyName"`
IsFeeChargingMonitoring bool `xml:"isFeeChargingMonitoring"`
PublicIP string `xml:"publicIp"`
PrivateIP string `xml:"privateIp"`
ServerImageName string `xml:"serverImageName"`
ServerInstanceStatus common.CommonCode `xml:"serverInstanceStatus"`
ServerInstanceOperation common.CommonCode `xml:"serverInstanceOperation"`
ServerInstanceStatusName string `xml:"serverInstanceStatusName"`
CreateDate string `xml:"createDate"`
Uptime string `xml:"uptime"`
ServerImageProductCode string `xml:"serverImageProductCode"`
ServerProductCode string `xml:"serverProductCode"`
IsProtectServerTermination bool `xml:"isProtectServerTermination"`
PortForwardingPublicIP string `xml:"portForwardingPublicIp"`
PortForwardingExternalPort int `xml:"portForwardingExternalPort"`
PortForwardingInternalPort int `xml:"portForwardingInternalPort"`
Zone common.Zone `xml:"zone"`
Region common.Region `xml:"region"`
BaseBlockStorageDiskType common.CommonCode `xml:"baseBlockStorageDiskType"`
BaseBlockStroageDiskDetailType common.CommonCode `xml:"baseBlockStroageDiskDetailType"`
InternetLineType common.CommonCode `xml:"internetLineType"`
UserData string `xml:"userData"`
AccessControlGroupList []AccessControlGroup `xml:"accessControlGroupList>accessControlGroup"`
}
type AccessControlGroup struct {
AccessControlGroupConfigurationNo string `xml:"accessControlGroupConfigurationNo"`
AccessControlGroupName string `xml:"accessControlGroupName"`
AccessControlGroupDescription string `xml:"accessControlGroupDescription"`
IsDefault bool `xml:"isDefault"`
CreateDate string `xml:"createDate"`
}
// RequestGetLoginKeyList is Login Key structures
type RequestGetLoginKeyList struct {
KeyName string
PageNo int
PageSize int
}
type LoginKeyList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
LoginKeyList []LoginKey `xml:"loginKeyList>loginKey,omitempty"`
}
type LoginKey struct {
Fingerprint string `xml:"fingerprint"`
KeyName string `xml:"keyName"`
CreateDate string `xml:"createDate"`
}
type PrivateKey struct {
common.CommonResponse
PrivateKey string `xml:"privateKey"`
}
type RequestCreatePublicIPInstance struct {
ServerInstanceNo string
PublicIPDescription string
InternetLineTypeCode string
RegionNo string
}
type RequestPublicIPInstanceList struct {
IsAssociated bool
PublicIPInstanceNoList []string
PublicIPList []string
SearchFilterName string
SearchFilterValue string
InternetLineTypeCode string
RegionNo string
PageNo int
PageSize int
SortedBy string
SortingOrder string
}
type PublicIPInstanceList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
PublicIPInstanceList []PublicIPInstance `xml:"publicIpInstanceList>publicIpInstance,omitempty"`
}
type PublicIPInstance struct {
PublicIPInstanceNo string `xml:"publicIpInstanceNo"`
PublicIP string `xml:"publicIp"`
PublicIPDescription string `xml:"publicIpDescription"`
CreateDate string `xml:"createDate"`
InternetLineType common.CommonCode `xml:"internetLineType"`
PublicIPInstanceStatusName string `xml:"publicIpInstanceStatusName"`
PublicIPInstanceStatus common.CommonCode `xml:"publicIpInstanceStatus"`
PublicIPInstanceOperation common.CommonCode `xml:"publicIpInstanceOperation"`
PublicIPKindType common.CommonCode `xml:"publicIpKindType"`
ServerInstance ServerInstance `xml:"serverInstanceAssociatedWithPublicIp"`
}
type RequestDeletePublicIPInstances struct {
PublicIPInstanceNoList []string
}
// RequestGetServerInstanceList : Get Server Instance List
type RequestGetServerInstanceList struct {
ServerInstanceNoList []string
SearchFilterName string
SearchFilterValue string
PageNo int
PageSize int
ServerInstanceStatusCode string
InternetLineTypeCode string
RegionNo string
BaseBlockStorageDiskTypeCode string
BaseBlockStorageDiskDetailTypeCode string
SortedBy string
SortingOrder string
}
type RequestStopServerInstances struct {
ServerInstanceNoList []string
}
type RequestTerminateServerInstances struct {
ServerInstanceNoList []string
}
// RequestGetRootPassword : Request to get root password of the server
type RequestGetRootPassword struct {
ServerInstanceNo string
PrivateKey string
}
// RootPassword : Response of getting root password of the server
type RootPassword struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
RootPassword string `xml:"rootPassword"`
}
// RequestGetZoneList : Request to get zone list
type RequestGetZoneList struct {
regionNo string
}
// ZoneList : Response of getting zone list
type ZoneList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
Zone []common.Zone `xml:"zoneList>zone"`
}
// RegionList : Response of getting region list
type RegionList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
RegionList []common.Region `xml:"regionList>region,omitempty"`
}
type RequestBlockStorageInstance struct {
BlockStorageName string
BlockStorageSize int
BlockStorageDescription string
ServerInstanceNo string
}
type RequestBlockStorageInstanceList struct {
ServerInstanceNo string
BlockStorageInstanceNoList []string
SearchFilterName string
SearchFilterValue string
BlockStorageTypeCodeList []string
PageNo int
PageSize int
BlockStorageInstanceStatusCode string
DiskTypeCode string
DiskDetailTypeCode string
RegionNo string
SortedBy string
SortingOrder string
}
type BlockStorageInstanceList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
BlockStorageInstance []BlockStorageInstance `xml:"blockStorageInstanceList>blockStorageInstance,omitempty"`
}
type BlockStorageInstance struct {
BlockStorageInstanceNo string `xml:"blockStorageInstanceNo"`
ServerInstanceNo string `xml:"serverInstanceNo"`
ServerName string `xml:"serverName"`
BlockStorageType common.CommonCode `xml:"blockStorageType"`
BlockStorageName string `xml:"blockStorageName"`
BlockStorageSize int `xml:"blockStorageSize"`
DeviceName string `xml:"deviceName"`
BlockStorageProductCode string `xml:"blockStorageProductCode"`
BlockStorageInstanceStatus common.CommonCode `xml:"blockStorageInstanceStatus"`
BlockStorageInstanceOperation common.CommonCode `xml:"blockStorageInstanceOperation"`
BlockStorageInstanceStatusName string `xml:"blockStorageInstanceStatusName"`
CreateDate string `xml:"createDate"`
BlockStorageInstanceDescription string `xml:"blockStorageInstanceDescription"`
DiskType common.CommonCode `xml:"diskType"`
DiskDetailType common.CommonCode `xml:"diskDetailType"`
}
// RequestGetServerProductList : Request to get server product list
type RequestGetServerProductList struct {
ExclusionProductCode string
ProductCode string
ServerImageProductCode string
RegionNo string
}
type RequestAccessControlGroupList struct {
AccessControlGroupConfigurationNoList []string
IsDefault bool
AccessControlGroupName string
PageNo int
PageSize int
}
type AccessControlGroupList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
AccessControlGroup []AccessControlGroup `xml:"accessControlGroupList>accessControlGroup,omitempty"`
}
type AccessControlRuleList struct {
common.CommonResponse
TotalRows int `xml:"totalRows"`
AccessControlRuleList []AccessControlRule `xml:"accessControlRuleList>accessControlRule,omitempty"`
}
type AccessControlRule struct {
AccessControlRuleConfigurationNo string `xml:"accessControlRuleConfigurationNo"`
AccessControlRuleDescription string `xml:"accessControlRuleDescription"`
SourceAccessControlRuleConfigurationNo string `xml:"sourceAccessControlRuleConfigurationNo"`
SourceAccessControlRuleName string `xml:"sourceAccessControlRuleName"`
ProtocolType common.CommonCode `xml:"protocolType"`
SourceIP string `xml:"sourceIp"`
DestinationPort string `xml:"destinationPort"`
}

View File

@ -0,0 +1,62 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processStopServerInstancesParams(reqParams *RequestStopServerInstances) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil || len(reqParams.ServerInstanceNoList) == 0 {
return params, errors.New("serverInstanceNoList is required")
}
if len(reqParams.ServerInstanceNoList) > 0 {
for k, v := range reqParams.ServerInstanceNoList {
params[fmt.Sprintf("serverInstanceNoList.%d", k+1)] = v
}
}
return params, nil
}
// StopServerInstances stop server instances
func (s *Conn) StopServerInstances(reqParams *RequestStopServerInstances) (*ServerInstanceList, error) {
params, err := processStopServerInstancesParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "stopServerInstances"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ServerInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var serverInstanceList = ServerInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &serverInstanceList); err != nil {
fmt.Println(err)
return nil, err
}
return &serverInstanceList, nil
}

View File

@ -0,0 +1,62 @@
package sdk
import (
"encoding/xml"
"errors"
"fmt"
common "github.com/NaverCloudPlatform/ncloud-sdk-go/common"
request "github.com/NaverCloudPlatform/ncloud-sdk-go/request"
)
func processTerminateServerInstancesParams(reqParams *RequestTerminateServerInstances) (map[string]string, error) {
params := make(map[string]string)
if reqParams == nil || len(reqParams.ServerInstanceNoList) == 0 {
return params, errors.New("serverInstanceNoList is required")
}
if len(reqParams.ServerInstanceNoList) > 0 {
for k, v := range reqParams.ServerInstanceNoList {
params[fmt.Sprintf("serverInstanceNoList.%d", k+1)] = v
}
}
return params, nil
}
// TerminateServerInstances terminate server instances
func (s *Conn) TerminateServerInstances(reqParams *RequestTerminateServerInstances) (*ServerInstanceList, error) {
params, err := processTerminateServerInstancesParams(reqParams)
if err != nil {
return nil, err
}
params["action"] = "terminateServerInstances"
bytes, resp, err := request.NewRequest(s.accessKey, s.secretKey, "GET", s.apiURL+"server/", params)
if err != nil {
return nil, err
}
if resp.StatusCode != 200 {
responseError, err := common.ParseErrorResponse(bytes)
if err != nil {
return nil, err
}
respError := ServerInstanceList{}
respError.ReturnCode = responseError.ReturnCode
respError.ReturnMessage = responseError.ReturnMessage
return &respError, fmt.Errorf("%s %s - error code: %d , error message: %s", resp.Status, string(bytes), responseError.ReturnCode, responseError.ReturnMessage)
}
var serverInstanceList = ServerInstanceList{}
if err := xml.Unmarshal([]byte(bytes), &serverInstanceList); err != nil {
fmt.Println(err)
return nil, err
}
return &serverInstanceList, nil
}

24
vendor/vendor.json vendored
View File

@ -209,6 +209,30 @@
"revision": "4fe03583929022c9c96829401ffabc755e69782e",
"revisionTime": "2017-06-25T21:53:50Z"
},
{
"checksumSHA1": "N0jIjg2HeB8fM7dt8OED2BiRZz0=",
"path": "github.com/NaverCloudPlatform/ncloud-sdk-go/common",
"revision": "c2e73f942591b0f033a3c6df00f44badb2347c38",
"revisionTime": "2018-01-10T05:50:12Z"
},
{
"checksumSHA1": "7lT5Xmeo2MhE6CJvIInZyLBu6S8=",
"path": "github.com/NaverCloudPlatform/ncloud-sdk-go/oauth",
"revision": "c2e73f942591b0f033a3c6df00f44badb2347c38",
"revisionTime": "2018-01-10T05:50:12Z"
},
{
"checksumSHA1": "DpfU1gyyhIc1BuKZUZDRVDBkeSc=",
"path": "github.com/NaverCloudPlatform/ncloud-sdk-go/request",
"revision": "c2e73f942591b0f033a3c6df00f44badb2347c38",
"revisionTime": "2018-01-10T05:50:12Z"
},
{
"checksumSHA1": "QnZ2RMlms/zYbD8jg+lyS8ncQOY=",
"path": "github.com/NaverCloudPlatform/ncloud-sdk-go/sdk",
"revision": "c2e73f942591b0f033a3c6df00f44badb2347c38",
"revisionTime": "2018-01-10T05:50:12Z"
},
{
"checksumSHA1": "HttiPj314X1a0i2Jen1p6lRH/vE=",
"path": "github.com/aliyun/aliyun-oss-go-sdk/oss",