2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/oracle/oci-go-sdk/core"
|
|
|
|
)
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
// driverMock implements the Driver interface and communicates with Oracle
|
2017-09-12 11:30:39 -04:00
|
|
|
// OCI.
|
2017-02-13 05:35:14 -05:00
|
|
|
type driverMock struct {
|
|
|
|
CreateInstanceID string
|
|
|
|
CreateInstanceErr error
|
|
|
|
|
|
|
|
CreateImageID string
|
|
|
|
CreateImageErr error
|
|
|
|
|
|
|
|
DeleteImageID string
|
|
|
|
DeleteImageErr error
|
|
|
|
|
|
|
|
GetInstanceIPErr error
|
|
|
|
|
|
|
|
TerminateInstanceID string
|
|
|
|
TerminateInstanceErr error
|
|
|
|
|
|
|
|
WaitForImageCreationErr error
|
|
|
|
|
|
|
|
WaitForInstanceStateErr error
|
2018-02-13 08:20:26 -05:00
|
|
|
|
|
|
|
cfg *Config
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateInstance creates a new compute instance.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) CreateInstance(ctx context.Context, publicKey string) (string, error) {
|
2017-02-13 05:35:14 -05:00
|
|
|
if d.CreateInstanceErr != nil {
|
|
|
|
return "", d.CreateInstanceErr
|
|
|
|
}
|
|
|
|
|
|
|
|
d.CreateInstanceID = "ocid1..."
|
|
|
|
|
|
|
|
return d.CreateInstanceID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateImage creates a new custom image.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) CreateImage(ctx context.Context, id string) (core.Image, error) {
|
2017-02-13 05:35:14 -05:00
|
|
|
if d.CreateImageErr != nil {
|
2018-04-11 05:20:40 -04:00
|
|
|
return core.Image{}, d.CreateImageErr
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
d.CreateImageID = id
|
2018-04-11 05:20:40 -04:00
|
|
|
return core.Image{Id: &id}, nil
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteImage mocks deleting a custom image.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) DeleteImage(ctx context.Context, id string) error {
|
2017-02-13 05:35:14 -05:00
|
|
|
if d.DeleteImageErr != nil {
|
|
|
|
return d.DeleteImageErr
|
|
|
|
}
|
|
|
|
|
|
|
|
d.DeleteImageID = id
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-02-13 08:20:26 -05:00
|
|
|
// GetInstanceIP returns the public or private IP corresponding to the given instance id.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) GetInstanceIP(ctx context.Context, id string) (string, error) {
|
2017-02-13 05:35:14 -05:00
|
|
|
if d.GetInstanceIPErr != nil {
|
|
|
|
return "", d.GetInstanceIPErr
|
|
|
|
}
|
2018-02-13 08:20:26 -05:00
|
|
|
if d.cfg.UsePrivateIP {
|
|
|
|
return "private_ip", nil
|
|
|
|
}
|
2017-02-13 05:35:14 -05:00
|
|
|
return "ip", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TerminateInstance terminates a compute instance.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) TerminateInstance(ctx context.Context, id string) error {
|
2017-02-13 05:35:14 -05:00
|
|
|
if d.TerminateInstanceErr != nil {
|
|
|
|
return d.TerminateInstanceErr
|
|
|
|
}
|
|
|
|
|
|
|
|
d.TerminateInstanceID = id
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// WaitForImageCreation waits for a provisioning custom image to reach the
|
|
|
|
// "AVAILABLE" state.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) WaitForImageCreation(ctx context.Context, id string) error {
|
2017-02-13 05:35:14 -05:00
|
|
|
return d.WaitForImageCreationErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// WaitForInstanceState waits for an instance to reach the a given terminal
|
|
|
|
// state.
|
2018-06-26 05:05:56 -04:00
|
|
|
func (d *driverMock) WaitForInstanceState(ctx context.Context, id string, waitStates []string, terminalState string) error {
|
2017-02-13 05:35:14 -05:00
|
|
|
return d.WaitForInstanceStateErr
|
|
|
|
}
|