]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl | |
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | use WebService::Scaleway; | |
6 | ||
7 | use Test::More; | |
8 | ||
9 | BEGIN { | |
10 | plan skip_all => 't/api_key file missing' unless -f 't/api_key'; | |
11 | plan tests => 7; | |
12 | } | |
13 | ||
14 | open my $akf, '<', 't/api_key'; | |
15 | my $token = <$akf>; | |
16 | chomp $token; | |
17 | close $akf; | |
18 | my $sw = WebService::Scaleway->new($token); | |
19 | ||
20 | my $org = $sw->organizations; | |
21 | my $user = $sw->user($org->users->[0]->{id}); | |
22 | note 'This token belongs to ', $user->fullname, ' <', $user->email, '>'; | |
23 | ||
24 | my $ip = $sw->create_ip($org); | |
25 | note "Created new ip $ip with address ", $ip->address; | |
26 | is $sw->ip($ip)->address, $ip->address, 'get_ip'; | |
27 | my @ips = $sw->ips; | |
28 | ok grep ({$_->address eq $ip->address} @ips), 'list_ips'; | |
29 | ||
30 | my $vol = $sw->create_volume('testvol', $org, 'l_ssd', 50_000_000_000); | |
31 | note "Created new volume $vol with name ", $vol->name; | |
32 | is $sw->volume($vol)->name, $vol->name, 'get_volume'; | |
33 | my @vols = $sw->volumes; | |
34 | ok grep ({$_->name eq $vol->name} @vols), 'list_volumes'; | |
35 | ||
36 | my ($debian) = grep { $_->name =~ /debian jessie/i } $sw->images; | |
37 | my $srv = $sw->create_server('mysrv', $org, $debian, {1 => $vol->id}); | |
38 | note "Created new server $srv with name ", $srv->name; | |
39 | is $sw->server($srv)->name, $srv->name, 'get_server'; | |
40 | $srv->{name} = 'testsrv'; | |
41 | $sw->update_server($srv); | |
42 | is $sw->server($srv)->name, $srv->name, 'update_server'; | |
43 | my @srvs = $sw->servers; | |
44 | ok grep ({$_->name eq $srv->name} @srvs), 'list_servers'; | |
45 | note "This server can: ", join ' ', $sw->server_actions($srv); | |
46 | ||
47 | ## Snapshots are quite expensive | |
48 | #my $snp = $sw->create_snapshot('mysnap', $org, $vol); | |
49 | #note "Created new snapshot $snp with name ", $snp->name; | |
50 | #is $sw->snapshot($snp)->name, $snp->name, 'get_snapshot'; | |
51 | #$snp->{name} = 'testsnap'; | |
52 | #$sw->update_snapshot($snp); | |
53 | #is $sw->snapshot($snp)->name, $snp->name, 'update_snapshot'; | |
54 | ||
55 | @vols = map { $_->{id} } values %{$srv->volumes}; | |
56 | $sw->delete_server($srv); | |
57 | $sw->delete_ip($ip); | |
58 | $sw->delete_volume($_) for @vols; |