@@ -1084,3 +1084,79 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
10841084 m .logger .Debug ("snapshot created successfully" )
10851085 return nil
10861086}
1087+
1088+ // CreateBalloon creates a balloon device if one does not exist
1089+ func (m * Machine ) CreateBalloon (ctx context.Context , amountMib int64 , deflateOnOom bool , statsPollingIntervals int64 , opts ... PutBalloonOpt ) error {
1090+ balloon := models.Balloon {
1091+ AmountMib : & amountMib ,
1092+ DeflateOnOom : & deflateOnOom ,
1093+ StatsPollingIntervals : statsPollingIntervals ,
1094+ }
1095+ _ , err := m .client .PutBalloon (ctx , & balloon , opts ... )
1096+
1097+ if err != nil {
1098+ m .logger .Errorf ("Create balloon device failed : %s" , err )
1099+ return err
1100+ }
1101+
1102+ m .logger .Debug ("Created balloon device successful" )
1103+ return nil
1104+ }
1105+
1106+ // GetBalloonConfig gets the current balloon device configuration.
1107+ func (m * Machine ) GetBalloonConfig (ctx context.Context ) (models.Balloon , error ) {
1108+ var balloonConfig models.Balloon
1109+ resp , err := m .client .DescribeBalloonConfig (ctx )
1110+ if err != nil {
1111+ m .logger .Errorf ("Getting balloonConfig: %s" , err )
1112+ return balloonConfig , err
1113+ }
1114+
1115+ balloonConfig = * resp .Payload
1116+ m .logger .Debug ("GetBalloonConfig successful" )
1117+ return balloonConfig , err
1118+ }
1119+
1120+ // UpdateBalloon will update an existing balloon device, before or after machine startup
1121+ func (m * Machine ) UpdateBalloon (ctx context.Context , amountMib int64 , opts ... PatchBalloonOpt ) error {
1122+ ballonUpdate := models.BalloonUpdate {
1123+ AmountMib : & amountMib ,
1124+ }
1125+ _ , err := m .client .PatchBalloon (ctx , & ballonUpdate , opts ... )
1126+ if err != nil {
1127+ m .logger .Errorf ("Update balloon device failed : %s" , err )
1128+ return err
1129+ }
1130+
1131+ m .logger .Debug ("Update balloon device successful" )
1132+ return nil
1133+ }
1134+
1135+ // GetBalloonStats gets the latest balloon device statistics, only if enabled pre-boot.
1136+ func (m * Machine ) GetBalloonStats (ctx context.Context ) (models.BalloonStats , error ) {
1137+ var balloonStats models.BalloonStats
1138+ resp , err := m .client .DescribeBalloonStats (ctx )
1139+ if err != nil {
1140+ m .logger .Errorf ("Getting balloonStats: %s" , err )
1141+ return balloonStats , err
1142+ }
1143+ balloonStats = * resp .Payload
1144+ m .logger .Debug ("GetBalloonStats successful" )
1145+ return balloonStats , nil
1146+ }
1147+
1148+ // UpdateBalloon will update a balloon device statistics polling interval.
1149+ // Statistics cannot be turned on/off after boot.
1150+ func (m * Machine ) UpdateBalloonStats (ctx context.Context , statsPollingIntervals int64 , opts ... PatchBalloonStatsIntervalOpt ) error {
1151+ balloonStatsUpdate := models.BalloonStatsUpdate {
1152+ StatsPollingIntervals : & statsPollingIntervals ,
1153+ }
1154+
1155+ if _ , err := m .client .PatchBalloonStatsInterval (ctx , & balloonStatsUpdate , opts ... ); err != nil {
1156+ m .logger .Errorf ("UpdateBalloonStats failed: %v" , err )
1157+ return err
1158+ }
1159+
1160+ m .logger .Debug ("UpdateBalloonStats successful" )
1161+ return nil
1162+ }
0 commit comments