NAME
VM::JiffyBox - OO-API for JiffyBox Virtual Machine
VERSION
version 0.024
SYNOPSIS
##############################
# CREATE A CLONE FROM BACKUP #
##############################
# stuff we need to know our self
my $auth_token = $ARGV[0];
my $box_name = $ARGV[1];
my $clone_name = $ARGV[2];
# prepare connection to VM-Server
my $jiffy = VM::JiffyBox->new(token => $auth_token);
# translate VM-Name (String) to ID (Number)
my $master_box_id = $jiffy->get_id_from_name($box_name);
say "master_box_id: $master_box_id";
# prepare connection to the VM
my $master_box = $jiffy->get_vm($master_box_id);
# collect information about the VM
my $backup_id = $master_box->get_backups()->{result}->{daily}->{id};
my $plan_id = $master_box->get_details()->{result}->{plan}->{id};
say "backup_id: $backup_id";
say "plan_id: $plan_id";
# create a clone of the VM
my $clone_box = $jiffy->create_vm( name => $clone_name,
planid => $plan_id,
backupid => $backup_id,
);
# abort if create failed
unless ($clone_box) {
# FAIL
die $jiffy->last->{messages}->[0]->{message};
}
# wait for the clone to be ready
do {
say "waiting for clone to get READY";
sleep 15;
} while (not $clone_box->get_details->{result}->{status} eq 'READY');
# start the clone
$clone_box->start();
(See the examples
directory for more examples of working code.)
ERROR HANDLING
All methods will return 0
on failure, so you can check for this with a simple if
on the return value. If you need the error message you can use the cache and look into the attribute last
. The form of the message is open. It can contain a simple string, or also a hash. This depends on the kind of error. So if you want to be sure, just use Data::Dumper to print it.
CACHING
There are possibilities to take advantage of caching functionality. If you have once called get_details(), the results will be stored in the attribute details_cache
.
METHODS (LOGIC)
Methods that do not send API requests. They are just needed to prepare the requests internally, e.g. due to the OO-design.
get_vm
Returns an object-ref to an existing virtual machine (VM::JiffyBox::Box). Takes the ID for the virtual machine as first argument.
test_mode
If set to any true value methods related to API-calls will just return information about the parameters it would have used to do the call.
METHODS (API)
Methods which are directly related to the official API. A call to such a method will directly lead to an API request to the server.
get_details
Returns hashref with information about the hypervisor and its virtual machines. Takes no arguments.
Results are cached in details_cache
.
create_vm
Creates a new virtual machine and returns an object-ref to it (VM::JiffyBox::Box). You can pass any named arguments as described by the official API from JiffyBox, since they will be transformed directly to JSON
and sent to the API. This means, what is choosen as argument name, will be sent.
- name
-
The name for the new VM. Needed.
- planid
-
The ID for pricing. Needed.
- backupid
-
Name of the backup-image to take. Needed if you don't use
distribution
. - distribution
-
OS for the VM. Needed if you don't use
backupid
. - password
-
Please look up the official API-Docs for description. Optinal.
- use_sskey
-
Please look up the official API-Docs for description. Optinal.
- metadata
-
Please look up the official API-Docs for description. Optinal.
There may be more options. Please see the official documentation of JiffyBox.
Note: This methods interface changed (as announced) and is not compatible with older releases of VM::JiffyBox.
METHODS (SHORTCUTS)
Methods which are not part of the official API, but provide some often needed calls by using the API mentioned above.
get_id_from_name
Returns the ID for a specific virtual machine. Takes the name for the virtual machine as first argument. Returns 0
if there was no match.
(Also updates the details_cache
)
SEE ALSO
Source, contributions, patches: https://github.com/tim-schwarz/VM-JiffyBox
This module is not officially supported by or related to the company domainfactory in Germany. However it aims to provide an interface to the API of their product JiffyBox. So to use this module with success you should also read their API-Documentation, available for registered users of their service.
SPECIAL NOTES
This software was developed together with an apprentice. This is mentioned here to show that this can lead to good modules and encourage programmers to give interesting work to those who are learning.
AUTHOR
Tim Schwarz, Boris Däppen <bdaeppen.perl@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Tim Schwarz, Boris Däppen, plusW.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.