VM::JiffyBox - OO-API for JiffyBox Virtual Machine
version 0.032
############################## # 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.)
examples
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.
0
if
last
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.
details_cache
Methods that do not send API requests. They are just needed to prepare the requests internally, e.g. due to the OO-design.
Returns an object-ref to an existing virtual machine (VM::JiffyBox::Box). Takes the ID for the virtual machine as first argument.
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 which are directly related to the official API. A call to such a method will directly lead to an API request to the server.
Returns hashref with information about the hypervisor and its virtual machines. Takes no arguments.
Results are cached in details_cache.
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.
JSON
The name for the new VM. Needed.
The ID for pricing. Needed.
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.
backupid
Please look up the official API-Docs for description. Optinal.
There may be more options. Please see the official documentation of JiffyBox.
Get information about available distribution images for the virtual machines. Returns a hashref.
Get information about existing plans (pricing). Takes no arguments. Returns a hashref.
Returns details for a plan-id or name (pricing model). Pass name or ID as an argument to the method. Returns a hashref.
Returns a list of VM::JiffyBox::Box objects, where each object represents an existing box.
VM::JiffyBox::Box
my @boxes = $jb->get_vms(); for my $box ( @boxes ) { print $box->name, "\n"; }
Methods which are not part of the official API, but provide some often needed calls by using the API mentioned above.
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)
This is a software library for the perl programming language.
Source, contributions, patches: https://github.com/borisdaeppen/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.
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.
Boris Däppen
Renée Bäcker
Tim Schwarz
Tim Schwarz, Boris Däppen <bdaeppen.perl@gmail.com>
This software is copyright (c) 2016 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.
To install VM::JiffyBox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm VM::JiffyBox
CPAN shell
perl -MCPAN -e shell install VM::JiffyBox
For more information on module installation, please visit the detailed CPAN module installation guide.