cdbg: allow parsing state to query QEMU instances for cdbg deploy

Signed-off-by: Malte Poll <mp@edgeless.systems>
This commit is contained in:
Malte Poll 2022-05-24 09:44:00 +02:00 committed by Malte Poll
parent ff657a2ee7
commit 6bb393fcb7

View File

@ -20,6 +20,8 @@ func GetScalingGroupsFromConfig(stat state.ConstellationState, config *configc.C
return getGCPInstances(stat, config)
case len(stat.AzureCoordinators) != 0:
return getAzureInstances(stat, config)
case len(stat.QEMUCoordinators) != 0:
return getQEMUInstances(stat, config)
default:
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no instances to init")
}
@ -122,3 +124,32 @@ func getAzureInstances(stat state.ConstellationState, _ *configc.Config) (coordi
}
return
}
func getQEMUInstances(stat state.ConstellationState, _ *configc.Config) (coordinators, nodes cmdc.ScalingGroup, err error) {
coordinatorMap := stat.QEMUCoordinators
if len(coordinatorMap) == 0 {
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
}
var coordinatorInstances cmdc.Instances
for _, node := range coordinatorMap {
coordinatorInstances = append(coordinatorInstances, cmdc.Instance(node))
}
// GroupID of coordinators is empty, since they currently do not scale.
coordinators = cmdc.ScalingGroup{
Instances: coordinatorInstances,
GroupID: "",
}
nodeMap := stat.QEMUNodes
if len(nodeMap) == 0 {
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
}
var nodeInstances cmdc.Instances
for _, node := range nodeMap {
nodeInstances = append(nodeInstances, cmdc.Instance(node))
}
nodes = cmdc.ScalingGroup{
Instances: nodeInstances,
GroupID: "",
}
return
}