feat(client): implemented getinstance in garm provider
Some checks failed
Go Tests / go-tests (push) Failing after 1m28s
Some checks failed
Go Tests / go-tests (push) Failing after 1m28s
This commit is contained in:
parent
f1f644648f
commit
3f375f88ff
6 changed files with 132 additions and 17 deletions
|
|
@ -34,6 +34,14 @@ func NewConfig(cfgFile string) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
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 {
|
func (c *Config) Validate() error {
|
||||||
|
|
|
||||||
6
config/config.toml
Normal file
6
config/config.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
organization = "edp-developer-framework"
|
||||||
|
region = "EU"
|
||||||
|
|
||||||
|
[cloudlet]
|
||||||
|
name = "Munich"
|
||||||
|
organization = "TelekomOP"
|
||||||
|
|
@ -141,6 +141,56 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
|
||||||
return response.Data, nil
|
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) {
|
func (e *EdgeConnect) RetrieveToken(ctx context.Context) (string, error) {
|
||||||
json_data, err := json.Marshal(map[string]string{
|
json_data, err := json.Marshal(map[string]string{
|
||||||
"username": e.Credentials.Username,
|
"username": e.Credentials.Username,
|
||||||
|
|
@ -221,7 +271,7 @@ func (e *EdgeConnect) DeleteApp(ctx context.Context, appkey AppKey, region strin
|
||||||
return nil
|
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)
|
token, err := e.RetrieveToken(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,11 @@ type NewAppInstanceInput struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstance struct {
|
type AppInstance struct {
|
||||||
Key AppInstanceKey `json:"key"`
|
Key AppInstanceKey `json:"key"`
|
||||||
AppKey AppKey `json:"app_key"`
|
AppKey AppKey `json:"app_key"`
|
||||||
Flavor Flavor `json:"flavor"`
|
Flavor Flavor `json:"flavor"`
|
||||||
|
State string `json:"state"`
|
||||||
|
PowerState string `json:"power_state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstanceKey struct {
|
type AppInstanceKey struct {
|
||||||
|
|
|
||||||
28
lala/lala.go
28
lala/lala.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/internal/client"
|
||||||
|
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/provider"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testManifest = `
|
var testManifest = `
|
||||||
|
|
@ -62,7 +63,7 @@ func main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
e.DeleteAppInstance(ctx, client.AppInstanceKey{
|
/*e.DeleteAppInstance(ctx, client.AppInstanceKey{
|
||||||
Organization: "edp-developer-framework",
|
Organization: "edp-developer-framework",
|
||||||
Name: "mganterInstanceTest",
|
Name: "mganterInstanceTest",
|
||||||
CloudletKey: client.CloudletKey{
|
CloudletKey: client.CloudletKey{
|
||||||
|
|
@ -70,11 +71,7 @@ func main() {
|
||||||
Name: "Munich",
|
Name: "Munich",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
client.AppKey{
|
"EU")
|
||||||
Organization: "edp-developer-framework",
|
|
||||||
Name: "mganter-test",
|
|
||||||
Version: "0.0.1",
|
|
||||||
}, "EU")
|
|
||||||
|
|
||||||
e.DeleteApp(ctx, client.AppKey{
|
e.DeleteApp(ctx, client.AppKey{
|
||||||
Organization: "edp-developer-framework",
|
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)
|
fmt.Printf("Error: %v\n", err)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,11 @@ package provider
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"edp.buildth.ing/DevFW-CICD/garm-provider-edge-connect/config"
|
"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"
|
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.0"
|
||||||
"github.com/cloudbase/garm-provider-common/params"
|
"github.com/cloudbase/garm-provider-common/params"
|
||||||
|
|
@ -31,13 +34,25 @@ func NewEdgeConnectProvider(configPath, controllerID string) (execution.External
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error loading config: %w", err)
|
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{
|
return &edgeConnectProvider{
|
||||||
|
client: client,
|
||||||
controllerID: controllerID,
|
controllerID: controllerID,
|
||||||
cfg: conf,
|
cfg: conf,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type edgeConnectProvider struct {
|
type edgeConnectProvider struct {
|
||||||
|
client client.EdgeConnect
|
||||||
controllerID string
|
controllerID string
|
||||||
cfg *config.Config
|
cfg *config.Config
|
||||||
}
|
}
|
||||||
|
|
@ -65,13 +80,31 @@ func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance strin
|
||||||
// GetInstance will return details about one instance.
|
// GetInstance will return details about one instance.
|
||||||
func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string) (params.ProviderInstance, error) {
|
func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string) (params.ProviderInstance, error) {
|
||||||
providerInstance := params.ProviderInstance{
|
providerInstance := params.ProviderInstance{
|
||||||
ProviderID: "",
|
ProviderID: a.controllerID,
|
||||||
Name: "",
|
Name: instance,
|
||||||
OSType: "",
|
OSType: params.Linux,
|
||||||
OSArch: "",
|
OSArch: params.Amd64,
|
||||||
OSName: "",
|
OSName: "lala",
|
||||||
OSVersion: "",
|
OSVersion: "lalatest",
|
||||||
Status: "running",
|
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
|
return providerInstance, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue