|
|
|
|
@ -15,6 +15,7 @@ type driverOCI struct {
|
|
|
|
|
computeClient core.ComputeClient
|
|
|
|
|
vcnClient core.VirtualNetworkClient
|
|
|
|
|
cfg *Config
|
|
|
|
|
context context.Context
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewDriverOCI Creates a new driverOCI with a connected compute client and a connected vcn client.
|
|
|
|
|
@ -37,7 +38,7 @@ func NewDriverOCI(cfg *Config) (Driver, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateInstance creates a new compute instance.
|
|
|
|
|
func (d *driverOCI) CreateInstance(publicKey string) (string, error) {
|
|
|
|
|
func (d *driverOCI) CreateInstance(ctx context.Context, publicKey string) (string, error) {
|
|
|
|
|
metadata := map[string]string{
|
|
|
|
|
"ssh_authorized_keys": publicKey,
|
|
|
|
|
}
|
|
|
|
|
@ -69,8 +70,8 @@ func (d *driverOCI) CreateInstance(publicKey string) (string, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateImage creates a new custom image.
|
|
|
|
|
func (d *driverOCI) CreateImage(id string) (core.Image, error) {
|
|
|
|
|
res, err := d.computeClient.CreateImage(context.TODO(), core.CreateImageRequest{CreateImageDetails: core.CreateImageDetails{
|
|
|
|
|
func (d *driverOCI) CreateImage(ctx context.Context, id string) (core.Image, error) {
|
|
|
|
|
res, err := d.computeClient.CreateImage(ctx, core.CreateImageRequest{CreateImageDetails: core.CreateImageDetails{
|
|
|
|
|
CompartmentId: &d.cfg.CompartmentID,
|
|
|
|
|
InstanceId: &id,
|
|
|
|
|
DisplayName: &d.cfg.ImageName,
|
|
|
|
|
@ -84,14 +85,14 @@ func (d *driverOCI) CreateImage(id string) (core.Image, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteImage deletes a custom image.
|
|
|
|
|
func (d *driverOCI) DeleteImage(id string) error {
|
|
|
|
|
_, err := d.computeClient.DeleteImage(context.TODO(), core.DeleteImageRequest{ImageId: &id})
|
|
|
|
|
func (d *driverOCI) DeleteImage(ctx context.Context, id string) error {
|
|
|
|
|
_, err := d.computeClient.DeleteImage(ctx, core.DeleteImageRequest{ImageId: &id})
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetInstanceIP returns the public or private IP corresponding to the given instance id.
|
|
|
|
|
func (d *driverOCI) GetInstanceIP(id string) (string, error) {
|
|
|
|
|
vnics, err := d.computeClient.ListVnicAttachments(context.TODO(), core.ListVnicAttachmentsRequest{
|
|
|
|
|
func (d *driverOCI) GetInstanceIP(ctx context.Context, id string) (string, error) {
|
|
|
|
|
vnics, err := d.computeClient.ListVnicAttachments(ctx, core.ListVnicAttachmentsRequest{
|
|
|
|
|
InstanceId: &id,
|
|
|
|
|
CompartmentId: &d.cfg.CompartmentID,
|
|
|
|
|
})
|
|
|
|
|
@ -103,7 +104,7 @@ func (d *driverOCI) GetInstanceIP(id string) (string, error) {
|
|
|
|
|
return "", errors.New("instance has zero VNICs")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vnic, err := d.vcnClient.GetVnic(context.TODO(), core.GetVnicRequest{VnicId: vnics.Items[0].VnicId})
|
|
|
|
|
vnic, err := d.vcnClient.GetVnic(ctx, core.GetVnicRequest{VnicId: vnics.Items[0].VnicId})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("Error getting VNIC details: %s", err)
|
|
|
|
|
}
|
|
|
|
|
@ -119,8 +120,8 @@ func (d *driverOCI) GetInstanceIP(id string) (string, error) {
|
|
|
|
|
return *vnic.PublicIp, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *driverOCI) GetInstanceInitialCredentials(id string) (string, string, error) {
|
|
|
|
|
credentials, err := d.computeClient.GetWindowsInstanceInitialCredentials(context.TODO(), core.GetWindowsInstanceInitialCredentialsRequest{
|
|
|
|
|
func (d *driverOCI) GetInstanceInitialCredentials(ctx context.Context, id string) (string, string, error) {
|
|
|
|
|
credentials, err := d.computeClient.GetWindowsInstanceInitialCredentials(ctx, core.GetWindowsInstanceInitialCredentialsRequest{
|
|
|
|
|
InstanceId: &id,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
@ -131,8 +132,8 @@ func (d *driverOCI) GetInstanceInitialCredentials(id string) (string, string, er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TerminateInstance terminates a compute instance.
|
|
|
|
|
func (d *driverOCI) TerminateInstance(id string) error {
|
|
|
|
|
_, err := d.computeClient.TerminateInstance(context.TODO(), core.TerminateInstanceRequest{
|
|
|
|
|
func (d *driverOCI) TerminateInstance(ctx context.Context, id string) error {
|
|
|
|
|
_, err := d.computeClient.TerminateInstance(ctx, core.TerminateInstanceRequest{
|
|
|
|
|
InstanceId: &id,
|
|
|
|
|
})
|
|
|
|
|
return err
|
|
|
|
|
@ -140,10 +141,10 @@ func (d *driverOCI) TerminateInstance(id string) error {
|
|
|
|
|
|
|
|
|
|
// WaitForImageCreation waits for a provisioning custom image to reach the
|
|
|
|
|
// "AVAILABLE" state.
|
|
|
|
|
func (d *driverOCI) WaitForImageCreation(id string) error {
|
|
|
|
|
func (d *driverOCI) WaitForImageCreation(ctx context.Context, id string) error {
|
|
|
|
|
return waitForResourceToReachState(
|
|
|
|
|
func(string) (string, error) {
|
|
|
|
|
image, err := d.computeClient.GetImage(context.TODO(), core.GetImageRequest{ImageId: &id})
|
|
|
|
|
image, err := d.computeClient.GetImage(ctx, core.GetImageRequest{ImageId: &id})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
@ -159,10 +160,10 @@ func (d *driverOCI) WaitForImageCreation(id string) error {
|
|
|
|
|
|
|
|
|
|
// WaitForInstanceState waits for an instance to reach the a given terminal
|
|
|
|
|
// state.
|
|
|
|
|
func (d *driverOCI) WaitForInstanceState(id string, waitStates []string, terminalState string) error {
|
|
|
|
|
func (d *driverOCI) WaitForInstanceState(ctx context.Context, id string, waitStates []string, terminalState string) error {
|
|
|
|
|
return waitForResourceToReachState(
|
|
|
|
|
func(string) (string, error) {
|
|
|
|
|
instance, err := d.computeClient.GetInstance(context.TODO(), core.GetInstanceRequest{InstanceId: &id})
|
|
|
|
|
instance, err := d.computeClient.GetInstance(ctx, core.GetInstanceRequest{InstanceId: &id})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
|