| 1 |
package ecs |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/base64" |
| 5 |
"encoding/json" |
| 6 |
"strconv" |
| 7 |
"time" |
| 8 |
|
| 9 |
"github.com/denverdino/aliyungo/common" |
| 10 |
"github.com/denverdino/aliyungo/util" |
| 11 |
) |
| 12 |
|
| 13 |
|
| 14 |
type InstanceStatus string |
| 15 |
|
| 16 |
|
| 17 |
const ( |
| 18 |
Creating = InstanceStatus("Creating") |
| 19 |
Pending = InstanceStatus("Pending") |
| 20 |
Running = InstanceStatus("Running") |
| 21 |
Starting = InstanceStatus("Starting") |
| 22 |
|
| 23 |
Stopped = InstanceStatus("Stopped") |
| 24 |
Stopping = InstanceStatus("Stopping") |
| 25 |
Deleted = InstanceStatus("Deleted") |
| 26 |
) |
| 27 |
|
| 28 |
type LockReason string |
| 29 |
|
| 30 |
const ( |
| 31 |
LockReasonFinancial = LockReason("financial") |
| 32 |
LockReasonSecurity = LockReason("security") |
| 33 |
) |
| 34 |
|
| 35 |
type LockReasonType struct { |
| 36 |
LockReason LockReason |
| 37 |
} |
| 38 |
|
| 39 |
type DescribeUserdataArgs struct { |
| 40 |
RegionId common.Region |
| 41 |
InstanceId string |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
type DescribeUserdataItemType struct { |
| 47 |
UserData string |
| 48 |
InstanceId string |
| 49 |
RegionId string |
| 50 |
} |
| 51 |
|
| 52 |
type DescribeUserdataResponse struct { |
| 53 |
common.Response |
| 54 |
DescribeUserdataItemType |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
func (client *Client) DescribeUserdata(args *DescribeUserdataArgs) (userData *DescribeUserdataItemType, err error) { |
| 61 |
response := DescribeUserdataResponse{} |
| 62 |
|
| 63 |
err = client.Invoke("DescribeUserdata", args, &response) |
| 64 |
|
| 65 |
if err == nil { |
| 66 |
return &response.DescribeUserdataItemType, nil |
| 67 |
} |
| 68 |
|
| 69 |
return nil, err |
| 70 |
} |
| 71 |
|
| 72 |
type DescribeInstanceStatusArgs struct { |
| 73 |
RegionId common.Region |
| 74 |
ZoneId string |
| 75 |
common.Pagination |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
type InstanceStatusItemType struct { |
| 81 |
InstanceId string |
| 82 |
Status InstanceStatus |
| 83 |
} |
| 84 |
|
| 85 |
type DescribeInstanceStatusResponse struct { |
| 86 |
common.Response |
| 87 |
common.PaginationResult |
| 88 |
InstanceStatuses struct { |
| 89 |
InstanceStatus []InstanceStatusItemType |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
func (client *Client) DescribeInstanceStatus(args *DescribeInstanceStatusArgs) (instanceStatuses []InstanceStatusItemType, pagination *common.PaginationResult, err error) { |
| 97 |
response, err := client.DescribeInstanceStatusWithRaw(args) |
| 98 |
|
| 99 |
if err == nil { |
| 100 |
return response.InstanceStatuses.InstanceStatus, &response.PaginationResult, nil |
| 101 |
} |
| 102 |
|
| 103 |
return nil, nil, err |
| 104 |
} |
| 105 |
|
| 106 |
func (client *Client) DescribeInstanceStatusWithRaw(args *DescribeInstanceStatusArgs) (response *DescribeInstanceStatusResponse, err error) { |
| 107 |
args.Validate() |
| 108 |
response = &DescribeInstanceStatusResponse{} |
| 109 |
|
| 110 |
err = client.Invoke("DescribeInstanceStatus", args, response) |
| 111 |
if err != nil { |
| 112 |
return nil, err |
| 113 |
} |
| 114 |
|
| 115 |
return response, nil |
| 116 |
} |
| 117 |
|
| 118 |
type StopInstanceArgs struct { |
| 119 |
InstanceId string |
| 120 |
ForceStop bool |
| 121 |
} |
| 122 |
|
| 123 |
type StopInstanceResponse struct { |
| 124 |
common.Response |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
func (client *Client) StopInstance(instanceId string, forceStop bool) error { |
| 131 |
args := StopInstanceArgs{ |
| 132 |
InstanceId: instanceId, |
| 133 |
ForceStop: forceStop, |
| 134 |
} |
| 135 |
response := StopInstanceResponse{} |
| 136 |
err := client.Invoke("StopInstance", &args, &response) |
| 137 |
return err |
| 138 |
} |
| 139 |
|
| 140 |
type StartInstanceArgs struct { |
| 141 |
InstanceId string |
| 142 |
} |
| 143 |
|
| 144 |
type StartInstanceResponse struct { |
| 145 |
common.Response |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
func (client *Client) StartInstance(instanceId string) error { |
| 152 |
args := StartInstanceArgs{InstanceId: instanceId} |
| 153 |
response := StartInstanceResponse{} |
| 154 |
err := client.Invoke("StartInstance", &args, &response) |
| 155 |
return err |
| 156 |
} |
| 157 |
|
| 158 |
type RebootInstanceArgs struct { |
| 159 |
InstanceId string |
| 160 |
ForceStop bool |
| 161 |
} |
| 162 |
|
| 163 |
type RebootInstanceResponse struct { |
| 164 |
common.Response |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
func (client *Client) RebootInstance(instanceId string, forceStop bool) error { |
| 171 |
request := RebootInstanceArgs{ |
| 172 |
InstanceId: instanceId, |
| 173 |
ForceStop: forceStop, |
| 174 |
} |
| 175 |
response := RebootInstanceResponse{} |
| 176 |
err := client.Invoke("RebootInstance", &request, &response) |
| 177 |
return err |
| 178 |
} |
| 179 |
|
| 180 |
type DescribeInstanceAttributeArgs struct { |
| 181 |
InstanceId string |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
type OperationLocksType struct { |
| 187 |
LockReason []LockReasonType |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
type SecurityGroupIdSetType struct { |
| 193 |
SecurityGroupId string |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
type IpAddressSetType struct { |
| 199 |
IpAddress []string |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
type VpcAttributesType struct { |
| 205 |
VpcId string |
| 206 |
VSwitchId string |
| 207 |
PrivateIpAddress IpAddressSetType |
| 208 |
NatIpAddress string |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
type EipAddressAssociateType struct { |
| 214 |
AllocationId string |
| 215 |
IpAddress string |
| 216 |
Bandwidth int |
| 217 |
InternetChargeType common.InternetChargeType |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
type SpotStrategyType string |
| 222 |
|
| 223 |
|
| 224 |
const ( |
| 225 |
NoSpot = SpotStrategyType("NoSpot") |
| 226 |
SpotWithPriceLimit = SpotStrategyType("SpotWithPriceLimit") |
| 227 |
SpotAsPriceGo = SpotStrategyType("SpotAsPriceGo") |
| 228 |
) |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
type InstanceAttributesType struct { |
| 233 |
InstanceId string |
| 234 |
InstanceName string |
| 235 |
Description string |
| 236 |
ImageId string |
| 237 |
RegionId common.Region |
| 238 |
ZoneId string |
| 239 |
CPU int |
| 240 |
Memory int |
| 241 |
ClusterId string |
| 242 |
InstanceType string |
| 243 |
InstanceTypeFamily string |
| 244 |
HostName string |
| 245 |
SerialNumber string |
| 246 |
Status InstanceStatus |
| 247 |
OperationLocks OperationLocksType |
| 248 |
SecurityGroupIds struct { |
| 249 |
SecurityGroupId []string |
| 250 |
} |
| 251 |
PublicIpAddress IpAddressSetType |
| 252 |
InnerIpAddress IpAddressSetType |
| 253 |
InstanceNetworkType string |
| 254 |
InternetMaxBandwidthIn int |
| 255 |
InternetMaxBandwidthOut int |
| 256 |
InternetChargeType common.InternetChargeType |
| 257 |
CreationTime util.ISO6801Time |
| 258 |
VpcAttributes VpcAttributesType |
| 259 |
EipAddress EipAddressAssociateType |
| 260 |
IoOptimized StringOrBool |
| 261 |
InstanceChargeType common.InstanceChargeType |
| 262 |
ExpiredTime util.ISO6801Time |
| 263 |
Tags struct { |
| 264 |
Tag []TagItemType |
| 265 |
} |
| 266 |
SpotStrategy SpotStrategyType |
| 267 |
SpotPriceLimit float64 |
| 268 |
KeyPairName string |
| 269 |
} |
| 270 |
|
| 271 |
type DescribeInstanceAttributeResponse struct { |
| 272 |
common.Response |
| 273 |
InstanceAttributesType |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
func (client *Client) DescribeInstanceAttribute(instanceId string) (instance *InstanceAttributesType, err error) { |
| 280 |
args := DescribeInstanceAttributeArgs{InstanceId: instanceId} |
| 281 |
|
| 282 |
response := DescribeInstanceAttributeResponse{} |
| 283 |
err = client.Invoke("DescribeInstanceAttribute", &args, &response) |
| 284 |
if err != nil { |
| 285 |
return nil, err |
| 286 |
} |
| 287 |
return &response.InstanceAttributesType, err |
| 288 |
} |
| 289 |
|
| 290 |
type ModifyInstanceAttributeArgs struct { |
| 291 |
InstanceId string |
| 292 |
InstanceName string |
| 293 |
Description string |
| 294 |
Password string |
| 295 |
HostName string |
| 296 |
UserData string |
| 297 |
} |
| 298 |
|
| 299 |
type ModifyInstanceAttributeResponse struct { |
| 300 |
common.Response |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
func (client *Client) ModifyInstanceAttribute(args *ModifyInstanceAttributeArgs) error { |
| 307 |
response := ModifyInstanceAttributeResponse{} |
| 308 |
err := client.Invoke("ModifyInstanceAttribute", args, &response) |
| 309 |
return err |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
const InstanceDefaultTimeout = 120 |
| 314 |
|
| 315 |
|
| 316 |
func (client *Client) WaitForInstance(instanceId string, status InstanceStatus, timeout int) error { |
| 317 |
if timeout <= 0 { |
| 318 |
timeout = InstanceDefaultTimeout |
| 319 |
} |
| 320 |
for { |
| 321 |
instance, err := client.DescribeInstanceAttribute(instanceId) |
| 322 |
if err != nil { |
| 323 |
return err |
| 324 |
} |
| 325 |
if instance.Status == status { |
| 326 |
|
| 327 |
|
| 328 |
time.Sleep(DefaultWaitForInterval * time.Second) |
| 329 |
break |
| 330 |
} |
| 331 |
timeout = timeout - DefaultWaitForInterval |
| 332 |
if timeout <= 0 { |
| 333 |
return common.GetClientErrorFromString("Timeout") |
| 334 |
} |
| 335 |
time.Sleep(DefaultWaitForInterval * time.Second) |
| 336 |
|
| 337 |
} |
| 338 |
return nil |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
func (client *Client) WaitForInstanceAsyn(instanceId string, status InstanceStatus, timeout int) error { |
| 344 |
if timeout <= 0 { |
| 345 |
timeout = InstanceDefaultTimeout |
| 346 |
} |
| 347 |
for { |
| 348 |
instance, err := client.DescribeInstanceAttribute(instanceId) |
| 349 |
if err != nil { |
| 350 |
e, _ := err.(*common.Error) |
| 351 |
if e.Code != "InvalidInstanceId.NotFound" && e.Code != "Forbidden.InstanceNotFound" { |
| 352 |
return err |
| 353 |
} |
| 354 |
} else if instance != nil && instance.Status == status { |
| 355 |
|
| 356 |
break |
| 357 |
} |
| 358 |
timeout = timeout - DefaultWaitForInterval |
| 359 |
if timeout <= 0 { |
| 360 |
return common.GetClientErrorFromString("Timeout") |
| 361 |
} |
| 362 |
time.Sleep(DefaultWaitForInterval * time.Second) |
| 363 |
|
| 364 |
} |
| 365 |
return nil |
| 366 |
} |
| 367 |
|
| 368 |
type DescribeInstanceVncUrlArgs struct { |
| 369 |
RegionId common.Region |
| 370 |
InstanceId string |
| 371 |
} |
| 372 |
|
| 373 |
type DescribeInstanceVncUrlResponse struct { |
| 374 |
common.Response |
| 375 |
VncUrl string |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
func (client *Client) DescribeInstanceVncUrl(args *DescribeInstanceVncUrlArgs) (string, error) { |
| 381 |
response := DescribeInstanceVncUrlResponse{} |
| 382 |
|
| 383 |
err := client.Invoke("DescribeInstanceVncUrl", args, &response) |
| 384 |
|
| 385 |
if err == nil { |
| 386 |
return response.VncUrl, nil |
| 387 |
} |
| 388 |
|
| 389 |
return "", err |
| 390 |
} |
| 391 |
|
| 392 |
type DescribeInstancesArgs struct { |
| 393 |
RegionId common.Region |
| 394 |
VpcId string |
| 395 |
VSwitchId string |
| 396 |
ZoneId string |
| 397 |
InstanceIds string |
| 398 |
InstanceNetworkType string |
| 399 |
InstanceName string |
| 400 |
Status InstanceStatus |
| 401 |
PrivateIpAddresses string |
| 402 |
InnerIpAddresses string |
| 403 |
PublicIpAddresses string |
| 404 |
SecurityGroupId string |
| 405 |
Tag map[string]string |
| 406 |
InstanceType string |
| 407 |
SpotStrategy SpotStrategyType |
| 408 |
common.Pagination |
| 409 |
} |
| 410 |
|
| 411 |
type DescribeInstancesResponse struct { |
| 412 |
common.Response |
| 413 |
common.PaginationResult |
| 414 |
Instances struct { |
| 415 |
Instance []InstanceAttributesType |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
func (client *Client) DescribeInstances(args *DescribeInstancesArgs) (instances []InstanceAttributesType, pagination *common.PaginationResult, err error) { |
| 423 |
response, err := client.DescribeInstancesWithRaw(args) |
| 424 |
if err != nil { |
| 425 |
return nil, nil, err |
| 426 |
} |
| 427 |
|
| 428 |
return response.Instances.Instance, &response.PaginationResult, nil |
| 429 |
} |
| 430 |
|
| 431 |
func (client *Client) DescribeInstancesWithRaw(args *DescribeInstancesArgs) (response *DescribeInstancesResponse, err error) { |
| 432 |
args.Validate() |
| 433 |
response = &DescribeInstancesResponse{} |
| 434 |
|
| 435 |
err = client.Invoke("DescribeInstances", args, &response) |
| 436 |
if err != nil { |
| 437 |
return nil, err |
| 438 |
} |
| 439 |
|
| 440 |
return response, nil |
| 441 |
} |
| 442 |
|
| 443 |
type ModifyInstanceAutoReleaseTimeArgs struct { |
| 444 |
InstanceId string |
| 445 |
AutoReleaseTime string |
| 446 |
} |
| 447 |
|
| 448 |
type ModifyInstanceAutoReleaseTimeResponse struct { |
| 449 |
common.Response |
| 450 |
} |
| 451 |
|
| 452 |
例设定自动释放时间。 |
| 453 |
|
| 454 |
|
| 455 |
func (client *Client) ModifyInstanceAutoReleaseTime(instanceId, time string) error { |
| 456 |
args := ModifyInstanceAutoReleaseTimeArgs{ |
| 457 |
InstanceId: instanceId, |
| 458 |
AutoReleaseTime: time, |
| 459 |
} |
| 460 |
response := ModifyInstanceAutoReleaseTimeResponse{} |
| 461 |
err := client.Invoke("ModifyInstanceAutoReleaseTime", &args, &response) |
| 462 |
return err |
| 463 |
} |
| 464 |
|
| 465 |
type DeleteInstanceArgs struct { |
| 466 |
InstanceId string |
| 467 |
} |
| 468 |
|
| 469 |
type DeleteInstanceResponse struct { |
| 470 |
common.Response |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
func (client *Client) DeleteInstance(instanceId string) error { |
| 477 |
args := DeleteInstanceArgs{InstanceId: instanceId} |
| 478 |
response := DeleteInstanceResponse{} |
| 479 |
err := client.Invoke("DeleteInstance", &args, &response) |
| 480 |
return err |
| 481 |
} |
| 482 |
|
| 483 |
type DataDiskType struct { |
| 484 |
Size int |
| 485 |
Category DiskCategory |
| 486 |
SnapshotId string |
| 487 |
DiskName string |
| 488 |
Description string |
| 489 |
Device string |
| 490 |
DeleteWithInstance bool |
| 491 |
} |
| 492 |
|
| 493 |
type SystemDiskType struct { |
| 494 |
Size int |
| 495 |
Category DiskCategory |
| 496 |
DiskName string |
| 497 |
Description string |
| 498 |
} |
| 499 |
|
| 500 |
type IoOptimized string |
| 501 |
|
| 502 |
type StringOrBool struct { |
| 503 |
Value bool |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
func (io *StringOrBool) UnmarshalJSON(value []byte) error { |
| 508 |
if value[0] == '"' { |
| 509 |
var str string |
| 510 |
err := json.Unmarshal(value, &str) |
| 511 |
if err == nil { |
| 512 |
io.Value = (str == "true" || str == "optimized") |
| 513 |
} |
| 514 |
return err |
| 515 |
} |
| 516 |
var boolVal bool |
| 517 |
err := json.Unmarshal(value, &boolVal) |
| 518 |
if err == nil { |
| 519 |
io.Value = boolVal |
| 520 |
} |
| 521 |
return err |
| 522 |
} |
| 523 |
|
| 524 |
func (io StringOrBool) Bool() bool { |
| 525 |
return io.Value |
| 526 |
} |
| 527 |
|
| 528 |
func (io StringOrBool) String() string { |
| 529 |
return strconv.FormatBool(io.Value) |
| 530 |
} |
| 531 |
|
| 532 |
var ( |
| 533 |
IoOptimizedNone = IoOptimized("none") |
| 534 |
IoOptimizedOptimized = IoOptimized("optimized") |
| 535 |
) |
| 536 |
|
| 537 |
type SecurityEnhancementStrategy string |
| 538 |
|
| 539 |
var ( |
| 540 |
InactiveSecurityEnhancementStrategy = SecurityEnhancementStrategy("Active") |
| 541 |
DeactiveSecurityEnhancementStrategy = SecurityEnhancementStrategy("Deactive") |
| 542 |
) |
| 543 |
|
| 544 |
type CreateInstanceArgs struct { |
| 545 |
RegionId common.Region |
| 546 |
ZoneId string |
| 547 |
ImageId string |
| 548 |
InstanceType string |
| 549 |
SecurityGroupId string |
| 550 |
InstanceName string |
| 551 |
Description string |
| 552 |
InternetChargeType common.InternetChargeType |
| 553 |
InternetMaxBandwidthIn int |
| 554 |
InternetMaxBandwidthOut int |
| 555 |
HostName string |
| 556 |
Password string |
| 557 |
IoOptimized IoOptimized |
| 558 |
SystemDisk SystemDiskType |
| 559 |
DataDisk []DataDiskType |
| 560 |
VSwitchId string |
| 561 |
PrivateIpAddress string |
| 562 |
ClientToken string |
| 563 |
InstanceChargeType common.InstanceChargeType |
| 564 |
Period int |
| 565 |
PeriodUnit common.TimeType |
| 566 |
UserData string |
| 567 |
AutoRenew bool |
| 568 |
AutoRenewPeriod int |
| 569 |
SpotStrategy SpotStrategyType |
| 570 |
SpotPriceLimit float64 |
| 571 |
KeyPairName string |
| 572 |
RamRoleName string |
| 573 |
SecurityEnhancementStrategy SecurityEnhancementStrategy |
| 574 |
} |
| 575 |
|
| 576 |
type CreateInstanceResponse struct { |
| 577 |
common.Response |
| 578 |
InstanceId string |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
func (client *Client) CreateInstance(args *CreateInstanceArgs) (instanceId string, err error) { |
| 585 |
if args.UserData != "" { |
| 586 |
|
| 587 |
args.UserData = base64.StdEncoding.EncodeToString([]byte(args.UserData)) |
| 588 |
} |
| 589 |
response := CreateInstanceResponse{} |
| 590 |
err = client.Invoke("CreateInstance", args, &response) |
| 591 |
if err != nil { |
| 592 |
return "", err |
| 593 |
} |
| 594 |
return response.InstanceId, err |
| 595 |
} |
| 596 |
|
| 597 |
type RunInstanceArgs struct { |
| 598 |
CreateInstanceArgs |
| 599 |
MinAmount int |
| 600 |
MaxAmount int |
| 601 |
AutoReleaseTime string |
| 602 |
NetworkType string |
| 603 |
InnerIpAddress string |
| 604 |
BusinessInfo string |
| 605 |
} |
| 606 |
|
| 607 |
type RunInstanceResponse struct { |
| 608 |
common.Response |
| 609 |
InstanceIdSets InstanceIdSets |
| 610 |
} |
| 611 |
|
| 612 |
type InstanceIdSets struct { |
| 613 |
InstanceIdSet []string |
| 614 |
} |
| 615 |
|
| 616 |
type BusinessInfo struct { |
| 617 |
Pack string `json:"pack,omitempty"` |
| 618 |
ActivityId string `json:"activityId,omitempty"` |
| 619 |
} |
| 620 |
|
| 621 |
func (client *Client) RunInstances(args *RunInstanceArgs) (instanceIdSet []string, err error) { |
| 622 |
if args.UserData != "" { |
| 623 |
|
| 624 |
args.UserData = base64.StdEncoding.EncodeToString([]byte(args.UserData)) |
| 625 |
} |
| 626 |
response := RunInstanceResponse{} |
| 627 |
err = client.Invoke("RunInstances", args, &response) |
| 628 |
if err != nil { |
| 629 |
return nil, err |
| 630 |
} |
| 631 |
return response.InstanceIdSets.InstanceIdSet, err |
| 632 |
} |
| 633 |
|
| 634 |
type SecurityGroupArgs struct { |
| 635 |
InstanceId string |
| 636 |
SecurityGroupId string |
| 637 |
} |
| 638 |
|
| 639 |
type SecurityGroupResponse struct { |
| 640 |
common.Response |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
func (client *Client) JoinSecurityGroup(instanceId string, securityGroupId string) error { |
| 647 |
args := SecurityGroupArgs{InstanceId: instanceId, SecurityGroupId: securityGroupId} |
| 648 |
response := SecurityGroupResponse{} |
| 649 |
err := client.Invoke("JoinSecurityGroup", &args, &response) |
| 650 |
return err |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
func (client *Client) LeaveSecurityGroup(instanceId string, securityGroupId string) error { |
| 657 |
args := SecurityGroupArgs{InstanceId: instanceId, SecurityGroupId: securityGroupId} |
| 658 |
response := SecurityGroupResponse{} |
| 659 |
err := client.Invoke("LeaveSecurityGroup", &args, &response) |
| 660 |
return err |
| 661 |
} |
| 662 |
|
| 663 |
type AttachInstancesArgs struct { |
| 664 |
RegionId common.Region |
| 665 |
RamRoleName string |
| 666 |
InstanceIds string |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
func (client *Client) AttachInstanceRamRole(args *AttachInstancesArgs) (err error) { |
| 673 |
response := common.Response{} |
| 674 |
err = client.Invoke("AttachInstanceRamRole", args, &response) |
| 675 |
if err != nil { |
| 676 |
return err |
| 677 |
} |
| 678 |
return nil |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
func (client *Client) DetachInstanceRamRole(args *AttachInstancesArgs) (err error) { |
| 685 |
response := common.Response{} |
| 686 |
err = client.Invoke("DetachInstanceRamRole", args, &response) |
| 687 |
if err != nil { |
| 688 |
return err |
| 689 |
} |
| 690 |
return nil |
| 691 |
} |
| 692 |
|
| 693 |
type DescribeInstanceRamRoleResponse struct { |
| 694 |
common.Response |
| 695 |
InstanceRamRoleSets struct { |
| 696 |
InstanceRamRoleSet []InstanceRamRoleSetType |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
type InstanceRamRoleSetType struct { |
| 701 |
InstanceId string |
| 702 |
RamRoleName string |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
func (client *Client) DescribeInstanceRamRole(args *AttachInstancesArgs) (resp *DescribeInstanceRamRoleResponse, err error) { |
| 709 |
response := &DescribeInstanceRamRoleResponse{} |
| 710 |
err = client.Invoke("DescribeInstanceRamRole", args, response) |
| 711 |
if err != nil { |
| 712 |
return response, err |
| 713 |
} |
| 714 |
return response, nil |
| 715 |
} |
| 716 |
|
| 717 |
type ModifyInstanceSpecArgs struct { |
| 718 |
InstanceId string |
| 719 |
InstanceType string |
| 720 |
InternetMaxBandwidthOut *int |
| 721 |
InternetMaxBandwidthIn *int |
| 722 |
ClientToken string |
| 723 |
} |
| 724 |
|
| 725 |
type ModifyInstanceSpecResponse struct { |
| 726 |
common.Response |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
func (client *Client) ModifyInstanceSpec(args *ModifyInstanceSpecArgs) error { |
| 736 |
response := ModifyInstanceSpecResponse{} |
| 737 |
return client.Invoke("ModifyInstanceSpec", args, &response) |
| 738 |
} |
| 739 |
|
| 740 |
type ModifyInstanceVpcAttributeArgs struct { |
| 741 |
InstanceId string |
| 742 |
VSwitchId string |
| 743 |
PrivateIpAddress string |
| 744 |
} |
| 745 |
|
| 746 |
type ModifyInstanceVpcAttributeResponse struct { |
| 747 |
common.Response |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
func (client *Client) ModifyInstanceVpcAttribute(args *ModifyInstanceVpcAttributeArgs) error { |
| 754 |
response := ModifyInstanceVpcAttributeResponse{} |
| 755 |
return client.Invoke("ModifyInstanceVpcAttribute", args, &response) |
| 756 |
} |
| 757 |
|
| 758 |
type ModifyInstanceChargeTypeArgs struct { |
| 759 |
InstanceIds string |
| 760 |
RegionId common.Region |
| 761 |
Period int |
| 762 |
PeriodUnit common.TimeType |
| 763 |
IncludeDataDisks bool |
| 764 |
DryRun bool |
| 765 |
AutoPay bool |
| 766 |
ClientToken string |
| 767 |
} |
| 768 |
|
| 769 |
type ModifyInstanceChargeTypeResponse struct { |
| 770 |
common.Response |
| 771 |
Order string |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
func (client *Client) ModifyInstanceChargeType(args *ModifyInstanceChargeTypeArgs) (*ModifyInstanceChargeTypeResponse, error) { |
| 778 |
response := &ModifyInstanceChargeTypeResponse{} |
| 779 |
if err := client.Invoke("ModifyInstanceChargeType", args, response); err != nil { |
| 780 |
return response, err |
| 781 |
} |
| 782 |
return response, nil |
| 783 |
} |
| 784 |
|
| 785 |
type RenewalStatus string |
| 786 |
|
| 787 |
const ( |
| 788 |
RenewAutoRenewal = RenewalStatus("AutoRenewal") |
| 789 |
RenewNormal = RenewalStatus("Normal") |
| 790 |
RenewNotRenewal = RenewalStatus("NotRenewal") |
| 791 |
) |
| 792 |
|
| 793 |
type ModifyInstanceAutoRenewAttributeArgs struct { |
| 794 |
InstanceId string |
| 795 |
RegionId common.Region |
| 796 |
Duration int |
| 797 |
AutoRenew bool |
| 798 |
RenewalStatus RenewalStatus |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
func (client *Client) ModifyInstanceAutoRenewAttribute(args *ModifyInstanceAutoRenewAttributeArgs) error { |
| 803 |
response := &common.Response{} |
| 804 |
return client.Invoke("ModifyInstanceAutoRenewAttribute", args, response) |
| 805 |
} |
| 806 |
|
| 807 |
type DescribeInstanceAutoRenewAttributeArgs struct { |
| 808 |
InstanceId string |
| 809 |
RegionId common.Region |
| 810 |
} |
| 811 |
|
| 812 |
type InstanceRenewAttribute struct { |
| 813 |
InstanceId string |
| 814 |
Duration int |
| 815 |
AutoRenewEnabled bool |
| 816 |
PeriodUnit string |
| 817 |
RenewalStatus RenewalStatus |
| 818 |
} |
| 819 |
|
| 820 |
type DescribeInstanceAutoRenewAttributeResponse struct { |
| 821 |
common.Response |
| 822 |
InstanceRenewAttributes struct { |
| 823 |
InstanceRenewAttribute []InstanceRenewAttribute |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
func (client *Client) DescribeInstanceAutoRenewAttribute(args *DescribeInstanceAutoRenewAttributeArgs) (*DescribeInstanceAutoRenewAttributeResponse, error) { |
| 829 |
response := &DescribeInstanceAutoRenewAttributeResponse{} |
| 830 |
err := client.Invoke("DescribeInstanceAutoRenewAttribute", args, response) |
| 831 |
return response, err |
| 832 |
} |