-
Notifications
You must be signed in to change notification settings - Fork 0
/
_rancher
1297 lines (1175 loc) · 53.9 KB
/
_rancher
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
#compdef rancher
#
# zsh completion for rancher-cli (https://github.com/rancher/cli)
#
# version: 0.0.1
# github: https://github.com/go/rancher-zsh-completion
#
# contributors:
# - Go Chiba
#
# license:
#
# Copyright (c) 2016, Go Chiba
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Short-option stacking can be enabled with:
# zstyle ':completion:*:*:rancher:*' option-stacking yes
# zstyle ':completion:*:*:rancher-*:*' option-stacking yes
__rancher_arguments() {
if zstyle -t ":completion:${curcontext}:" option-stacking; then
print -- -s
fi
}
# BO catalog
__rancher_catalog_commands() {
local -a _rancher_catalog_subcommands
_rancher_catalog_subcommands=(
"ls:List catalog templates"
"install:Install catalog template"
"help:Shows a list of commands or help for one command"
)
_describe -t rancher-catalog-commands "rancher catalog command" _rancher_catalog_subcommands
}
__rancher_catalog_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --quiet,-q)"{--quiet,-q}"[Only display IDs]" \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help --system,-s)"{--system,-s}"[Show system templates, not user]" \
"($help):command: _command_names -e" && ret=0
;;
(install)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --answers,-a)"{--answers,-a}"[Answer file]" \
"($help --name)"--name"[Name of stack to create]" \
"($help --system,-s)"{--system,-s}"[Install a system template]" \
"($help):command: _command_names -e" && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_catalog_commands" && ret=0
;;
esac
return ret
}
# EO catalog
# BO environment
__rancher_environments() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines environments args
type=$1; shift
filter=$1; shift
[[ $filter != "none" ]] && args=("-f $filter")
### TODO: Currently not supported Account base API
### Enabled environment completion as experimental
#if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
# return 0
#else
# lines=(${(f)"$(_call_program commands rancher environment ls)"})
#fi
lines=(${(f)"$(_call_program commands rancher environment ls)"})
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Env ID and Name
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:10:: :::)${${line[${begin[NAME]},${end[NAME]}]}%% ##}}"
environments=($environments $s)
done
_describe -t environments-list "environments" environments "$@" && ret=0
return ret
}
__rancher_environment_commands() {
local -a _rancher_environment_subcommands
_rancher_environment_subcommands=(
"ls:List environments"
"create:Create an environment"
"templates:Interact with environment templates"
"template:Interact with environment templates"
"rm:Remove environment(s)"
"deactivate:Deactivate environment(s)"
"activate:Activate environment(s)"
)
_describe -t rancher-environment-commands "rancher environment command" _rancher_environment_subcommands
}
__rancher_environment_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"{--all,-a}"[Show stop/inactive and recently removed resources]" \
"($help)"{--quiet,-q}"[Only display IDs]" \
"($help)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(create)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"{--all,-a}"[Show stop/inactive and recently removed resources]" \
"($help)"{--quiet,-q}"[Only display IDs]" \
"($help)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(templates|template)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"{--all,-a}"[Show stop/inactive and recently removed resources]" \
"($help)"{--quiet,-q}"[Only display IDs]" \
"($help)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0
case $state in
(command)
__rancher_environment_subsubcommands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:rancher-${words[-1]}:
__rancher_environment_subsubcommand && ret=0
;;
esac
;;
(rm)
_arguments $(__rancher_arguments) \
$opts_help && ret=0
;;
(deactivate)
_arguments $(__rancher_arguments) \
$opts_help \
"($help -)*:environment:__rancher_environments" && ret=0
;;
(activate)
_arguments $(__rancher_arguments) \
$opts_help \
"($help -)*:environment:__rancher_environments" && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_environment_commands" && ret=0
;;
esac
return ret
}
__rancher_environment_subsubcommands() {
local -a _rancher_environment_subsubcommands
_rancher_environment_subsubcommands=(
"export:Export an environment template to STDOUT"
"import:Import an environment template to from file"
)
_describe -t rancher-environment-subsubcommands "rancher environment subcommand" _rancher_environment_subsubcommands
}
__rancher_environment_subsubcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(export)
_arguments $(__rancher_arguments) \
$opts_help \
"($help -)*:environment:__rancher_environments" && ret=0
;;
(import)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"--public"[Make template public]" \
"($help):command: _command_names -e" && ret=0
;;
esac
return ret
}
# EO environment
# BO host
__rancher_hosts() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines hosts args
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher host ls -a)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Host ID and Hostname
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:20:: :::)${${line[${begin[HOSTNAME]},${end[HOSTNAME]}]}%% ##}}"
hosts=($hosts $s)
done
_describe -t hosts-list "hosts" hosts "$@" && ret=0
return ret
}
__rancher_host_commands() {
local -a _rancher_host_subcommands
_rancher_host_subcommands=(
"ls:List hosts"
"create:Create a host"
"help:Shows a list of commands or help for one command"
)
_describe -t rancher-host-commands "rancher host command" _rancher_host_subcommands
}
__rancher_host_subcommand() {
local -a _command_args opts_help opts_create_host
local expl help="--help"
integer ret=1
opts_create_host=(
"($help --driver,-d)"{--driver,-d}"[Driver to use: amazonec2, azure, packet, digitalocean]"
"($help)"--description"[\[\$DESCRIPTION\]]"
"($help)"--labels"[\[\$LABELS\]]"
"($help)"--docker-version"[\[\$DOCKER_VERSION\]]"
"($help)"--auth-key"[\[\$AUTH_KEY\]]"
"($help)"--auth-certificate-authority"[\[\$AUTH_CERTIFICATE_AUTHORITY\]]"
"($help)"--engine-install-url"[\[\$ENGINE_INSTALL_URL\]]:url:(http\:// https\://)"
"($help)"--engine-registry-mirror"[\[\$ENGINE_REGISTRY_MIRROR\]]"
"($help)"--engine-insecure-registry"[\[\$ENGINE_INSECURE_REGISTRY\]]"
"($help)"--engine-storage-driver"[\[\$ENGINE_STORAGE_DRIVER\]]"
"($help)"--engine-opt"[\[\$ENGINE_OPT\]]"
"($help)"--engine-label"[\[\$ENGINE_LABEL\]]"
"($help)"--engine-env"[\[\$ENGINE_ENV\]]"
"($help)"--packet-os"[Pakcet OS, possible values are: ubuntu_14_04 \[\$PACKET_OS\]]"
"($help)"--packet-plan"[Pakcet Server Plan \[\$PACKET_PLAN\]]"
"($help)"--packet-project-id"[Pakcet Project Id \[\$PACKET_PROJECT_ID\]]"
"($help)"--packet-api-key"[Pakcet api key \[\$PACKET_API_KEY\]]"
"($help)"--packet-billing-cycle"[Packet billing cycle, hourly or monthly \[\$PACKET_BILLING_CYCLE\]]"
"($help)"--packet-facility-code"[Packet facility code \[\$PACKET_FACILITY_CODE\]]"
"($help)"--digitalocean-ipv6"[enable ipv6 for droplet \[\$DIGITALOCEAN_IPV6\]]"
"($help)"--digitalocean-access-token"[Digital Ocean access token \[\$DIGITALOCEAN_ACCESS_TOKEN\]]"
"($help)"--digitalocean-ssh-key-fingerprint"[SSH key fingerprint \[\$DIGITALOCEAN_SSH_KEY_FINGERPRINT\]]"
"($help)"--digitalocean-ssh-user"[SSH username \[\$DIGITALOCEAN_SSH_USER\]]"
"($help)"--digitalocean-userdata"[path to file with cloud-init user-data \[\$DIGITALOCEAN_USERDATA\]]"
"($help)"--digitalocean-region"[Digital Ocean region \[\$DIGITALOCEAN_REGION\]]"
"($help)"--digitalocean-size"[Digital Ocean size \[\$DIGITALOCEAN_SIZE\]]"
"($help)"--digitalocean-ssh-port"[SSH port \[\$DIGITALOCEAN_SSH_PORT\]]"
"($help)"--digitalocean-backups"[enable backups for droplet \[\$DIGITALOCEAN_BACKUPS\]]"
"($help)"--digitalocean-image"[Digital Ocean Image \[\$DIGITALOCEAN_IMAGE\]]"
"($help)"--digitalocean-private-networking"[enable private networking for droplet \[\$DIGITALOCEAN_PRIVATE_NETWORKING\]]"
"($help)"*--amazonec2-insecure-transport"[Disable SSL when sending requests \[\$AMAZONEC2_INSECURE_TRANSPORT\]]"
"($help)"*--amazonec2-root-size"[AWS root disk size (in GB) \[\$AMAZONEC2_ROOT_SIZE\]]"
"($help)"*--amazonec2-secret-key"[AWS Secret Key \[\$AMAZONEC2_SECRET_KEY\]]"
"($help)"*--amazonec2-session-token"[AWS Session Token \[\$AMAZONEC2_SESSION_TOKEN\]]"
"($help)"--amazonec2-ssh-keypath"[SSH Key for Instance \[\$AMAZONEC2_SSH_KEYPATH\]]"
"($help)"--amazonec2-tags"[AWS Tags (e.g. key1,value1,key2,value2) \[\$AMAZONEC2_TAGS\]]"
"($help)"--amazonec2-iam-instance-profile"[AWS IAM Instance Profile \[\$AMAZONEC2_IAM_INSTANCE_PROFILE\]]"
"($help)"--amazonec2-access-key"[AWS Access Key \[\$AMAZONEC2_ACCESS_KEY\]]"
"($help)"--amazonec2-keypair-name"[AWS keypair to use; requires --amazonec2-ssh-keypath \[\$AMAZONEC2_KEYPAIR_NAME\]]"
"($help)"--amazonec2-private-address-only"[Only use a private IP address \[\$AMAZONEC2_PRIVATE_ADDRESS_ONLY\]]"
"($help)"--amazonec2-request-spot-instance"[Set this flag to request spot instance \[\$AMAZONEC2_REQUEST_SPOT_INSTANCE\]]"
"($help)"--amazonec2-vpc-id"[AWS VPC id \[\$AMAZONEC2_VPC_ID\]]"
"($help)"--amazonec2-endpoint"[Optional endpoint URL (hostname only or fully qualified URI) \[\$AMAZONEC2_ENDPOINT\]]:url:(http\:// https\://"
"($help)"--amazonec2-region"[AWS region \[\$AMAZONEC2_REGION\]]"
"($help)"--amazonec2-spot-price"[AWS spot instance bid price (in dollar) \[\$AMAZONEC2_SPOT_PRICE\]]"
"($help)"--amazonec2-ami"[AWS machine image \[\$AMAZONEC2_AMI\]]"
"($help)"--amazonec2-open-port"[Make the specified port number accessible from the Internet \[\$AMAZONEC2_OPEN_PORT\]]"
"($help)"--amazonec2-ssh-user"[Set the name of the ssh user \[\$AMAZONEC2_SSH_USER\]]"
"($help)"--amazonec2-use-ebs-optimized-instance"[Create an EBS optimized instance \[\$AMAZONEC2_USE_EBS_OPTIMIZED_INSTANCE\]]"
"($help)"--amazonec2-use-private-address"[Force the usage of private IP address \[\$AMAZONEC2_USE_PRIVATE_ADDRESS\]]"
"($help)"--amazonec2-zone"[AWS zone for instance (i.e. a,b,c,d,e) \[\$AMAZONEC2_ZONE\]]"
"($help)"--amazonec2-instance-type"[AWS instance type \[\$AMAZONEC2_INSTANCE_TYPE\]]"
"($help)"--amazonec2-security-group"[AWS VPC security group \[\$AMAZONEC2_SECURITY_GROUP\]]"
"($help)"--amazonec2-retries"[Set retry count for recoverable failures (use -1 to disable) \[\$AMAZONEC2_RETRIES\]]"
"($help)"--amazonec2-monitoring"[Set this flag to enable CloudWatch monitoring \[\$AMAZONEC2_MONITORING\]]"
"($help)"--amazonec2-subnet-id"[AWS VPC subnet id \[\$AMAZONEC2_SUBNET_ID\]]"
"($help)"--amazonec2-volume-type"[Amazon EBS volume type \[\$AMAZONEC2_VOLUME_TYPE\]]"
"($help)"--amazonec2-device-name"[AWS root device name \[\$AMAZONEC2_DEVICE_NAME\]]"
"($help)"--azure-image"[Azure virtual machine OS image \[\$AZURE_IMAGE\]]"
"($help)"--azure-location"[Azure region to create the virtual machine \[\$AZURE_LOCATION\]]"
"($help)"--azure-private-ip-address"[Specify a static private IP address for the machine \[\$AZURE_PRIVATE_IP_ADDRESS\]]"
"($help)"--azure-resource-group"[Azure Resource Group name (will be created if missing) \[\$AZURE_RESOURCE_GROUP\]]"
"($help)"--azure-vnet"[Azure Virtual Network name to connect the virtual machine (in \[resourcegroup:\]name format) \[\$AZURE_VNET\]]"
"($help)"--azure-availability-set"[Azure Availability Set to place the virtual machine into \[\$AZURE_AVAILABILITY_SET\]]"
"($help)"--azure-client-secret"[Azure Service Principal Account password (optional, browser auth is used if not specified) \[\$AZURE_CLIENT_SECRET\]]"
"($help)"--azure-environment"[Azure environment (e.g. AzurePublicCloud, AzureChinaCloud) \[\$AZURE_ENVIRONMENT\]]"
"($help)"--azure-no-public-ip"[Do not create a public IP address for the machine \[\$AZURE_NO_PUBLIC_IP\]]"
"($help)"--azure-ssh-user"[Username for SSH login \[\$AZURE_SSH_USER\]]"
"($help)"--azure-subnet"[Azure Subnet Name to be used within the Virtual Network \[\$AZURE_SUBNET\]]"
"($help)"--azure-open-port"[Make the specified port number accessible from the Internet \[\$AZURE_OPEN_PORT\]]"
"($help)"--azure-size"[Size for Azure Virtual Machine \[\$AZURE_SIZE\]]"
"($help)"--azure-static-public-ip"[Assign a static public IP address to the machine \[\$AZURE_STATIC_PUBLIC_IP\]]"
"($help)"--azure-storage-type"[Type of Storage Account to host the OS Disk for the machine \[\$AZURE_STORAGE_TYPE\]]"
"($help)"--azure-subscription-id"[Azure Subscription ID \[\$AZURE_SUBSCRIPTION_ID\]]"
"($help)"--azure-client-id"[Azure Service Principal Account ID (optional, browser auth is used if not specified) \[\$AZURE_CLIENT_ID\]]"
"($help)"--azure-custom-data"[Path to file with custom-data \[\$AZURE_CUSTOM_DATA\]]"
"($help)"--azure-docker-port"[Port number for Docker engine \[\$AZURE_DOCKER_PORT\]]"
"($help)"--azure-subnet-prefix"[Private CIDR block to be used for the new subnet, should comply RFC 1918 \[\$AZURE_SUBNET_PREFIX\]]"
"($help)"--azure-use-private-ip"[Use private IP address of the machine to connect \[\$AZURE_USE_PRIVATE_IP\]]"
)
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"{--quiet,-q}"[Only display IDs]" \
"($help)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(create)
local state
_arguments $(__rancher_arguments) \
$opts_help \
$opts_create_host \
"($help):command: _command_names -e" && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_host_commands" && ret=0
;;
esac
return ret
}
# EO host
# BO secret
__rancher_secrets() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines volumes
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher $rancher_options volumes ls -a)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Volume ID, and STATE
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:70:: :::)${${line[${begin[NAME]},${end[NAME]}]}}%% ##}"
s="$s, ${(l:10:: :::)${${line[${begin[STATE]},${end[STATE]}]}}%% ##}"
s="$s, ${(l:8:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}}%% ##}"
s="$s, ${(r:60:: :::)${${line[${begin[DETAIL]},${end[DETAIL]}]}}%% ##}"
volumes=($volumes $s)
done
_describe -t volumes-list "volumes" volumes && ret=0
return ret
}
__rancher_secret_commands() {
local -a _rancher_secret_subcommands
_rancher_secret_subcommands=(
"ls:List secrets"
"create:Create a secret"
)
_describe -t rancher-secret-commands "rancher secret command" _rancher_secret_subcommands
}
__rancher_secret_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --quiet, -q)"{--quiet,-q}"[Only display IDs]" \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(create)
_arguments $(__rancher_arguments) \
$opts_help && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_secret_commands" && ret=0
;;
esac
return ret
}
# EO secret
# BO stack
__rancher_stacks() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines stacks args
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher stack ls)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Host ID and Name
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:20:: :::)${${line[${begin[NAME]},${end[NAME]}]}%% ##}}"
s="$s , ${(r:20:: :::)${${line[${begin[STATE]},${end[STATE]}]}%% ##}}"
stacks=($stacks $s)
done
_describe -t stacks-list "stacks" stacks "$@" && ret=0
return ret
}
__rancher_stack_commands() {
local -a _rancher_stack_subcommands
_rancher_stack_subcommands=(
"ls:List stacks"
"create:Create a stacks"
"help:Shows a list of commands or help for one command"
)
_describe -t rancher-stack-commands "rancher stack command" _rancher_stack_subcommands
}
__rancher_stack_subcommand() {
local -a _command_args opts_help opts_create_update
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
opts_create_update=(
"($help)*--constraint=[Placement constraints]:constraint: "
"($help)--endpoint-mode=[Placement constraints]:mode:(dnsrr vip)"
"($help)*"{-e=,--env=}"[Set environment variables]:env: "
"($help)*--group-add=[Add additional user groups to the container]:group:_groups"
"($help)*--label=[Service labels]:label: "
"($help)--limit-cpu=[Limit CPUs]:value: "
"($help)--limit-memory=[Limit Memory]:value: "
"($help)--log-driver=[Logging driver for service]:logging driver:__rancher_log_drivers"
"($help)*--log-opt=[Logging driver options]:log driver options:__rancher_log_options"
"($help)*--mount=[Attach a mount to the service]:mount: "
"($help)--name=[Service name]:name: "
"($help)*--network=[Network attachments]:network: "
"($help)*"{-p=,--publish=}"[Publish a port as a node port]:port: "
"($help)--replicas=[Number of tasks]:replicas: "
"($help)--reserve-cpu=[Reserve CPUs]:value: "
"($help)--reserve-memory=[Reserve Memory]:value: "
"($help)--restart-condition=[Restart when condition is met]:mode:(any none on-failure)"
"($help)--restart-delay=[Delay between restart attempts]:delay: "
"($help)--restart-max-attempts=[Maximum number of restarts before giving up]:max-attempts: "
"($help)--restart-window=[Window used to evaluate the restart policy]:window: "
"($help)--stop-grace-period=[Time to wait before force killing a container]:grace period: "
"($help)--update-delay=[Delay between updates]:delay: "
"($help)--update-failure-action=[Action on update failure]:mode:(pause continue)"
"($help)--update-parallelism=[Maximum number of tasks updated simultaneously]:number: "
"($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users"
"($help)--with-registry-auth[Send registry authentication details to swarm agents]"
"($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
)
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --system, -s)"{--system,-s}"[Show system resources]" \
"($help --quiet, -q)"{--quiet,-q}"[Only display IDs]" \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(create)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --start)"--start"[Start stack on create]" \
"($help --system, -s)"{--system,-s}"[Create a system stack]" \
"($help --empty, -e)"{--empty,-e}"[Create an empty stack]" \
"($help --quiet, -q)"{--quiet,-q}"[Only display IDs]" \
"($help --docker-compose, -f)"{--docker-compose,-f}"[Docker Compose file (default: \"docker-compose.yml\")]" \
"($help --rancher-compose, -r)"{--rancher-compose,-r}"[Rancher Compose file (default: \"rancher-compose.yml\")]" && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_stack_commands" && ret=0
;;
esac
return ret
}
# EO stack
# BO volume
__rancher_volumes() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines volumes
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher $rancher_options volumes ls -a)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Volume ID, and STATE
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:70:: :::)${${line[${begin[NAME]},${end[NAME]}]}}%% ##}"
s="$s, ${(l:10:: :::)${${line[${begin[STATE]},${end[STATE]}]}}%% ##}"
s="$s, ${(l:8:: :::)${${line[${begin[DRIVER]},${end[DRIVER]}]}}%% ##}"
s="$s, ${(r:60:: :::)${${line[${begin[DETAIL]},${end[DETAIL]}]}}%% ##}"
volumes=($volumes $s)
done
_describe -t volumes-list "volumes" volumes && ret=0
return ret
}
__rancher_volume_commands() {
local -a _rancher_volume_subcommands
_rancher_volume_subcommands=(
"ls:List volumes"
"rm:Delete volume"
"create:Create volume"
"help:Shows a list of commands or help for one command"
)
_describe -t rancher-volume-commands "rancher volume command" _rancher_volume_subcommands
}
__rancher_volume_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(ls)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --all, -a)"{--all,-a}"[Show stop/inactive and recently removed resources]" \
"($help --quiet, -q)"{--quiet,-q}"[Only display IDs]" \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(rm)
_arguments $(__rancher_arguments) \
$opts_help \
"($help -)*:volumes:__rancher_volumes" && ret=0
;;
(create)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --driver)"--driver"[Specify volume driver name]" \
"($help --opt)"--opt"[Set driver specific key/value options]" \
"($help):command: _command_names -e" && ret=0
;;
(help)
_arguments $(__rancher_arguments) ":subcommand:__rancher_volume_commands" && ret=0
;;
esac
return ret
}
# EO volume
# BO service
__rancher_services() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines services args
### TODO: Design to filtering service type lines
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher ps -a)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Host ID and Name
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:30:: :::)${${line[${begin[NAME]},${end[NAME]}]}%% ##}}"
s="$s, ${(r:30:: :::)${${line[${begin[STATE]},${end[STATE]}]}%% ##}}"
services=($services $s)
done
_describe -t services-list "services" services "$@" && ret=0
return ret
}
# EO service
# BO container
__rancher_containers() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines containers args
### TODO: Currently not supported Account base API
if [[ -z "${(M)RANCHER_URL:#*project*}" ]] then
return 0
else
lines=(${(f)"$(_call_program commands rancher ps -c -a -s)"})
fi
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Host ID and Name
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:30:: :::)${${line[${begin[NAME]},${end[NAME]}]}%% ##}}"
s="$s, ${${${line[${begin[STATE]},${end[STATE]}]}/:/\\:}%% ##}"
s="$s , ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}"
containers=($containers $s)
done
_describe -t containers-list "containers" containers "$@" && ret=0
return ret
}
# EO container
# BO machine
__rancher_machines() {
[[ $PREFIX = -* ]] && return 1
integer ret=1
local line s
declare -a lines machines args
### TODO: Design to filtering machine type lines
lines=(${(f)"$(_call_program commands rancher ps -c)"})
# Parse header line to find columns
local i=1 j=1 k header=${lines[1]}
declare -A begin end
while (( j < ${#header} - 1 )); do
i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 ))
j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 ))
k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 ))
begin[${header[$i,$((j-1))]}]=$i
end[${header[$i,$((j-1))]}]=$k
done
end[${header[$i,$((j-1))]}]=-1
lines=(${lines[2,-1]})
# Host ID and Name
for line in $lines; do
s="${line[${begin[ID]},${end[ID]}]%% ##}"
s="$s:${(r:10:: :::)${${line[${begin[NAME]},${end[NAME]}]}%% ##}}"
machines=($machines $s)
done
_describe -t machines-list "machines" machines "$@" && ret=0
return ret
}
# EO machine
__rancher_caching_policy() {
oldp=( "$1"(Nmh+1) ) # 1 hour
(( $#oldp ))
}
__rancher_commands() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
if [[ -z "$cache_policy" ]]; then
zstyle ":completion:${curcontext}:" cache-policy __rancher_caching_policy
fi
# if ( [[ ${+_rancher_subcommands} -eq 0 ]] || _cache_invalid rancher_subcommands) \
# && ! _retrieve_cache rancher_subcommands;
# then
# local -a lines
# lines=(${(f)"$(_call_program commands rancher 2>&1)"})
# _rancher_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:})
## _rancher_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:})
# _rancher_subcommands=($_rancher_subcommands)
# (( $#_rancher_subcommands > 2 )) && _store_cache rancher_subcommands _rancher_subcommands
# fi
### TODO: should be dynamically get commands as above
if ( [[ ${+_rancher_subcommands} -eq 0 ]] || _cache_invalid rancher_subcommands) \
&& ! _retrieve_cache rancher_subcommands;
then
_rancher_subcommands=(
"catalog:Operation with catalogs"
"config:Setup client configuration"
"docker:Run docker CLI on a host"
"environment:Interact with environments"
"env:Interact with environments"
"events:Displays resource change events"
"event:Displays resource change events"
"exec:Run a command on a container"
"export:Export configuration yml for a stack as a tar archive"
"hosts:Operations on hosts"
"host:Operations on hosts"
"logs:Fetch the logs of a container"
"ps:Show services/containers"
"restart:Restart service, container"
"rm:Delete service, container, stack, host, machine"
"run:Run services"
"scale:Set number of containers to run for a service"
"secrets:Operation on secrets"
"secret:Operation on secrets"
"ssh:SSH into host"
"stacks:Operations on stacks"
"stack:Operations on stacks"
"start:Start or activate service, container, host"
"activate:Start or activate service, container, host"
"stop:Stop or deactivate service, container, host"
"deactivate:Stop or deactivate service, container, host"
"up:Bring all services up"
"volumes:Operations on volumes"
"volume:Operations on volumes"
"inspect:View details for service, container, host, stack, machine"
"wait:Wait for resources service, container, host, stack, machine"
)
_store_cache rancher_subcommands _rancher_subcommands
fi
_describe -t rancher-commands "rancher command" _rancher_subcommands
}
__rancher_subcommand() {
local -a _command_args opts_help
local expl help="--help"
integer ret=1
opts_help=("(: -)--help[Print usage]")
case "$words[1]" in
(catalog)
local curcontext="$curcontext" state
_arguments $(__rancher_arguments) \
$opts_help \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0
case $state in
(command)
__rancher_catalog_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:rancher-${words[-1]}:
__rancher_catalog_subcommand && ret=0
;;
esac
;;
(config)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --print,-p)"{--print,-p}"[Print the current configuration]" && ret=0
;;
(docker)
_arguments $(__rancher_arguments) \
$opts_help \
"($help -): :__docker_commands" \
"($help):command: _command_names -e" && ret=0
;;
(environment|env)
local curcontext="$curcontext" state
_arguments $(__rancher_arguments) \
$opts_help \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0
case $state in
(command)
__rancher_environment_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:rancher-${words[-1]}:
__rancher_environment_subcommand && ret=0
;;
esac
;;
(events|event)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help --reconnect -r)"{--reconnect,-r}"[Reconnect on error]" \
"($help):command: _command_names -e" && ret=0
;;
(exec)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --help-docker)"--help-docker"[Display the 'docker exec --help']" && ret=0
;;
(export)
_arguments $(__rancher_arguments) \
$opts_help \
"($help)"{--file,-f}"[Write to a file, instead of STDOUT]" \
"($help)"{--system,-s}"[If exporting the entire environment, include system]" && ret=0
;;
(hosts|host)
local curcontext="$curcontext" state
_arguments $(__rancher_arguments) \
$opts_help \
"($help -): :->command" \
"($help -)*:: :->option-or-argument" && ret=0
case $state in
(command)
__rancher_host_commands && ret=0
;;
(option-or-argument)
curcontext=${curcontext%:*:*}:rancher-${words[-1]}:
__rancher_host_subcommand && ret=0
;;
esac
;;
(logs)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --service -s)"{--service,-s}"[Show service logs]" \
"($help --sub-log)"--sub-log"[Show service sub logs]" \
"($help --follow -f)"{--follow,-f}"[Follow log output]" \
"($help --tail)"--tail"[Number of lines to show from the end of the logs (default: 100)]" \
"($help --since)"--since"[Show logs since timestamp]" \
"($help --timestamps -t)"{--timestamps,-t}"[Show timestamps]" \
"($help -)*:services:__rancher_services" && ret=0
;;
(ps)
_arguments $(__rancher_arguments) \
$opts_help \
"($help --all -a)"{--all,-a}"[Show stop/inactive and recently removed resources]" \
"($help --system -s)"{--system,-s}"[Show system resources]" \
"($help --containers -c)"{--containers,-c}"[Display containers]" \
"($help --quiet -q)"{--quiet,-q}"[Only display IDs]" \
"($help --format)"--format"['json' or Custom format: {{.Id}} {{.Name}}]" \
"($help):command: _command_names -e" && ret=0
;;
(restart)
local state
_arguments $(__rancher_arguments) \
$opts_help \
"($help --type)"--type"[Restrict restart to specific types (service, container)]:type:(service container)" \