feat(client): implemented getinstance in garm provider
Some checks failed
Go Tests / go-tests (push) Failing after 1m28s

This commit is contained in:
Christopher Hase 2025-09-03 13:36:57 +02:00
parent f1f644648f
commit 3f375f88ff
6 changed files with 132 additions and 17 deletions

View file

@ -34,6 +34,14 @@ func NewConfig(cfgFile string) (*Config, error) {
}
type Config struct {
Organization string `toml:"organization"`
CloudletKey CloudletKey `toml:"cloudlet"`
Region string `toml:"region"`
}
type CloudletKey struct {
Organization string `toml:"organization"`
Name string `toml:"name"`
}
func (c *Config) Validate() error {

6
config/config.toml Normal file
View file

@ -0,0 +1,6 @@
organization = "edp-developer-framework"
region = "EU"
[cloudlet]
name = "Munich"
organization = "TelekomOP"

View file

@ -141,6 +141,56 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
return response.Data, nil
}
func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanceKey, region string) (AppInstance, error) {
token, err := e.RetrieveToken(ctx)
if err != nil {
return AppInstance{}, err
}
input := struct {
App struct {
AppInstKey AppInstanceKey `json:"key"`
} `json:"appinst"`
Region string `json:"Region"`
}{
App: struct {
AppInstKey AppInstanceKey `json:"key"`
}{
AppInstKey: appinstkey,
},
Region: region,
}
json_data, err := json.Marshal(input)
if err != nil {
return AppInstance{}, err
}
request, err := http.NewRequestWithContext(ctx, "POST", e.BaseURL+"/api/v1/auth/ctrl/ShowAppInst", bytes.NewBuffer(json_data))
if err != nil {
return AppInstance{}, err
}
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
resp, err := e.HttpClient.Do(request)
if err != nil {
return AppInstance{}, err
}
defer resp.Body.Close()
var response struct {
Data AppInstance `json:"data"`
}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return AppInstance{}, err
}
return response.Data, nil
}
func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
json_data, err := json.Marshal(map[string]string{
"username": e.Credentials.Username,
@ -221,7 +271,7 @@ func (e *EdgeConnect) DeleteApp(ctx context.Context, appkey AppKey, region strin
return nil
}
func (e *EdgeConnect) DeleteAppInstance(ctx context.Context, appinstancekey AppInstanceKey, appkey AppKey, region string) error {
func (e *EdgeConnect) DeleteAppInstance(ctx context.Context, appinstancekey AppInstanceKey, region string) error {
token, err := e.RetrieveToken(ctx)
if err != nil {
return err

View file

@ -6,9 +6,11 @@ type NewAppInstanceInput struct {
}
type AppInstance struct {
Key AppInstanceKey `json:"key"`
AppKey AppKey `json:"app_key"`
Flavor Flavor `json:"flavor"`
Key AppInstanceKey `json:"key"`
AppKey AppKey `json:"app_key"`
Flavor Flavor `json:"flavor"`
State string `json:"state"`
PowerState string `json:"power_state"`
}
type AppInstanceKey struct {

View file

@ -7,6 +7,7 @@ import (
"os"
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/provider"
)
var testManifest = `
@ -62,7 +63,7 @@ func main() {
},
}
e.DeleteAppInstance(ctx, client.AppInstanceKey{
/*e.DeleteAppInstance(ctx, client.AppInstanceKey{
Organization: "edp-developer-framework",
Name: "mganterInstanceTest",
CloudletKey: client.CloudletKey{
@ -70,11 +71,7 @@ func main() {
Name: "Munich",
},
},
client.AppKey{
Organization: "edp-developer-framework",
Name: "mganter-test",
Version: "0.0.1",
}, "EU")
"EU")
e.DeleteApp(ctx, client.AppKey{
Organization: "edp-developer-framework",
@ -134,6 +131,25 @@ func main() {
},
})
fmt.Printf("Error: %v\n", err)*/
appinst, err := e.ShowAppInstance(ctx, client.AppInstanceKey{
Organization: "edp-developer-framework",
Name: "mganterInstanceTest",
CloudletKey: client.CloudletKey{
Organization: "TelekomOP",
Name: "Munich",
},
},
"EU")
fmt.Printf("appinst: %v\n", appinst)
fmt.Printf("Error: %v\n", err)
edgeprovider, err := provider.NewEdgeConnectProvider("/home/chris/ipcei/projects/garm-provider-edge-connect/config/config.toml", "lalacontroller")
providerinst, err := edgeprovider.GetInstance(ctx, appinst.Key.Name)
fmt.Printf("provider: %v\n", providerinst)
fmt.Printf("Error: %v\n", err)
/*

View file

@ -17,8 +17,11 @@ package provider
import (
"context"
"fmt"
"net/http"
"os"
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/config"
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.0"
"github.com/cloudbase/garm-provider-common/params"
@ -31,13 +34,25 @@ func NewEdgeConnectProvider(configPath, controllerID string) (execution.External
if err != nil {
return nil, fmt.Errorf("error loading config: %w", err)
}
client := client.EdgeConnect{
BaseURL: "https://hub.apps.edge.platform.mg3.mdb.osc.live",
HttpClient: &http.Client{},
Credentials: client.Credentials{
Username: os.Getenv("EDGEXR_USERNAME"),
Password: os.Getenv("EDGEXR_PASSWORD"),
},
}
return &edgeConnectProvider{
client: client,
controllerID: controllerID,
cfg: conf,
}, nil
}
type edgeConnectProvider struct {
client client.EdgeConnect
controllerID string
cfg *config.Config
}
@ -65,13 +80,31 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
// GetInstance will return details about one instance.
func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string) (params.ProviderInstance, error) {
providerInstance := params.ProviderInstance{
ProviderID: "",
Name: "",
OSType: "",
OSArch: "",
OSName: "",
OSVersion: "",
Status: "running",
ProviderID: a.controllerID,
Name: instance,
OSType: params.Linux,
OSArch: params.Amd64,
OSName: "lala",
OSVersion: "lalatest",
Status: params.InstanceStatusUnknown,
}
appinstkey := client.AppInstanceKey{
Organization: a.cfg.Organization,
Name: instance,
CloudletKey: client.CloudletKey{
Organization: a.cfg.CloudletKey.Organization,
Name: a.cfg.CloudletKey.Name,
},
}
appinst, err := a.client.ShowAppInstance(ctx, appinstkey, a.cfg.Region)
if err != nil {
return params.ProviderInstance{}, err
}
if appinst.State == "Ready" {
providerInstance.Status = params.InstanceRunning
}
return providerInstance, nil