This commit is contained in:
parent
8884165ffe
commit
044f1b04b8
5 changed files with 34 additions and 19 deletions
|
|
@ -34,6 +34,7 @@ func NewConfig(cfgFile string) (*Config, error) {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
LogFile string `toml:"log_file"`
|
||||
Organization string `toml:"organization"`
|
||||
CloudletKey CloudletKey `toml:"cloudlet"`
|
||||
Region string `toml:"region"`
|
||||
|
|
@ -45,5 +46,9 @@ type CloudletKey struct {
|
|||
}
|
||||
|
||||
func (c *Config) Validate() error {
|
||||
if c.LogFile == "" {
|
||||
return fmt.Errorf("log_file is not defined in provider config")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
organization = "edp-developer-framework"
|
||||
region = "EU"
|
||||
log_file = "./lala.log"
|
||||
|
||||
[cloudlet]
|
||||
name = "Munich"
|
||||
|
|
|
|||
|
|
@ -26,16 +26,19 @@ type Credentials struct {
|
|||
func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceInput) error {
|
||||
token, err := e.RetrieveToken(ctx)
|
||||
if err != nil {
|
||||
log.Printf("failed to retrieve token %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
json_data, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
log.Printf("failed to marshal NewAppInstanceInput %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", e.BaseURL+"/api/v1/auth/ctrl/CreateAppInst", bytes.NewBuffer(json_data))
|
||||
if err != nil {
|
||||
log.Printf("failed to create request %v\n", err)
|
||||
return err
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
|
|
@ -43,17 +46,14 @@ func (e *EdgeConnect) NewAppInstance(ctx context.Context, input NewAppInstanceIn
|
|||
|
||||
resp, err := e.HttpClient.Do(request)
|
||||
if err != nil {
|
||||
log.Printf("failed to execute request %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
/*fmt.Printf("Header: %v\n", request.Header)
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
if resp.StatusCode != 200 {
|
||||
log.Printf("failed received non 200 status code %v\n", resp.Status)
|
||||
}
|
||||
fmt.Printf("Response: %v\n", string(bodyBytes))*/
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -80,16 +80,8 @@ func (e *EdgeConnect) NewApp(ctx context.Context, input NewAppInput) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
/*fmt.Printf("Header: %v\n", request.Header)
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Response: %v\n", string(bodyBytes))*/
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
12
main.go
12
main.go
|
|
@ -17,6 +17,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
|
@ -31,7 +32,6 @@ var signals = []os.Signal{
|
|||
}
|
||||
|
||||
func main() {
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), signals...)
|
||||
defer stop()
|
||||
|
||||
|
|
@ -41,12 +41,20 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
prov, err := provider.NewEdgeConnectProvider(executionEnv.ProviderConfigFile, executionEnv.ControllerID)
|
||||
prov, logFilePath, err := provider.NewEdgeConnectProvider(executionEnv.ProviderConfigFile, executionEnv.ControllerID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error creating provider: %q", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logFile, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
defer logFile.Close()
|
||||
// set log out put
|
||||
log.SetOutput(logFile)
|
||||
|
||||
result, err := executionEnv.Run(ctx, prov)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to run command: %+v\n", err)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -35,10 +36,10 @@ import (
|
|||
|
||||
var Version = "v0.0.0-unknown"
|
||||
|
||||
func NewEdgeConnectProvider(configPath, controllerID string) (execution.ExternalProvider, error) {
|
||||
func NewEdgeConnectProvider(configPath, controllerID string) (execution.ExternalProvider, string, error) {
|
||||
conf, err := config.NewConfig(configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading config: %w", err)
|
||||
return nil, "", fmt.Errorf("error loading config: %w", err)
|
||||
}
|
||||
|
||||
client := client.EdgeConnect{
|
||||
|
|
@ -54,7 +55,7 @@ func NewEdgeConnectProvider(configPath, controllerID string) (execution.External
|
|||
client: client,
|
||||
controllerID: controllerID,
|
||||
cfg: conf,
|
||||
}, nil
|
||||
}, conf.LogFile, nil
|
||||
}
|
||||
|
||||
type edgeConnectProvider struct {
|
||||
|
|
@ -65,6 +66,7 @@ type edgeConnectProvider struct {
|
|||
|
||||
// CreateInstance creates a new compute instance in the provider.
|
||||
func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParams params.BootstrapInstance) (params.ProviderInstance, error) {
|
||||
log.Printf("Executing CreateInstance with %v\n", bootstrapParams)
|
||||
|
||||
instancename := fmt.Sprintf("garm-%v-%v-%v", a.controllerID, bootstrapParams.PoolID, bootstrapParams.Name)
|
||||
|
||||
|
|
@ -190,6 +192,7 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
|
||||
// Delete instance will delete the instance in a provider.
|
||||
func (a *edgeConnectProvider) DeleteInstance(ctx context.Context, instance string) error {
|
||||
log.Printf("Executing DeleteInstance %s\n", instance)
|
||||
|
||||
appinstkey := client.AppInstanceKey{
|
||||
Organization: a.cfg.Organization,
|
||||
|
|
@ -221,6 +224,7 @@ 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) {
|
||||
log.Printf("Executing GetInstance %s\n", instance)
|
||||
providerInstance := params.ProviderInstance{
|
||||
ProviderID: a.controllerID,
|
||||
Name: instance,
|
||||
|
|
@ -254,6 +258,7 @@ func (a *edgeConnectProvider) GetInstance(ctx context.Context, instance string)
|
|||
|
||||
// ListInstances will list all instances for a provider.
|
||||
func (a *edgeConnectProvider) ListInstances(ctx context.Context, poolID string) ([]params.ProviderInstance, error) {
|
||||
log.Printf("Executing ListInstances for PoolID %s\n", poolID)
|
||||
|
||||
apps, err := a.client.ShowAppInstances(ctx, client.AppInstanceKey{
|
||||
Organization: a.cfg.Organization,
|
||||
|
|
@ -301,6 +306,8 @@ func filter[T any](s []T, predicate func(T) bool) []T {
|
|||
|
||||
// RemoveAllInstances will remove all instances created by this provider.
|
||||
func (a *edgeConnectProvider) RemoveAllInstances(ctx context.Context) error {
|
||||
log.Printf("Executing RemoveAllInstances\n")
|
||||
|
||||
apps, err := a.client.ShowAppInstances(ctx, client.AppInstanceKey{
|
||||
Organization: a.cfg.Organization,
|
||||
}, a.cfg.Region)
|
||||
|
|
@ -325,11 +332,13 @@ func (a *edgeConnectProvider) RemoveAllInstances(ctx context.Context) error {
|
|||
|
||||
// Stop shuts down the instance.
|
||||
func (a *edgeConnectProvider) Stop(ctx context.Context, instance string, force bool) error {
|
||||
log.Printf("Executing Stop %s\n", instance)
|
||||
panic(fmt.Sprintf("Stop() not implemented, called with instance: %s, force: %t", instance, force))
|
||||
}
|
||||
|
||||
// Start boots up an instance.
|
||||
func (a *edgeConnectProvider) Start(ctx context.Context, instance string) error {
|
||||
log.Printf("Executing Start %s\n", instance)
|
||||
panic(fmt.Sprintf("Start() not implemented, called with instance: %s", instance))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue