yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/reservedinstance.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package aws
    16  
    17  import (
    18  	"github.com/aws/aws-sdk-go/service/ec2"
    19  
    20  	"yunion.io/x/log"
    21  	"yunion.io/x/pkg/errors"
    22  )
    23  
    24  func (self *SRegion) GetReservedInstance() error {
    25  	ec2Client, err := self.getEc2Client()
    26  	if err != nil {
    27  		return errors.Wrap(err, "getEc2Client")
    28  	}
    29  	params := &ec2.DescribeReservedInstancesInput{}
    30  	res, err := ec2Client.DescribeReservedInstances(params)
    31  	if err != nil {
    32  		log.Errorf("DescribeReservedInstances fail %s", err)
    33  		return err
    34  	}
    35  	log.Debugf("%#v", res)
    36  	return nil
    37  }
    38  
    39  type SReservedHostOffering struct {
    40  	Duration       int
    41  	HourlyPrice    float64
    42  	InstanceFamily string
    43  	OfferingId     string
    44  	PaymentOption  string
    45  	UpfrontPrice   float64
    46  }
    47  
    48  func (self *SRegion) GetReservedHostOfferings() error {
    49  	ec2Client, err := self.getEc2Client()
    50  	if err != nil {
    51  		return errors.Wrap(err, "getEc2Client")
    52  	}
    53  	res, err := ec2Client.DescribeHostReservationOfferings(nil)
    54  	if err != nil {
    55  		log.Errorf("DescribeHostReservationOfferings fail %s", err)
    56  		return err
    57  	}
    58  	log.Debugf("%#v", res)
    59  	return nil
    60  }