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