@ -34,6 +34,7 @@ package kvmvm
 
			
		
	
		
			
				
					import  (  
			
		
	
		
			
				
						"context" 
 
			
		
	
		
			
				
						"strconv" 
 
			
		
	
		
			
				
						"strings" 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						log  "github.com/sirupsen/logrus" 
 
			
		
	
		
			
				
						"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute" 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -42,6 +43,260 @@ import (
 
			
		
	
		
			
				
						"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 
 
			
		
	
		
			
				
					)  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeEnabled ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
						enabled  :=  d . Get ( "enabled" ) . ( bool ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  enabled  { 
 
			
		
	
		
			
				
							req  :=  compute . EnableRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  _ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Enable ( ctx ,  req ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							req  :=  compute . DisableRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  _ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Disable ( ctx ,  req ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						log . Debugf ( "resourceComputeUpdate: enable=%v Compute ID %s after completing its resource configuration" ,  enabled ,  d . Id ( ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeStarted ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  d . Get ( "started" ) . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . StartRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  altBootId ,  ok  :=  d . Get ( "alt_boot_id" ) . ( int ) ;  ok  { 
 
			
		
	
		
			
				
								req . AltBootID  =  uint64 ( altBootId ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  stackId ,  ok  :=  d . Get ( "stack_id" ) . ( int ) ;  ok  { 
 
			
		
	
		
			
				
								req . StackID  =  uint64 ( stackId ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  _ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Start ( ctx ,  req ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							req  :=  compute . StopRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  force ,  ok  :=  d . Get ( "force_stop" ) . ( bool ) ;  ok  { 
 
			
		
	
		
			
				
								req . Force  =  force 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  _ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Stop ( ctx ,  req ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeResize ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						resizeReq  :=  compute . ResizeRequest { 
 
			
		
	
		
			
				
							ComputeID :  computeId , 
 
			
		
	
		
			
				
							Force :      true , 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						doUpdate  :=  false 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldCpu ,  newCpu  :=  d . GetChange ( "cpu" ) 
 
			
		
	
		
			
				
						if  oldCpu . ( int )  !=  newCpu . ( int )  { 
 
			
		
	
		
			
				
							resizeReq . CPU  =  uint64 ( newCpu . ( int ) ) 
 
			
		
	
		
			
				
							doUpdate  =  true 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							resizeReq . CPU  =  0 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldRam ,  newRam  :=  d . GetChange ( "ram" ) 
 
			
		
	
		
			
				
						if  oldRam . ( int )  !=  newRam . ( int )  { 
 
			
		
	
		
			
				
							resizeReq . RAM  =  uint64 ( newRam . ( int ) ) 
 
			
		
	
		
			
				
							doUpdate  =  true 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							resizeReq . RAM  =  0 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  doUpdate  { 
 
			
		
	
		
			
				
							log . Debugf ( "resourceComputeUpdate: changing CPU %d -> %d and/or RAM %d -> %d" , 
 
			
		
	
		
			
				
								oldCpu . ( int ) ,  newCpu . ( int ) , 
 
			
		
	
		
			
				
								oldRam . ( int ) ,  newRam . ( int ) ) 
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Resize ( ctx ,  resizeReq ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeBootDiskResize ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSize ,  newSize  :=  d . GetChange ( "boot_disk_size" ) 
 
			
		
	
		
			
				
						if  oldSize . ( int )  <  newSize . ( int )  { 
 
			
		
	
		
			
				
							req  :=  compute . DiskResizeRequest { ComputeID :  computeId ,  Size :  uint64 ( newSize . ( int ) ) } 
 
			
		
	
		
			
				
							if  diskId ,  ok  :=  d . GetOk ( "boot_disk_id" ) ;  ok  { 
 
			
		
	
		
			
				
								req . DiskID  =  uint64 ( diskId . ( int ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							}  else  { 
 
			
		
	
		
			
				
								bootDisk ,  err  :=  utilityComputeBootDiskCheckPresence ( ctx ,  d ,  m ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								req . DiskID  =  bootDisk . ID 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							log . Debugf ( "resourceComputeUpdate: compute ID %s, boot disk ID %d resize %d -> %d" , 
 
			
		
	
		
			
				
								d . Id ( ) ,  d . Get ( "boot_disk_id" ) . ( int ) ,  oldSize . ( int ) ,  newSize . ( int ) ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . DiskResize ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						}  else  if  oldSize . ( int )  >  newSize . ( int )  { 
 
			
		
	
		
			
				
							log . Warnf ( "resourceComputeUpdate: compute ID %s - shrinking boot disk is not allowed" ,  d . Id ( ) ) 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateDisks ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						deletedDisks  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
						addedDisks  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
						updatedDisks  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldDisks ,  newDisks  :=  d . GetChange ( "disks" ) 
 
			
		
	
		
			
				
						oldConv  :=  oldDisks . ( [ ] interface { } ) 
 
			
		
	
		
			
				
						newConv  :=  newDisks . ( [ ] interface { } ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						for  _ ,  el  :=  range  oldConv  { 
 
			
		
	
		
			
				
							if  ! isContainsDisk ( newConv ,  el )  { 
 
			
		
	
		
			
				
								deletedDisks  =  append ( deletedDisks ,  el ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						for  _ ,  el  :=  range  newConv  { 
 
			
		
	
		
			
				
							if  ! isContainsDisk ( oldConv ,  el )  { 
 
			
		
	
		
			
				
								addedDisks  =  append ( addedDisks ,  el ) 
 
			
		
	
		
			
				
							}  else  { 
 
			
		
	
		
			
				
								if  isChangeDisk ( oldConv ,  el )  { 
 
			
		
	
		
			
				
									updatedDisks  =  append ( updatedDisks ,  el ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( deletedDisks )  >  0  { 
 
			
		
	
		
			
				
							stopReq  :=  compute . StopRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								Force :      false , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Stop ( ctx ,  stopReq ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							for  _ ,  disk  :=  range  deletedDisks  { 
 
			
		
	
		
			
				
								diskConv  :=  disk . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								if  diskConv [ "disk_type" ] . ( string )  ==  "B"  { 
 
			
		
	
		
			
				
									continue 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								req  :=  compute . DiskDelRequest { 
 
			
		
	
		
			
				
									ComputeID :    computeId , 
 
			
		
	
		
			
				
									DiskID :       uint64 ( diskConv [ "disk_id" ] . ( int ) ) , 
 
			
		
	
		
			
				
									Permanently :  diskConv [ "permanently" ] . ( bool ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . DiskDel ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							req  :=  compute . StartRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								AltBootID :  0 , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							_ ,  err  =  c . CloudBroker ( ) . Compute ( ) . Start ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( addedDisks )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  disk  :=  range  addedDisks  { 
 
			
		
	
		
			
				
								diskConv  :=  disk . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								if  diskConv [ "disk_type" ] . ( string )  ==  "B"  { 
 
			
		
	
		
			
				
									continue 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								req  :=  compute . DiskAddRequest { 
 
			
		
	
		
			
				
									ComputeID :  computeId , 
 
			
		
	
		
			
				
									DiskName :   diskConv [ "disk_name" ] . ( string ) , 
 
			
		
	
		
			
				
									Size :       uint64 ( diskConv [ "size" ] . ( int ) ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  diskConv [ "sep_id" ] . ( int )  !=  0  { 
 
			
		
	
		
			
				
									req . SepID  =  uint64 ( diskConv [ "sep_id" ] . ( int ) ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  diskConv [ "disk_type" ] . ( string )  !=  ""  { 
 
			
		
	
		
			
				
									req . DiskType  =  diskConv [ "disk_type" ] . ( string ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  diskConv [ "pool" ] . ( string )  !=  ""  { 
 
			
		
	
		
			
				
									req . Pool  =  diskConv [ "pool" ] . ( string ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  diskConv [ "desc" ] . ( string )  !=  ""  { 
 
			
		
	
		
			
				
									req . Description  =  diskConv [ "desc" ] . ( string ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  diskConv [ "image_id" ] . ( int )  !=  0  { 
 
			
		
	
		
			
				
									req . ImageID  =  uint64 ( diskConv [ "image_id" ] . ( int ) ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . DiskAdd ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( updatedDisks )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  disk  :=  range  updatedDisks  { 
 
			
		
	
		
			
				
								diskConv  :=  disk . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								if  diskConv [ "disk_type" ] . ( string )  ==  "B"  { 
 
			
		
	
		
			
				
									continue 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								req  :=  compute . DiskResizeRequest { 
 
			
		
	
		
			
				
									ComputeID :  computeId , 
 
			
		
	
		
			
				
									DiskID :     uint64 ( diskConv [ "disk_id" ] . ( int ) ) , 
 
			
		
	
		
			
				
									Size :       uint64 ( diskConv [ "size" ] . ( int ) ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . DiskResize ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeExtraDisksConfigure ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } ,  do_delta  bool )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -154,6 +409,10 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
 
			
		
	
		
			
				
							req . ComputeID  =  uint64 ( d . Get ( "compute_id" ) . ( int ) ) 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  reason ,  ok  :=  d . GetOk ( "reason" ) ;  ok  { 
 
			
		
	
		
			
				
							req . Reason  =  reason . ( string ) 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						res ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Get ( ctx ,  req ) 
 
			
		
	
		
			
				
						if  err  !=  nil  { 
 
			
		
	
		
			
				
							return  nil ,  err 
 
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -162,6 +421,15 @@ func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m
 
			
		
	
		
			
				
						return  res ,  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  findBootDisk ( disks  compute . ListDisks )  * compute . ItemDisk  {  
			
		
	
		
			
				
						for  _ ,  disk  :=  range  disks  { 
 
			
		
	
		
			
				
							if  disk . Type  ==  "B"  { 
 
			
		
	
		
			
				
								return  & disk 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  networkSubresIPAddreDiffSupperss ( key ,  oldVal ,  newVal  string ,  d  * schema . ResourceData )  bool  {  
			
		
	
		
			
				
						if  newVal  !=  ""  &&  newVal  !=  oldVal  { 
 
			
		
	
		
			
				
							log . Debugf ( "networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE" ,  key ,  oldVal ,  newVal ) 
 
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -288,6 +556,659 @@ func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdate ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						req  :=  compute . UpdateRequest { 
 
			
		
	
		
			
				
							ComputeID :  computeId , 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  d . HasChange ( "name" )  { 
 
			
		
	
		
			
				
							req . Name  =  d . Get ( "name" ) . ( string ) 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						if  d . HasChange ( "desc" )  { 
 
			
		
	
		
			
				
							req . Description  =  d . Get ( "desc" ) . ( string ) 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  _ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Update ( ctx ,  req ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
							return  err 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateAffinityLabel ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						affinityLabel  :=  d . Get ( "affinity_label" ) . ( string ) 
 
			
		
	
		
			
				
						if  affinityLabel  ==  ""  { 
 
			
		
	
		
			
				
							req  :=  compute . AffinityLabelRemoveRequest { 
 
			
		
	
		
			
				
								ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AffinityLabelRemove ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						req  :=  compute . AffinityLabelSetRequest { 
 
			
		
	
		
			
				
							ComputeIDs :     [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
							AffinityLabel :  affinityLabel , 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AffinityLabelSet ( ctx ,  req ) 
 
			
		
	
		
			
				
						if  err  !=  nil  { 
 
			
		
	
		
			
				
							return  err 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateAffinityRules ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						deletedAR  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
						addedAR  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldAR ,  newAR  :=  d . GetChange ( "affinity_rules" ) 
 
			
		
	
		
			
				
						oldConv  :=  oldAR . ( [ ] interface { } ) 
 
			
		
	
		
			
				
						newConv  :=  newAR . ( [ ] interface { } ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( newConv )  ==  0  { 
 
			
		
	
		
			
				
							req  :=  compute . AffinityRulesClearRequest { 
 
			
		
	
		
			
				
								ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AffinityRulesClear ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							for  _ ,  el  :=  range  oldConv  { 
 
			
		
	
		
			
				
								if  ! isContainsAR ( newConv ,  el )  { 
 
			
		
	
		
			
				
									deletedAR  =  append ( deletedAR ,  el ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							for  _ ,  el  :=  range  newConv  { 
 
			
		
	
		
			
				
								if  ! isContainsAR ( oldConv ,  el )  { 
 
			
		
	
		
			
				
									addedAR  =  append ( addedAR ,  el ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  len ( deletedAR )  >  0  { 
 
			
		
	
		
			
				
								for  _ ,  ar  :=  range  deletedAR  { 
 
			
		
	
		
			
				
									arConv  :=  ar . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
									req  :=  compute . AffinityRuleRemoveRequest { 
 
			
		
	
		
			
				
										ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
										Topology :    arConv [ "topology" ] . ( string ) , 
 
			
		
	
		
			
				
										Policy :      arConv [ "policy" ] . ( string ) , 
 
			
		
	
		
			
				
										Mode :        arConv [ "mode" ] . ( string ) , 
 
			
		
	
		
			
				
										Key :         arConv [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
										Value :       arConv [ "value" ] . ( string ) , 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
									_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AffinityRuleRemove ( ctx ,  req ) 
 
			
		
	
		
			
				
									if  err  !=  nil  { 
 
			
		
	
		
			
				
										return  err 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  len ( addedAR )  >  0  { 
 
			
		
	
		
			
				
								for  _ ,  ar  :=  range  addedAR  { 
 
			
		
	
		
			
				
									arConv  :=  ar . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
									req  :=  compute . AffinityRuleAddRequest { 
 
			
		
	
		
			
				
										ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
										Topology :    arConv [ "topology" ] . ( string ) , 
 
			
		
	
		
			
				
										Policy :      arConv [ "policy" ] . ( string ) , 
 
			
		
	
		
			
				
										Mode :        arConv [ "mode" ] . ( string ) , 
 
			
		
	
		
			
				
										Key :         arConv [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
										Value :       arConv [ "value" ] . ( string ) , 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
									_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AffinityRuleAdd ( ctx ,  req ) 
 
			
		
	
		
			
				
									if  err  !=  nil  { 
 
			
		
	
		
			
				
										return  err 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateAntiAffinityRules ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						deletedAR  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
						addedAR  :=  make ( [ ] interface { } ,  0 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldAR ,  newAR  :=  d . GetChange ( "anti_affinity_rules" ) 
 
			
		
	
		
			
				
						oldConv  :=  oldAR . ( [ ] interface { } ) 
 
			
		
	
		
			
				
						newConv  :=  newAR . ( [ ] interface { } ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( newConv )  ==  0  { 
 
			
		
	
		
			
				
							req  :=  compute . AntiAffinityRulesClearRequest { 
 
			
		
	
		
			
				
								ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AntiAffinityRulesClear ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						}  else  { 
 
			
		
	
		
			
				
							for  _ ,  el  :=  range  oldConv  { 
 
			
		
	
		
			
				
								if  ! isContainsAR ( newConv ,  el )  { 
 
			
		
	
		
			
				
									deletedAR  =  append ( deletedAR ,  el ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							for  _ ,  el  :=  range  newConv  { 
 
			
		
	
		
			
				
								if  ! isContainsAR ( oldConv ,  el )  { 
 
			
		
	
		
			
				
									addedAR  =  append ( addedAR ,  el ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  len ( deletedAR )  >  0  { 
 
			
		
	
		
			
				
								for  _ ,  ar  :=  range  deletedAR  { 
 
			
		
	
		
			
				
									arConv  :=  ar . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
									req  :=  compute . AntiAffinityRuleRemoveRequest { 
 
			
		
	
		
			
				
										ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
										Topology :    arConv [ "topology" ] . ( string ) , 
 
			
		
	
		
			
				
										Policy :      arConv [ "policy" ] . ( string ) , 
 
			
		
	
		
			
				
										Mode :        arConv [ "mode" ] . ( string ) , 
 
			
		
	
		
			
				
										Key :         arConv [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
										Value :       arConv [ "value" ] . ( string ) , 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
									_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AntiAffinityRuleRemove ( ctx ,  req ) 
 
			
		
	
		
			
				
									if  err  !=  nil  { 
 
			
		
	
		
			
				
										return  err 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  len ( addedAR )  >  0  { 
 
			
		
	
		
			
				
								for  _ ,  ar  :=  range  addedAR  { 
 
			
		
	
		
			
				
									arConv  :=  ar . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
									req  :=  compute . AntiAffinityRuleAddRequest { 
 
			
		
	
		
			
				
										ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
										Topology :    arConv [ "topology" ] . ( string ) , 
 
			
		
	
		
			
				
										Policy :      arConv [ "policy" ] . ( string ) , 
 
			
		
	
		
			
				
										Mode :        arConv [ "mode" ] . ( string ) , 
 
			
		
	
		
			
				
										Key :         arConv [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
										Value :       arConv [ "value" ] . ( string ) , 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
									_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . AntiAffinityRuleAdd ( ctx ,  req ) 
 
			
		
	
		
			
				
									if  err  !=  nil  { 
 
			
		
	
		
			
				
										return  err 
 
			
		
	
		
			
				
									} 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateTags ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSet ,  newSet  :=  d . GetChange ( "tags" ) 
 
			
		
	
		
			
				
						deletedTags  :=  ( oldSet . ( * schema . Set ) . Difference ( newSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( deletedTags )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  tagInterface  :=  range  deletedTags  { 
 
			
		
	
		
			
				
								tagItem  :=  tagInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . TagRemoveRequest { 
 
			
		
	
		
			
				
									ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
									Key :         tagItem [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . TagRemove ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						addedTags  :=  ( newSet . ( * schema . Set ) . Difference ( oldSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( addedTags )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  tagInterface  :=  range  addedTags  { 
 
			
		
	
		
			
				
								tagItem  :=  tagInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . TagAddRequest { 
 
			
		
	
		
			
				
									ComputeIDs :  [ ] uint64 { computeId } , 
 
			
		
	
		
			
				
									Key :         tagItem [ "key" ] . ( string ) , 
 
			
		
	
		
			
				
									Value :       tagItem [ "value" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . TagAdd ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdatePFW ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSet ,  newSet  :=  d . GetChange ( "port_forwarding" ) 
 
			
		
	
		
			
				
						deletedPfws  :=  ( oldSet . ( * schema . Set ) . Difference ( newSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( deletedPfws )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  pfwInterface  :=  range  deletedPfws  { 
 
			
		
	
		
			
				
								pfwItem  :=  pfwInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . PFWDelRequest { 
 
			
		
	
		
			
				
									ComputeID :        computeId , 
 
			
		
	
		
			
				
									PublicPortStart :  uint64 ( pfwItem [ "public_port_start" ] . ( int ) ) , 
 
			
		
	
		
			
				
									LocalBasePort :    uint64 ( pfwItem [ "local_port" ] . ( int ) ) , 
 
			
		
	
		
			
				
									Proto :            pfwItem [ "proto" ] . ( string ) , 
 
			
		
	
		
			
				
									RuleID :           uint64 ( pfwItem [ "rule_id" ] . ( int ) ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								if  pfwItem [ "public_port_end" ] . ( int )  ==  - 1  { 
 
			
		
	
		
			
				
									req . PublicPortEnd  =  req . PublicPortStart 
 
			
		
	
		
			
				
								}  else  { 
 
			
		
	
		
			
				
									req . PublicPortEnd  =  uint64 ( pfwItem [ "public_port_end" ] . ( int ) ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								if  pfwItem [ "reason" ] . ( string )  !=  ""  { 
 
			
		
	
		
			
				
									req . Reason  =  pfwItem [ "reason" ] . ( string ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . PFWDel ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						addedPfws  :=  ( newSet . ( * schema . Set ) . Difference ( oldSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( addedPfws )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  pfwInterface  :=  range  addedPfws  { 
 
			
		
	
		
			
				
								pfwItem  :=  pfwInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . PFWAddRequest { 
 
			
		
	
		
			
				
									ComputeID :        computeId , 
 
			
		
	
		
			
				
									PublicPortStart :  uint64 ( pfwItem [ "public_port_start" ] . ( int ) ) , 
 
			
		
	
		
			
				
									PublicPortEnd :    int64 ( pfwItem [ "public_port_end" ] . ( int ) ) , 
 
			
		
	
		
			
				
									LocalBasePort :    uint64 ( pfwItem [ "local_port" ] . ( int ) ) , 
 
			
		
	
		
			
				
									Proto :            pfwItem [ "proto" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								if  pfwItem [ "reason" ] . ( string )  !=  ""  { 
 
			
		
	
		
			
				
									req . Reason  =  pfwItem [ "reason" ] . ( string ) 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								pwfId ,  err  :=  c . CloudBroker ( ) . Compute ( ) . PFWAdd ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
								d . Set ( "rule_id" ,  pwfId ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeRestore ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						restoreReq  :=  compute . RestoreRequest { ComputeID :  computeId } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Restore ( ctx ,  restoreReq ) 
 
			
		
	
		
			
				
						if  err  !=  nil  { 
 
			
		
	
		
			
				
							return  err 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  _ ,  ok  :=  d . GetOk ( "enabled" ) ;  ok  { 
 
			
		
	
		
			
				
							if  err  :=  utilityComputeEnabled ( ctx ,  d ,  m ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  _ ,  ok  :=  d . GetOk ( "started" ) ;  ok  { 
 
			
		
	
		
			
				
							if  err  :=  utilityComputeStarted ( ctx ,  d ,  m ) ;  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateUserAccess ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSet ,  newSet  :=  d . GetChange ( "user_access" ) 
 
			
		
	
		
			
				
						deletedUserAcess  :=  ( oldSet . ( * schema . Set ) . Difference ( newSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( deletedUserAcess )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  userAcessInterface  :=  range  deletedUserAcess  { 
 
			
		
	
		
			
				
								userAccessItem  :=  userAcessInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . UserRevokeRequest { 
 
			
		
	
		
			
				
									ComputeID :  computeId , 
 
			
		
	
		
			
				
									Username :   userAccessItem [ "username" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . UserRevoke ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						addedUserAccess  :=  ( newSet . ( * schema . Set ) . Difference ( oldSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( addedUserAccess )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  userAccessInterface  :=  range  addedUserAccess  { 
 
			
		
	
		
			
				
								userAccessItem  :=  userAccessInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . UserGrantRequest { 
 
			
		
	
		
			
				
									ComputeID :   computeId , 
 
			
		
	
		
			
				
									Username :    userAccessItem [ "username" ] . ( string ) , 
 
			
		
	
		
			
				
									AccessType :  userAccessItem [ "access_type" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . UserGrant ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateSnapshot ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSet ,  newSet  :=  d . GetChange ( "snapshot" ) 
 
			
		
	
		
			
				
						deletedSnapshots  :=  ( oldSet . ( * schema . Set ) . Difference ( newSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( deletedSnapshots )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  snapshotInterface  :=  range  deletedSnapshots  { 
 
			
		
	
		
			
				
								snapshotItem  :=  snapshotInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . SnapshotDeleteRequest { 
 
			
		
	
		
			
				
									ComputeID :  computeId , 
 
			
		
	
		
			
				
									Label :      snapshotItem [ "label" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . SnapshotDelete ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						addedSnapshots  :=  ( newSet . ( * schema . Set ) . Difference ( oldSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( addedSnapshots )  >  0  { 
 
			
		
	
		
			
				
							for  _ ,  snapshotInterface  :=  range  addedSnapshots  { 
 
			
		
	
		
			
				
								snapshotItem  :=  snapshotInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
								req  :=  compute . SnapshotCreateRequest { 
 
			
		
	
		
			
				
									ComputeID :  computeId , 
 
			
		
	
		
			
				
									Label :      snapshotItem [ "label" ] . ( string ) , 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
								_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . SnapshotCreate ( ctx ,  req ) 
 
			
		
	
		
			
				
								if  err  !=  nil  { 
 
			
		
	
		
			
				
									return  err 
 
			
		
	
		
			
				
								} 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeRollback ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  rollback ,  ok  :=  d . GetOk ( "rollback" ) ;  ok  { 
 
			
		
	
		
			
				
							req  :=  compute . StopRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								Force :      false , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Stop ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							rollbackInterface  :=  rollback . ( * schema . Set ) . List ( ) [ 0 ] 
 
			
		
	
		
			
				
							rollbackItem  :=  rollbackInterface . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							rollbackReq  :=  compute . SnapshotRollbackRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								Label :      rollbackItem [ "label" ] . ( string ) , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  =  c . CloudBroker ( ) . Compute ( ) . SnapshotRollback ( ctx ,  rollbackReq ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							startReq  :=  compute . StartRequest { ComputeID :  computeId } 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							log . Debugf ( "utilityComputeRollback: starting compute %d" ,  computeId ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  =  c . CloudBroker ( ) . Compute ( ) . Start ( ctx ,  startReq ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateCD ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldSet ,  newSet  :=  d . GetChange ( "cd" ) 
 
			
		
	
		
			
				
						deletedCd  :=  ( oldSet . ( * schema . Set ) . Difference ( newSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( deletedCd )  >  0  { 
 
			
		
	
		
			
				
							req  :=  compute . CDEjectRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  reason ,  ok  :=  d . GetOk ( "reason" ) ;  ok  { 
 
			
		
	
		
			
				
								req . Reason  =  reason . ( string ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . CDEject ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						addedCd  :=  ( newSet . ( * schema . Set ) . Difference ( oldSet . ( * schema . Set ) ) ) . List ( ) 
 
			
		
	
		
			
				
						if  len ( addedCd )  >  0  { 
 
			
		
	
		
			
				
							cdItem  :=  addedCd [ 0 ] . ( map [ string ] interface { } ) 
 
			
		
	
		
			
				
							req  :=  compute . CDInsertRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								CDROMID :    uint64 ( cdItem [ "cdrom_id" ] . ( int ) ) , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  reason ,  ok  :=  d . GetOk ( "reason" ) ;  ok  { 
 
			
		
	
		
			
				
								req . Reason  =  reason . ( string ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . CDInsert ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputePinToStack ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldPin ,  newPin  :=  d . GetChange ( "pin_to_stack" ) 
 
			
		
	
		
			
				
						if  oldPin . ( bool )  &&  ! newPin . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . UnpinFromStackRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . UnpinFromStack ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						if  ! oldPin . ( bool )  &&  newPin . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . PinToStackRequest { 
 
			
		
	
		
			
				
								ComputeID :      computeId , 
 
			
		
	
		
			
				
								TargetStackID :  uint64 ( d . Get ( "target_stack_id" ) . ( int ) ) , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  force ,  ok  :=  d . Get ( "force_pin" ) . ( bool ) ;  ok  { 
 
			
		
	
		
			
				
								req . Force  =  force 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . PinToStack ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputePause ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldPause ,  newPause  :=  d . GetChange ( "pause" ) 
 
			
		
	
		
			
				
						if  oldPause . ( bool )  &&  ! newPause . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . ResumeRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Resume ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						if  ! oldPause . ( bool )  &&  newPause . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . PauseRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Pause ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeReset ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldReset ,  newReset  :=  d . GetChange ( "reset" ) 
 
			
		
	
		
			
				
						if  ! oldReset . ( bool )  &&  newReset . ( bool )  { 
 
			
		
	
		
			
				
							req  :=  compute . ResetRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Reset ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateImage ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						oldImage ,  newImage  :=  d . GetChange ( "image_id" ) 
 
			
		
	
		
			
				
						stopReq  :=  compute . StopRequest { 
 
			
		
	
		
			
				
							ComputeID :  computeId , 
 
			
		
	
		
			
				
							Force :      false , 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Stop ( ctx ,  stopReq ) 
 
			
		
	
		
			
				
						if  err  !=  nil  { 
 
			
		
	
		
			
				
							return  err 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  oldImage . ( int )  !=  newImage . ( int )  { 
 
			
		
	
		
			
				
							req  :=  compute . RedeployRequest { 
 
			
		
	
		
			
				
								ComputeID :  computeId , 
 
			
		
	
		
			
				
								ImageID :    uint64 ( newImage . ( int ) ) , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							if  diskSize ,  ok  :=  d . GetOk ( "boot_disk_size" ) ;  ok  { 
 
			
		
	
		
			
				
								req . DiskSize  =  uint64 ( diskSize . ( int ) ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  dataDisks ,  ok  :=  d . GetOk ( "data_disks" ) ;  ok  { 
 
			
		
	
		
			
				
								req . DataDisks  =  dataDisks . ( string ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  autoStart ,  ok  :=  d . GetOk ( "auto_start" ) ;  ok  { 
 
			
		
	
		
			
				
								req . AutoStart  =  autoStart . ( bool ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
							if  forceStop ,  ok  :=  d . GetOk ( "force_stop" ) ;  ok  { 
 
			
		
	
		
			
				
								req . ForceStop  =  forceStop . ( bool ) 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . Redeploy ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  utilityComputeUpdateCustomFields ( ctx  context . Context ,  d  * schema . ResourceData ,  m  interface { } )  error  {  
			
		
	
		
			
				
						c  :=  m . ( * controller . ControllerCfg ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						computeId ,  _  :=  strconv . ParseUint ( d . Id ( ) ,  10 ,  64 ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						val  :=  d . Get ( "custom_fields" ) . ( string ) 
 
			
		
	
		
			
				
						val  =  strings . ReplaceAll ( val ,  "\\" ,  "" ) 
 
			
		
	
		
			
				
						val  =  strings . ReplaceAll ( val ,  "\n" ,  "" ) 
 
			
		
	
		
			
				
						val  =  strings . ReplaceAll ( val ,  "\t" ,  "" ) 
 
			
		
	
		
			
				
						val  =  strings . TrimSpace ( val ) 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						if  len ( val )  >  0  { 
 
			
		
	
		
			
				
							req  :=  compute . SetCustomFieldsRequest { 
 
			
		
	
		
			
				
								ComputeID :     computeId , 
 
			
		
	
		
			
				
								CustomFields :  val , 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
							_ ,  err  :=  c . CloudBroker ( ) . Compute ( ) . SetCustomFields ( ctx ,  req ) 
 
			
		
	
		
			
				
							if  err  !=  nil  { 
 
			
		
	
		
			
				
								return  err 
 
			
		
	
		
			
				
							} 
 
			
		
	
		
			
				
						} 
 
			
		
	
		
			
				
						// } else {
 
 
			
		
	
		
			
				
						// 	// req := compute.DeleteCustomFieldsRequest{
 
 
			
		
	
		
			
				
						// 	// 	ComputeID: computeId,
 
 
			
		
	
		
			
				
						// 	// }
 
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
						// 	// _, err := c.CloudBroker().Compute().DeleteCustomFields(ctx, req)
 
 
			
		
	
		
			
				
						// 	// if err != nil {
 
 
			
		
	
		
			
				
						// 	// 	return err
 
 
			
		
	
		
			
				
						// 	// }
 
 
			
		
	
		
			
				
						// }
 
 
			
		
	
		
			
				
						return  nil 
 
			
		
	
		
			
				
					}  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					func  isChangeDisk ( els  [ ] interface { } ,  el  interface { } )  bool  {  
			
		
	
		
			
				
						for  _ ,  elOld  :=  range  els  { 
 
			
		
	
		
			
				
							elOldConv  :=  elOld . ( map [ string ] interface { } )