c/a/api: reorganize and add AgentInit

Move hardware reporting-related data into a separate file for better
organization.

Also add an AgentInit message which will be used to pass data to the
Agent.

Change-Id: I1eecbd5a78da03170651f76f9f24e134dddaca4f
Reviewed-on: https://review.monogon.dev/c/monogon/+/1140
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Leopold Schabel <leo@monogon.tech>
diff --git a/cloud/shepherd/equinix/manager/initializer.go b/cloud/shepherd/equinix/manager/initializer.go
index 6194f0d..a60f352 100644
--- a/cloud/shepherd/equinix/manager/initializer.go
+++ b/cloud/shepherd/equinix/manager/initializer.go
@@ -323,14 +323,23 @@
 	if err := proto.Unmarshal(stdout, &arsp); err != nil {
 		return nil, fmt.Errorf("agent reply couldn't be unmarshaled: %w", err)
 	}
-	if !proto.Equal(&imsg, arsp.InitMessage) {
+	var successResp *apb.TakeoverSuccess
+	switch r := arsp.Result.(type) {
+	case *apb.TakeoverResponse_Error:
+		return nil, fmt.Errorf("agent returned error: %v", r.Error.Message)
+	case *apb.TakeoverResponse_Success:
+		successResp = r.Success
+	default:
+		return nil, fmt.Errorf("agent returned unknown result of type %T", arsp.Result)
+	}
+	if !proto.Equal(&imsg, successResp.InitMessage) {
 		return nil, fmt.Errorf("agent did not send back the init message.")
 	}
-	if len(arsp.Key) != ed25519.PublicKeySize {
+	if len(successResp.Key) != ed25519.PublicKeySize {
 		return nil, fmt.Errorf("agent key length mismatch.")
 	}
-	klog.Infof("Started the agent (provider ID: %s, key: %s).", d.ID, hex.EncodeToString(arsp.Key))
-	return arsp.Key, nil
+	klog.Infof("Started the agent (provider ID: %s, key: %s).", d.ID, hex.EncodeToString(successResp.Key))
+	return successResp.Key, nil
 }
 
 // init initializes the server described by t, using BMDB session 'sess' to set