switch from list (slice) to dict (map)
This commit is contained in:
		
							
								
								
									
										7
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								main.go
									
									
									
									
									
								
							| @@ -17,9 +17,14 @@ func main() { | ||||
|  | ||||
| 	ConfigPath = "config.yaml" | ||||
| 	 | ||||
| 	config := state.LoadConf(ConfigPath) | ||||
|     // Initialize the config.Services map | ||||
| 	var config state.Config | ||||
| 	config.MTD.Services = make(map[state.CustomUUID]state.Service) | ||||
|  | ||||
| 	config = state.LoadConf(ConfigPath) | ||||
| 	state.SaveConf(ConfigPath, config) | ||||
|  | ||||
|  | ||||
| 	config = indexAllInstances(config) | ||||
|  | ||||
| 	//TODO: figure out migration (MTD) | ||||
|   | ||||
| @@ -11,7 +11,17 @@ import ( | ||||
|  | ||||
| // AWSMoveInstance moves a specified instance to a new availability region | ||||
| func AWSMoveInstance(config state.Config) (state.Config) { | ||||
| 	instance := config.MTD.Services[0] // for testing use first instance | ||||
| 	// pseudorandom instance from all services for testing | ||||
| 	var serviceUUID state.CustomUUID | ||||
| 	var instance state.Service | ||||
| 	for key, service := range config.MTD.Services { | ||||
| 		serviceUUID = key | ||||
| 		instance = service | ||||
| 		break | ||||
| 	} | ||||
|  | ||||
| 	fmt.Println("MTD move service:\t", serviceUUID) | ||||
|  | ||||
| 	region, instanceID := DecodeCloudID(instance.CloudID) | ||||
| 	awsConfig := NewConfig(region, config.AWS.CredentialsPath) | ||||
| 	svc := ec2.NewFromConfig(awsConfig) | ||||
| @@ -27,14 +37,14 @@ func AWSMoveInstance(config state.Config) (state.Config) { | ||||
| 		fmt.Println("Error creating image:\t", err) | ||||
| 		return config | ||||
| 	} | ||||
| 	fmt.Println("Created image:\t", imageName) | ||||
| 	fmt.Println("Created image:\t\t", imageName) | ||||
|  | ||||
| 	err = waitForImageReady(svc, imageName, 5*time.Minute) | ||||
| 	if err != nil { | ||||
| 		fmt.Println("Error waiting for image to be ready:\t", err) | ||||
| 		return config | ||||
| 	} | ||||
| 	fmt.Println("Image is ready:\t", imageName) | ||||
| 	fmt.Println("Image is ready:\t\t", imageName) | ||||
|  | ||||
| 	newInstanceID, err := launchInstance(svc, realInstance, imageName) | ||||
| 	if err != nil { | ||||
| @@ -48,7 +58,7 @@ func AWSMoveInstance(config state.Config) (state.Config) { | ||||
| 		fmt.Println("Error terminating instance:\t", err) | ||||
| 		return config | ||||
| 	} | ||||
| 	fmt.Println("Terminated old instance:\t", instanceID) | ||||
| 	fmt.Println("Killed old instance:\t", instanceID) | ||||
|  | ||||
| 	image, err := describeImage(svc, imageName) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -17,12 +17,12 @@ type Config struct { | ||||
| } | ||||
|  | ||||
| type mtdconf struct { | ||||
|     Services        []Service   `yaml:"services"` | ||||
|     Services        map[CustomUUID]Service `yaml:"services"` | ||||
|  | ||||
| } | ||||
|  | ||||
| // Service contains all necessary information about a service to identify it in the cloud as well as configuring a proxy for it | ||||
| type Service struct { | ||||
|     ID              CustomUUID  `yaml:"id"` | ||||
|     CloudID         string      `yaml:"cloud_id"` | ||||
|     EntryIP         netip.Addr  `yaml:"entry_ip"` | ||||
|     EntryPort       uint16      `yaml:"entry_port"` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 schulze
					schulze