To be able to integrate VirtualBox with the Oracle Cloud Infrastructure, we need to be
able to manage, and create, and delete resources from the cloud using VirtualBox and its interface.
To do this we need to create an API key pair so that VirtualBox can authenticate with the
Oracle Cloud Infrastructure in order to be able to utilize and manage these resources.
The VirtualBox documentation has a section about how to integrate VirtualBox with the
Oracle Cloud Infrastructure, and it has details about how to create the
keys and use your profile to upload your key to your profile in the cloud console,
and how to set up the VirtualBox profile in order to integrate with Oracle Cloud Infrastructure.
You can read all about this at this link to the VirtualBox documentation.
So to begin let's create the key pair.
As I am using VirtualBox on Microsoft Windows, I would need to install the openssl application.
Another way to do it is I am going to use GitBash on my machine,
which will provide a Linux environment and access to the openssl application.
So the first thing we are going to do is create a directory where we can store our key files.
We are going to call it apikey, so we use the command mkdir apikey.
Let's change into that directory to prepare to create the key.
We use the openssl command with the genrsa option, and we output with the
-out oci-api-key.pem for the file to be created.
And we are going to create a file with a key length of 2048 bits,
we could create bigger, but this is good enough for now.
We are not generating a passphrase here,
so we are not including the options in the command, so this should be sufficient.
Pressing return, our key file is created and we are returned to the command prompt.
Next we will use the chmod command with 600 for the option to change the permissions for the file.
So we are going to give the user read write
permissions and the group and others no permissions.
That's the private key created, so next we are going to create the public key.
We use the openssl command again with rsa -pubout -in and then the name of the private key,
oci-api-key.pem, then the -out option and specify the name of the public key to be created.
After that's done, if we use the ls command we can see both keys created in our directory apikey.
Next we need to upload our public key to our Oracle Cloud Infrastructure console user settings.
There is an API key section which allows us to upload the key,
or drag and drop the key, so that our VirtualBox can integrate and operate
with the Oracle Cloud Infrastructure and utilize and manage resources.
To do this we go to our profile information at the top right under our icon for our profile.
Select user settings, scroll to API Keys, and here we have the option to add in an API key.
Clicking on Add API Key we get a dialog where we can have an API key pair generated for us,
and we can then download the public and private keys.
Or we can choose to upload a public key,
or we can paste in the contents of a public key into the dialog.
Because we have already created the keys we are going to take the Choose Public key File option.
We open up our Windows Explorer to our apikey folder, and we simply drag and drop
our oci-api-key-public.pem file into the dialog.
Here we can see the file has been uploaded.
Now we click Add to add this key, and associate it with our profile, so we click Add.
This now gives us a Configuration File Preview window, giving us a fingerprint and also its
association with our user profile, and our profile related components of the cloud console.
There is also details of how this information can be used
to create a config file on our system if required.
We will use this information also in our VirtualBox cloud profile when we set it up,
so let's go back to VirtualBox now and do that.
Back on VirtualBox we will click on the Tools menu, and then select Cloud.
This now displays the OCI group, which is where any cloud VMs would be displayed.
And we can see there is already an OCI profile configured.
We can have multiple profiles here to work with different compartments
and tenancies on our cloud infrastructure.
And by simply ticking the box under List VMs,
then we get to see those particular VMs associated with those profiles.
To create a new profile we click Add, which opens up a small dialog,
which allows us to insert the name of the new profile we want to add.
So I am going to put in OCIAPI and click OK to create the profile.
And here we can see it listed.
If I click on the name of the profile, we see user, the tenancy, the region,
a passphrase if we created one for the key, or not, the key file location for
the private key on our local machine, the fingerprint of the key file that was used,
and then a compartment to identify which resources we could use with this profile.
For security reasons, as I set up the cloud profile,
I will be partially obscuring parts of the OCID values.
So first let's add the user OCID,
returning to our console we still have the Configuration File Preview.
First let's highlight our user OCID value, and then we will paste that into our VirtualBox field.
To paste it in we simply double click on the field,
and that allows us to input something either by typing or by pasting.
Next we will get the tenancy information, again to our console file preview window,
and we copy the tenancy OCID value.
Next we will get the region information, so returning to our console we copy the region value,
us-ashburn-1, and go back to our VirtualBox profile and double click and paste that in.
As we did not create a passphrase when creating the key, we don't
have one to insert here, so it's not needed.
So next let's get the fingerprint for the key pair, again back to our console,
and we copy the fingerprint information, return to our VBox, double click and paste that in also.
Now we identify where the private key file is
located on our local machine where VBox is operating from.
So we open up our Windows Explorer,
go to our apikey folder, and copy the name of our private key.
Return to our profile, I type in the path to
the folder c:\apikey\ and then paste in the name of the file.
And finally we want to identify the compartment in our cloud from which
VirtualBox will be managing resources in and requesting resources from.
To get the compartment name, if we don't know it already, can return to our console
and close the Configuration File Preview Window, and we go to our cloud console menu.
And on the home page we can see that under Recently Visited there
is a link to Compartments and Identity.
But if we did not have this here, we could simply go down in the menu and
find Identity and Security and we would be able to see Compartments there also.
So let's click on Compartments Identity.
After waiting a few seconds we get a full list of compartments,
we have quite an extensive list here, actually two pages worth,
so I am going to go to the second page to find the one that I want to work with.
Scrolling down to the bottom I can see the name virtdoc, here I can very quickly get the
OCID value for this compartment by hovering over the OCID value under the OCID column.
And this gives us a pop up with the option to copy the value directly from here, so let's click Copy.
And we return to our VirtualBox profile,
double click on the compartment field and insert the OCID value for that compartment.
Lastly we click Apply and that's the profile created.
So now let's just quickly go in and make sure that the profile is actually talking with the console.
If we click on the OCIAPI group name,
we get the options to create a new instance or add and instance.
So let's just click on one of these, for instance let's take the Add Machine option.
This opens up the Add Cloud Virtual Machine dialog, and straight away there should be
communication between VirtualBox and our console using the API key to authenticate.
We can see in the notifications window that a list of cloud source instances is
being downloaded, which will then appear in the instances window.
And there we go, that's our list of instances that has been downloaded.
So that proves that we have got communication working using the API key to authenticate,
and we now have our VirtualBox integrated with Oracle Cloud Infrastructure.