view release on metacpan or search on metacpan
eg/deploy.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Juju;
use Data::Dumper;
$Data::Dumper::Indent = 1;
my $client = Juju->new(
endpoint => $ENV{JUJU_ENDPOINT},
password => $ENV{JUJU_PASS}
);
$client->login;
$client->deploy(
charm => 'mysql',
service_name => 'mysql',
cb => sub {
my $val = shift;
print Dumper($val);
}
eg/envinfo.pl view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Juju;
use Data::Dumper::Concise;
my $client = Juju->new(
endpoint => $ENV{JUJU_ENDPOINT},
password => $ENV{JUJU_PASS}
);
$client->login;
my $status = $client->status;
warn Dumper($status);
my $machines = [keys %{$status->{Response}->{Machines}}];
warn Dumper($machines);
# Easily destroy machines
lib/Juju/Environment.pm view on Meta::CPAN
use YAML::Tiny qw(Dump);
use Function::Parameters;
use Juju::Util;
use Juju::Error::Environment;
use namespace::autoclean;
with 'Juju::RPC';
has password => (is => 'ro', isa => 'Str', required => 1);
has is_authenticated => (is => 'rw', isa => 'Int', default => 0);
has endpoint => (
is => 'ro',
isa => 'Str',
default => 'wss://localhost:17070',
required => 1
);
has username => (is => 'ro', isa => 'Str', default => 'user-admin');
has Jobs => (
is => 'ro',
isa => 'HashRef',
builder => '_build_Jobs',
lib/Juju/Environment.pm view on Meta::CPAN
};
# block
return $self->call($params) unless $cb;
# non-block
return $self->call($params, $cb);
}
method add_relation (Str $endpoint_a, Str $endpoint_b, $cb = undef) {
my $params = {
'Type' => 'Client',
'Request' => 'AddRelation',
'Params' => {'Endpoints' => [$endpoint_a, $endpoint_b]}
};
# block
return $self->call($params) unless $cb;
# non-block
return $self->call($params, $cb);
}
method destroy_relation (Str $endpoint_a, Str $endpoint_b, $cb = undef) {
my $params = {
'Type' => 'Client',
'Request' => 'DestroyRelation',
'Params' => {'Endpoints' => [$endpoint_a, $endpoint_b]}
};
# block
return $self->call($params) unless $cb;
# non-block
return $self->call($params, $cb);
}
lib/Juju/Environment.pm view on Meta::CPAN
=head1 VERSION
version 2.002
=head1 SYNOPSIS
use Juju;
my $juju =
Juju->new(endpoint => 'wss://localhost:17070', password => 's3cr3t');
=head1 ATTRIBUTES
=head2 endpoint
Websocket address
=head2 username
Juju admin user, this is a tag and should not need changing from the
default.
B<Note> This will be changing once multiple user support is released.
lib/Juju/Environment.pm view on Meta::CPAN
=head2 add_relation
Sets a relation between units
B<Params>
=over 4
=item *
C<endpoint_a>
First unit endpoint
=item *
C<endpoint_b>
Second unit endpoint
=back
=head2 destroy_relation
Removes relation between endpoints
B<Params>
=over 4
=item *
C<endpoint_a>
First unit endpoint
=item *
C<endpoint_b>
Second unit endpoint
=back
=head2 deploy
Deploys a charm to service
$juju->deploy(
'mysql',
'mysql',
lib/Juju/Manual/Quickstart.pod view on Meta::CPAN
See more information on the workings of juju at
L<http://juju.ubuntu.com>
=head1 USING
To get started initialize the Juju class:
use Juju;
# Open connection over the websocket protocol
my $juju = Juju->new(endpoint => 'wss://192.168.122.16:17070',
password => '8fdsaf0fda');
$juju->login;
$juju->status(
sub {
my $status = shift;
print $status->{UUID};
}
);
# Close the connection
$juju->close;
The password is found in the B<~/.juju/environments/'env'.jenv> under
C<password>.
There is a B<port (17070)> for accessing the machine resources. To see what state
servers are available to you run:
$ juju api-endpoints
=head1 AUTHOR
Adam Stokes <adamjs@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2014 by Adam Stokes.
This is free software, licensed under:
lib/Juju/RPC.pm view on Meta::CPAN
use Function::Parameters;
has conn => (is => 'rw');
has result => (is => 'rw');
has is_connected => (is => 'rw');
has done => (is => 'rw');
has request_id => (is => 'rw', isa => 'Int', default => 1);
method BUILD {
my $client = AnyEvent::WebSocket::Client->new(ssl_no_verify => 1);
$self->conn($client->connect($self->endpoint)->recv);
$self->is_connected(1);
$self->conn->on(
each_message => sub {
my ($conn, $message) = @_;
my $body = decode_json($message->decoded_body);
if (defined($body->{Response})) {
$self->done->send($body);
}
}
t/01-auth.t view on Meta::CPAN
use lib "$FindBin::Bin/../lib";
plan skip_all =>
'must export JUJU_PASS and JUJU_ENDPOINT to enable these tests'
unless $ENV{JUJU_PASS} && $ENV{JUJU_ENDPOINT};
diag("JUJU Authentication");
use_ok('Juju');
my $juju_pass = $ENV{JUJU_PASS};
my $juju_endpoint = $ENV{JUJU_ENDPOINT};
my $juju_badpass = 'abacadaba';
my $juju = Juju->new(endpoint => $juju_endpoint, password => $juju_pass);
ok($juju->isa('Juju'), 'Is juju instance');
$juju->login;
ok($juju->is_authenticated == 1, "Authenticated properly");
# test failed login
$juju = Juju->new(endpoint => $juju_endpoint, password => $juju_badpass);
dies_ok { $juju->login } "Failed login.";
done_testing();
t/02-environment.t view on Meta::CPAN
use Test::Exception;
plan skip_all =>
'must export JUJU_PASS and JUJU_ENDPOINT to enable these tests'
unless $ENV{JUJU_PASS} && $ENV{JUJU_ENDPOINT};
diag("JUJU Environment tests");
use_ok('Juju');
my $juju_pass = $ENV{JUJU_PASS};
my $juju_endpoint = $ENV{JUJU_ENDPOINT};
my $juju = Juju->new(endpoint => $juju_endpoint, password => $juju_pass);
$juju->login;
# ENVIRONMENT -----------------------------------------------------------------
$juju->environment_info(
sub {
my $val = shift->{Response};
ok(defined($val->{UUID}), "Should get environment.");
}
);
t/03-machines.t view on Meta::CPAN
use DDP;
plan skip_all =>
'must export JUJU_PASS and JUJU_ENDPOINT to enable these tests'
unless $ENV{JUJU_PASS} && $ENV{JUJU_ENDPOINT};
diag("JUJU Machine administration");
use_ok('Juju');
my $juju_pass = $ENV{JUJU_PASS};
my $juju_endpoint = $ENV{JUJU_ENDPOINT};
my $juju = Juju->new(endpoint => $juju_endpoint, password => $juju_pass);
$juju->login;
dies_ok {$juju->add_machine } "Dies on no params";
$juju->add_machine(
'trusty', {}, "", "", "",
sub {
my $val = shift->{Response};
my $machine = $val->{Machines}->[0];
ok(!defined($machine->{Error}), "Add machine worked.");
t/04-deploy.t view on Meta::CPAN
use Test::Exception;
plan skip_all =>
'must export JUJU_PASS and JUJU_ENDPOINT to enable these tests'
unless $ENV{JUJU_PASS} && $ENV{JUJU_ENDPOINT};
diag("JUJU Service Deploy");
use_ok('Juju');
my $juju_pass = $ENV{JUJU_PASS};
my $juju_endpoint = $ENV{JUJU_ENDPOINT};
my $juju = Juju->new(endpoint => $juju_endpoint, password => $juju_pass);
$juju->login;
dies_ok {
$juju->deploy
}
'Dies if no charm or service name';
$juju->deploy(
'mysql', 'mysql', 1, "", {}, "",
sub {
t/04-deploy.t view on Meta::CPAN
my $val = shift;
ok(!defined($val->{Error}), "Deployed precise/wordpress service");
}
);
$juju->add_relation(
'mysql',
'wordpress',
sub {
my $val = shift;
ok(defined($val->{Response}->{Endpoints}->{wordpress}), "Found wordpress endpoint relation");
ok(defined($val->{Response}->{Endpoints}->{mysql}), "Found mysql endpoint relation");
}
);
## CLEANUP
diag("Cleaning up machines");
$juju->destroy_relation('wordpress', 'mysql');
$juju->service_destroy('wordpress');
$juju->service_destroy('mysql');
$juju->destroy_service_units(['wordpress/0', 'mysql/0']);
my $status = $juju->status;