This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1274 lines (975 loc) · 33.6 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<meta name="Description" content="さくらのクラウド上のリソースを簡単にコントロールするためのライブラリです。PHP, Perl, Ruby, Python, C# 等の言語でご利用いただけます。" />
<meta name="robots" content="index, follow" />
<meta name="google-site-verification" content="MXgG1S6jvxjLTKIrZWSbDaNFO6NKYDXLWhcx37UrTqg" />
<meta property="og:title" content="saklient - さくらのクラウド クライアントライブラリ" />
<meta property="og:type" content="article" />
<meta property="og:description" content="さくらのクラウド上のリソースを簡単にコントロールするためのライブラリです。PHP, Perl, Ruby, Python, C# 等の言語でご利用いただけます。" />
<meta property="og:url" content="http://sakura-internet.github.io/saklient.doc/" />
<meta property="og:image" content="http://sakura-internet.github.io/saklient.doc/img/sakura_logo_200x200.png" />
<meta property="og:site_name" content="saklient Sakura Cloud Client Library" />
<meta property="og:email" content="[email protected]" />
<title>saklient - さくらのクラウド クライアントライブラリ</title>
<link rel="stylesheet" href="./res/bootstrap.min.css" />
<link rel="stylesheet" href="./res/github.css" />
<style type="text/css">
.jumbotron {
min-width: 2340px;
padding: 0 0 20px 0;
background-image: url(./img/sakura_logo.svg);
background-repeat: no-repeat;
background-position: left center;
}
.container {
width: auto;
min-width: 2340px;
padding: 0 30px;
}
.jumbotron .container {
padding-left: 205px;
}
.jumbotron .container h1 small {
font-size: 50%;
}
.disable-select {
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
.alert.alert-less-padding {
padding: 6px 10px;
line-height: 1.25;
}
pre {
background-color: #f8f8f8;
}
pre code {
tab-size: 2;
width: 330px;
overflow-x: scroll;
white-space: pre;
}
.code-cs pre code {
width: 380px;
}
#code-wrapper {
/*width: 1520px;*/
/*margin: 0 15px;*/
/*border: solid 1px #ccc;*/
/*border-radius: 4px;*/
}
#code-body {
}
.code-each {
margin-left: 12px;
padding-left: 12px;
border-left: 1px dotted #ccc;
}
.code-each:nth-child(1) {
margin-left: 0;
border-left-color: transparent;
}
</style>
</head>
<body>
<div class="jumbotron">
<div class="container" itemscope itemtype="https://schema.org/Code">
<h1 itemprop="name">saklient <small>さくらのクラウド クライアントライブラリ</small></h1>
<p itemprop="description">
<a href="http://cloud.sakura.ad.jp/" target="_blank"><strong>さくらのクラウド</strong></a>上のリソースを簡単にコントロールするためのライブラリです。PHP, Perl, Ruby, Python, C# 等の言語でご利用いただけます。<br/>
An easy interface to control your resources on <strong>SAKURA Cloud</strong>.
</p>
</div>
</div>
<div class="container">
<div class="row">
<span style="font-size:48px;padding:0 12px;color:white;background-color:red">DEPRECATED</span>
<span style="font-size:24px;color:red">本ライブラリは廃止されました。<a href="https://developer.sakura.ad.jp/">代替ライブラリ</a>をご利用ください。</span>
</div>
<div class="row">
<div class="col-md-10">
<h2>サーバの作成 <small>Create a server</small></h2>
</div>
<div class="col-md-2 alert alert-warning alert-less-padding">
<small>
saklient.node(Node.js版)の実装は実験的なものです。<br/>
Node.jsでは <a href="https://github.com/sakura-internet/node-sacloud/" target="_blank">node-sacloud</a> をご利用いただけます。
</small>
</div>
</div>
<div class="row" id="code-wrapper">
<div id="code-body">
<div class="code-each pull-left code-php"><h4><div class="pull-right"><a href="./files/saklient.php-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/php/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://packagist.org/packages/sakura-internet/saklient" target="_blank" class="btn btn-primary btn-xs">Packagist</a> <a href="https://github.com/sakura-internet/saklient.php" target="_blank" class="btn btn-primary btn-xs">Github</a></div>PHP <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="php"><?php
require_once 'vendor/autoload.php';
use Saklient\Cloud\API;
# settings
$token = $argv[1];
$secret = $argv[2];
$zone = $argv[3];
$name = 'saklient demo';
$description = 'saklient demo';
$tag = 'saklient-test';
$cpu = 1;
$mem = 2;
$hostName = 'saklient-test';
$password = 'C8#mf92mp!*s';
$sshPublicKey = 'ssh-rsa AAAA...';
# authorize
$api = API::authorize
($token,$secret,$zone);
# search archives
echo "searching archives\n";
$archives = $api->archive
->withNameLike('CentOS 6.5 64bit')
->withSizeGib(20)
->withSharedScope()
->limit(1)
->find();
$archive = $archives[0];
# search scripts
echo "searching scripts\n";
$scripts = $api->script
->withNameLike('WordPress')
->withSharedScope()
->limit(1)
->find();
$script = $scripts[0];
# create a disk
echo "creating a disk\n";
$disk = $api->disk->create();
$disk->name = $name;
$disk->description = $description;
$disk->tags = [$tag];
$disk->plan = $api->product->disk->ssd;
$disk->source = $archive;
$disk->save();
# create a server
echo "creating a server\n";
$server = $api->server->create();
$server->name = $name;
$server->description = $description;
$server->tags = [$tag];
$server->plan = $api->product->server
->getBySpec($cpu, $mem);
$server->save();
# connect to shared segment
echo "connecting the server" .
" to shared segment\n";
$iface = $server->addIface();
$iface->connectToSharedSegment();
# wait disk copy
echo "waiting disk copy\n";
if (!$disk->sleepWhileCopying()) {
die('failed');
}
# connect the disk to the server
echo "connecting the disk\n";
$disk->connectTo($server);
# config the disk
$diskconf = $disk->createConfig();
$diskconf->hostName = $hostName;
$diskconf->password = $password;
$diskconf->sshKey = $sshPublicKey;
$diskconf->scripts[] = $script;
$diskconf->write();
# boot
echo "booting the server\n";
$server->boot();
# stop
sleep(3);
echo "stopping the server\n";
$server->stop();
if (!$server->sleepUntilDown()) {
die('failed');
}
# disconnect the disk from the server
echo "disconnecting the disk\n";
$disk->disconnect();
# delete the server
echo "deleting the server\n";
$server->destroy();
# delete the disk
echo "deleting the disk\n";
$disk->destroy();
</code></pre></div><div class="code-each pull-left code-cs"><h4><div class="pull-right"><a href="./files/saklient.cs-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/cs/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://www.nuget.org/packages/Saklient/" target="_blank" class="btn btn-primary btn-xs">NuGet.org</a> <a href="https://github.com/sakura-internet/saklient.cs" target="_blank" class="btn btn-primary btn-xs">Github</a></div>C# <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="cs">using System;
using System.Collections.Generic;
using System.Threading;
using Saklient.Cloud;
using Saklient.Cloud.Resources;
class CreateServerExample {
static void Main(string[] args) {
// settings
string token = args[0];
string secret = args[1];
string zone = args[2];
string name = "saklient demo";
string description = "saklient demo";
string tag = "saklient-test";
int cpu = 1;
int mem = 2;
string hostName = "saklient-test";
string password = "C8#mf92mp!*s";
string sshPublicKey = "ssh-rsa AAAA...";
// authorize
API api = API.Authorize(token,secret,zone);
// search archives
Console.WriteLine("searching archives");
List<Archive> archives = api.Archive
.WithNameLike("CentOS 6.5 64bit")
.WithSizeGib(20)
.WithSharedScope()
.Limit(1)
.Find();
Archive archive = archives[0];
// search scripts
Console.WriteLine("searching scripts");
List<Script> scripts = api.Script
.WithNameLike("WordPress")
.WithSharedScope()
.Limit(1)
.Find();
Script script = scripts[0];
// create a disk
Console.WriteLine("creating a disk");
Disk disk = api.Disk.Create();
disk.Name = name;
disk.Description = description;
disk.Tags = new List<string> {tag};
disk.Plan = api.Product.Disk.Ssd;
disk.Source = archive;
disk.Save();
// create a server
Console.WriteLine("creating a server");
Server server = api.Server.Create();
server.Name = name;
server.Description = description;
server.Tags = new List<string> {tag};
server.Plan = api.Product.Server
.GetBySpec(cpu, mem);
server.Save();
// connect to shared segment
Console.WriteLine("connecting the server"+
" to shared segment");
Iface iface = server.AddIface();
iface.ConnectToSharedSegment();
// wait disk copy
Console.WriteLine("waiting disk copy");
if (!disk.SleepWhileCopying()) {
throw new Exception("failed");
}
// connect the disk to the server
Console.WriteLine("connecting the disk");
disk.ConnectTo(server);
// config the disk
DiskConfig diskconf = disk.CreateConfig();
diskconf.HostName = hostName;
diskconf.Password = password;
diskconf.SshKey = sshPublicKey;
diskconf.Scripts.Add(script);
diskconf.Write();
// boot
Console.WriteLine("booting the server");
server.Boot();
// stop
Thread.Sleep(3);
Console.WriteLine("stopping the server");
server.Stop();
if (!server.SleepUntilDown()) {
throw new Exception("failed");
}
// disconnect the disk from the server
Console.WriteLine("disconnecting the disk");
disk.Disconnect();
// delete the server
Console.WriteLine("deleting the server");
server.Destroy();
// delete the disk
Console.WriteLine("deleting the disk");
disk.Destroy();
}
}
</code></pre></div><div class="code-each pull-left code-python"><h4><div class="pull-right"><a href="./files/saklient.python-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/python/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://pypi.python.org/pypi/saklient" target="_blank" class="btn btn-primary btn-xs">PyPI</a> <a href="https://github.com/sakura-internet/saklient.python" target="_blank" class="btn btn-primary btn-xs">Github</a></div>Python <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="python">#!/usr/local/bin/python3
import sys, time
from saklient.cloud.api import API
# settings
token = sys.argv[1]
secret = sys.argv[2]
zone = sys.argv[3]
name = 'saklient demo'
description = 'saklient demo'
tag = 'saklient-test'
cpu = 1
mem = 2
host_name = 'saklient-test'
password = 'C8#mf92mp!*s'
ssh_public_key = 'ssh-rsa AAAA...'
# authorize
api = API.authorize(token,secret,zone)
# search archives
print('searching archives')
archives = api.archive \
.with_name_like('CentOS 6.5 64bit') \
.with_size_gib(20) \
.with_shared_scope() \
.limit(1) \
.find()
archive = archives[0]
# search scripts
print('searching scripts')
scripts = api.script \
.with_name_like('WordPress') \
.with_shared_scope() \
.limit(1) \
.find()
script = scripts[0]
# create a disk
print('creating a disk')
disk = api.disk.create()
disk.name = name
disk.description = description
disk.tags = [tag]
disk.source = archive
disk.plan = api.product.disk.ssd
disk.save()
# create a server
print('creating a server')
server = api.server.create()
server.name = name
server.description = description
server.tags = [tag]
server.plan = api.product.server \
.get_by_spec(cpu, mem)
server.save()
# connect to shared segment
print('connecting the server' +\
' to shared segment')
iface = server.add_iface()
iface.connect_to_shared_segment()
# wait disk copy
print('waiting disk copy')
if not disk.sleep_while_copying():
raise Exception('failed')
# connect the disk to the server
print('connecting the disk')
disk.connect_to(server)
# config the disk
diskconf = disk.create_config()
diskconf.host_name = host_name
diskconf.password = password
diskconf.ssh_key = ssh_public_key
diskconf.scripts.append(script)
diskconf.write()
# boot
print('booting the server')
server.boot()
# stop
time.sleep(3)
print('stopping the server')
server.stop()
if not server.sleep_until_down():
raise Exception('failed')
# disconnect the disk from the server
print('disconnecting the disk')
disk.disconnect()
# delete the server
print('deleting the server')
server.destroy()
# delete the disk
print('deleting the disk')
disk.destroy()
</code></pre></div><div class="code-each pull-left code-ruby"><h4><div class="pull-right"><a href="./files/saklient.ruby-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/ruby/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://rubygems.org/gems/saklient" target="_blank" class="btn btn-primary btn-xs">RubyGems</a> <a href="https://github.com/sakura-internet/saklient.ruby" target="_blank" class="btn btn-primary btn-xs">Github</a></div>Ruby <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="ruby">#!/usr/bin/ruby
require 'saklient/cloud/api'
# settings
token = $*[0]
secret = $*[1]
zone = $*[2]
name = 'saklient demo'
description = 'saklient demo'
tag = 'saklient-test'
cpu = 1
mem = 2
host_name = 'saklient-test'
password = 'C8#mf92mp!*s'
ssh_public_key = 'ssh-rsa AAAA...'
# authorize
api = Saklient::Cloud::API::
authorize(token, secret, zone)
# search archives
puts 'searching archives'
archives = api.archive.
with_name_like('CentOS 6.5 64bit').
with_size_gib(20).
with_shared_scope.
limit(1).
find
archive = archives[0]
# search scripts
puts 'searching scripts'
scripts = api.script.
with_name_like('WordPress').
with_shared_scope.
limit(1).
find
script = scripts[0]
# create a disk
puts 'creating a disk'
disk = api.disk.create
disk.name = name
disk.description = description
disk.tags = [tag]
disk.plan = api.product.disk.ssd
disk.source = archive
disk.save
# create a server
puts 'creating a server'
server = api.server.create
server.name = name
server.description = description
server.tags = [tag]
server.plan = api.product.server.
get_by_spec(cpu, mem)
server.save
# connect to shared segment
puts 'connecting the server' +
' to shared segment'
iface = server.add_iface
iface.connect_to_shared_segment
# wait disk copy
puts 'waiting disk copy'
disk.sleep_while_copying or
abort 'failed'
# connect the disk to the server
puts 'connecting the disk'
disk.connect_to(server)
# config the disk
diskconf = disk.create_config
diskconf.host_name = host_name
diskconf.password = password
diskconf.ssh_key = ssh_public_key
diskconf.scripts.push(script)
diskconf.write
# boot
puts 'booting the server'
server.boot
# stop
sleep 3
puts 'stopping the server'
server.stop
server.sleep_until_down or
abort 'failed'
# disconnect the disk from the server
puts 'disconnecting the disk'
disk.disconnect
# delete the server
puts 'deleting the server'
server.destroy
# delete the disk
puts 'deleting the disk'
disk.destroy
</code></pre></div><div class="code-each pull-left code-perl"><h4><div class="pull-right"><a href="https://github.com/sakura-internet/saklient.perl" target="_blank" class="btn btn-primary btn-xs">Github</a></div>Perl <small class="text-danger">(Alpha)</small><div class="clearfix" /></h4><pre><code class="perl">#!/usr/bin/perl
use strict;
use warnings;
use Saklient::Cloud::API;
# settings
my $token = $ARGV[0];
my $secret = $ARGV[1];
my $zone = $ARGV[2];
my $name = 'saklient demo';
my $description = 'saklient demo';
my $tag = 'saklient-test';
my $cpu = 1;
my $mem = 2;
my $host_name = 'saklient-test';
my $password = 'C8#mf92mp!*s';
my $ssh_public_key = 'ssh-rsa AAAA...';
# authorize
my $api=Saklient::Cloud::API::authorize
($token, $secret, $zone);
# search archives
print "searching archives\n";
my $archives = $api->archive
->with_name_like('CentOS 6.5 64bit')
->with_size_gib(20)
->with_shared_scope
->limit(1)
->find;
my $archive = $archives->[0];
# search scripts
print "searching scripts\n";
my $scripts = $api->script
->with_name_like('WordPress')
->with_shared_scope
->limit(1)
->find;
my $script = $scripts->[0];
# create a disk
print "creating a disk\n";
my $disk = $api->disk->create
->name($name)
->description($description)
->tags([$tag])
->source($archive)
->plan($api->product->disk->ssd)
->save;
# create a server
print "creating a server\n";
my $server = $api->server->create
->name($name)
->description($description)
->tags([$tag])
->plan($api->product->server
->get_by_spec($cpu, $mem))
->save;
# connect to shared segment
print "connecting the server" .
" to shared segment\n";
my $iface = $server->add_iface;
$iface->connect_to_shared_segment;
# wait disk copy
print "waiting disk copy\n";
$disk->sleep_while_copying
or die 'failed';
# connect the disk to the server
print "connecting the disk\n";
$disk->connect_to($server);
# config the disk
$disk->create_config
->host_name($host_name)
->password($password)
->ssh_key($ssh_public_key)
->add_script($script)
->write;
# boot
print "booting the server\n";
$server->boot;
# stop
sleep 3;
print "stopping the server\n";
$server->stop;
$server->sleep_until_down
or die 'failed';
# disconnect the disk from the server
print "disconnecting the disk\n";
$disk->disconnect;
# delete the server
print "deleting the server\n";
$server->destroy;
# delete the disk
print "deleting the disk\n";
$disk->destroy;
</code></pre></div><div class="code-each pull-left code-javascript"><h4><div class="pull-right"><a href="https://github.com/sakura-internet/saklient.node" target="_blank" class="btn btn-primary btn-xs disabled">Github</a></div>Node.js <small class="text-danger">(Experimental)</small><div class="clearfix" /></h4><pre><code class="javascript">
var saklient = require('saklient');
// settings
var token = process.argv[2];
var secret = process.argv[3];
var zone = process.argv[4];
var name = 'saklient demo';
var description = 'saklient demo';
var tag = 'saklient-test';
var cpu = 1;
var mem = 2;
var hostName = 'saklient-test';
var password = 'C8#mf92mp!*s';
var sshPublicKey = 'ssh-rsa AAAA...';
// authorize
var api = saklient.cloud.API.
authorize(token, secret, zone);
// search archives
console.log('searching archives');
var archives = api.archive.
withNameLike('CentOS 6.5 64bit').
withSizeGib(20).
withSharedScope().
limit(1).
find();
var archive = archives[0];
// search scripts
console.log('searching scripts');
var scripts = api.script.
withNameLike('WordPress').
withSharedScope().
limit(1).
find();
var script = scripts[0];
// create a disk
console.log('creating a disk');
var disk = api.disk.create();
disk.name = name;
disk.description = description;
disk.tags = [tag];
disk.plan = api.product.disk.ssd;
disk.source = archive;
disk.save();
// create a server
console.log('creating a server');
var server = api.server.create();
server.name = name;
server.description = description;
server.tags = [tag];
server.plan = api.product.server.
getBySpec(cpu, mem);
server.save();
// connect to shared segment
console.log('connecting the server' +
' to shared segment');
var iface = server.addIface();
iface.connectToSharedSegment();
// wait disk copy
console.log('waiting disk copy');
if (!disk.sleepWhileCopying()) {
process.exit(1);
}
// connect the disk to the server
console.log('connecting the disk');
disk.connectTo(server);
// config the disk
var diskconf = disk.createConfig();
diskconf.hostName = hostName;
diskconf.password = password;
diskconf.sshKey = sshPublicKey;
diskconf.scripts.push(script);
diskconf.write();
// boot
console.log('booting the server');
server.boot();
// stop the server
api.sleep(3);
console.log('stopping the server');
server.stop();
if (!server.sleepUntilDown()) {
process.exit(1);
}
// disconnect the disk from the server
console.log('disconnecting the disk');
disk.disconnect();
// delete the server
console.log('deleting the server');
server.destroy();
// delete the disk
console.log('deleting the disk');
disk.destroy();
</code></pre></div> <div class="clearfix"></div>
</div>
</div>
<hr>
<div class="row">
<div class="col-md-10">
<h2>ディスクイメージのダウンロード <small>Download a disk image</small></h2>
</div>
<div class="col-md-2 alert alert-warning alert-less-padding">
<small>
saklient.node(Node.js版)の実装は実験的なものです。<br/>
Node.jsでは <a href="https://github.com/sakura-internet/node-sacloud/" target="_blank">node-sacloud</a> をご利用いただけます。
</small>
</div>
</div>
<div class="row" id="code-wrapper">
<div id="code-body">
<div class="code-each pull-left code-php"><h4><div class="pull-right"><a href="./files/saklient.php-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/php/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://packagist.org/packages/sakura-internet/saklient" target="_blank" class="btn btn-primary btn-xs">Packagist</a> <a href="https://github.com/sakura-internet/saklient.php" target="_blank" class="btn btn-primary btn-xs">Github</a></div>PHP <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="php"><?php
require_once 'vendor/autoload.php';
use Saklient\Cloud\API;
# settings
$token = $argv[1];
$secret = $argv[2];
$zone = $argv[3];
$srcName = 'GitLab';
# authorize
$api = API::authorize
($token,$secret,$zone);
# search the source disk
$disks = $api->disk
->withNameLike($srcName)
->limit(1)
->find();
$disk = $disks[0];
# copy the disk to a new archive
echo "copying the disk ".
"to a new archive\n";
$archive = $api->archive->create();
$archive->name = 'Copy:'.$disk->name;
$archive->source = $disk;
$archive->save();
if (!$archive->sleepWhileCopying()) {
die('failed');
}
# get FTP information
$ftp = $archive->openFtp()->ftpInfo;
echo "FTP information:\n";
echo " user: ", $ftp->user, "\n";
echo " pass: ", $ftp->password, "\n";
echo " host: ", $ftp->hostName, "\n";
# download the archive via FTPS
echo "downloading the archive\n";
$url = 'ftps://' .
rawurlencode($ftp->user) .':'.
rawurlencode($ftp->password) .'@'.
$ftp->hostName . '/archive.img';
$src = fopen($url, 'r');
$dst = fopen('./archive.img', 'w');
stream_copy_to_stream($src, $dst);
fclose($dst);
fclose($src);
# delete the archive after download
echo "deleting the archive\n";
$archive->closeFtp();
$archive->destroy();
</code></pre></div><div class="code-each pull-left code-cs"><h4><div class="pull-right"><a href="./files/saklient.cs-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/cs/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://www.nuget.org/packages/Saklient/" target="_blank" class="btn btn-primary btn-xs">NuGet.org</a> <a href="https://github.com/sakura-internet/saklient.cs" target="_blank" class="btn btn-primary btn-xs">Github</a></div>C# <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="cs">using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Saklient.Cloud;
using Saklient.Cloud.Resources;
class DownloadArchiveExample {
static void Main(string[] args) {
// settings
string token = args[0];
string secret = args[1];
string zone = args[2];
string srcName = "GitLab";
// authorize
API api = API.Authorize(token,secret,zone);
// search the source disk
List<Disk> disks = api.Disk
.WithNameLike(srcName)
.Limit(1)
.Find();
Disk disk = disks[0];
// copy the disk to a new archive
Console.WriteLine("copying the disk "+
"to a new archive");
Archive archive = api.Archive.Create();
archive.Name = "Copy:" + disk.Name;
archive.Source = disk;
archive.Save();
if (!archive.SleepWhileCopying()) {
throw new Exception("failed");
}
// get FTP information
FtpInfo ftp = archive.OpenFtp().FtpInfo;
Console.WriteLine("FTP information:");
Console.WriteLine(" user: "+ftp.User);
Console.WriteLine(" pass: "+ftp.Password);
Console.WriteLine(" host: "+ftp.HostName);
// download the archive via FTPS
Uri uri = new Uri("ftp://"+ftp.HostName+
"/archive.img");
var req = (FtpWebRequest)FtpWebRequest.
Create(uri);
req.EnableSsl = true;
req.Credentials = new NetworkCredential
(ftp.User, ftp.Password);
req.Method =
WebRequestMethods.Ftp.DownloadFile;
var res =(FtpWebResponse)req.GetResponse();
var src = res.GetResponseStream();
var dst = new FileStream("archive.img",
FileMode.Create, FileAccess.Write);
src.CopyTo(dst);
dst.Close();
src.Close();
// delete the archive after download
Console.WriteLine("deleting the archive");
archive.CloseFtp();
archive.Destroy();
}
}
</code></pre></div><div class="code-each pull-left code-python"><h4><div class="pull-right"><a href="./files/saklient.python-examples.zip" class="btn btn-primary btn-xs">ZIP</a> <a href="./api/python/" target="_blank" class="btn btn-primary btn-xs">API</a> <a href="https://pypi.python.org/pypi/saklient" target="_blank" class="btn btn-primary btn-xs">PyPI</a> <a href="https://github.com/sakura-internet/saklient.python" target="_blank" class="btn btn-primary btn-xs">Github</a></div>Python <small class="text-danger">(Beta)</small><div class="clearfix" /></h4><pre><code class="python">#!/usr/local/bin/python3
import sys, time
from ftplib import FTP_TLS
from saklient.cloud.api import API
# settings
token = sys.argv[1]
secret = sys.argv[2]
zone = sys.argv[3]
src_name = 'GitLab'
# authorize
api = API.authorize(token,secret,zone)
# search the source disk
disks = api.disk \
.with_name_like(src_name) \
.limit(1) \
.find()
disk = disks[0]
# copy the disk to a new archive
print('copying the disk ' +\
'to a new archive')
archive = api.archive.create()
archive.name = 'Copy:' + disk.name
archive.source = disk
archive.save()
if not archive.sleep_while_copying():