Revision 50a707fa
b/scripts/gnt-backup | ||
---|---|---|
29 | 29 |
from ganeti.cli import * |
30 | 30 |
from ganeti import opcodes |
31 | 31 |
from ganeti import constants |
32 |
from ganeti import errors |
|
33 |
from ganeti import utils |
|
32 | 34 |
|
33 | 35 |
|
34 | 36 |
_VALUE_TRUE = "true" |
... | ... | |
94 | 96 |
if opts.hypervisor: |
95 | 97 |
hypervisor, hvparams = opts.hypervisor |
96 | 98 |
|
99 |
if opts.nics: |
|
100 |
try: |
|
101 |
nic_max = max(int(nidx[0])+1 for nidx in opts.nics) |
|
102 |
except ValueError, err: |
|
103 |
raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) |
|
104 |
nics = [{}] * nic_max |
|
105 |
for nidx, ndict in opts.nics.items(): |
|
106 |
nidx = int(nidx) |
|
107 |
nics[nidx] = ndict |
|
108 |
elif opts.no_nics: |
|
109 |
# no nics |
|
110 |
nics = [] |
|
111 |
else: |
|
112 |
# default of one nic, all auto |
|
113 |
nics = [{}] |
|
114 |
|
|
115 |
if opts.disk_template == constants.DT_DISKLESS: |
|
116 |
if opts.disks: |
|
117 |
raise errors.OpPrereqError("Diskless instance but disk" |
|
118 |
" information passed") |
|
119 |
disks = [] |
|
120 |
else: |
|
121 |
if not opts.disks: |
|
122 |
raise errors.OpPrereqError("No disk information specified") |
|
123 |
try: |
|
124 |
disk_max = max(int(didx[0])+1 for didx in opts.disks) |
|
125 |
except ValueError, err: |
|
126 |
raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) |
|
127 |
disks = [{}] * disk_max |
|
128 |
for didx, ddict in opts.disks: |
|
129 |
didx = int(didx) |
|
130 |
if "size" not in ddict: |
|
131 |
raise errors.OpPrereqError("Missing size for disk %d" % didx) |
|
132 |
try: |
|
133 |
ddict["size"] = utils.ParseUnit(ddict["size"]) |
|
134 |
except ValueError, err: |
|
135 |
raise errors.OpPrereqError("Invalid disk size for disk %d: %s" % |
|
136 |
(didx, err)) |
|
137 |
disks[didx] = ddict |
|
138 |
|
|
97 | 139 |
ValidateBeParams(opts.beparams) |
98 | 140 |
|
99 | 141 |
op = opcodes.OpCreateInstance(instance_name=instance, |
100 |
disk_size=opts.size, swap_size=opts.swap, |
|
101 | 142 |
disk_template=opts.disk_template, |
143 |
disks=disks, |
|
144 |
nics=nics, |
|
102 | 145 |
mode=constants.INSTANCE_IMPORT, |
103 | 146 |
pnode=pnode, snode=snode, |
104 | 147 |
ip_check=opts.ip_check, |
105 |
ip=opts.ip, bridge=opts.bridge, start=False,
|
|
148 |
start=False, |
|
106 | 149 |
src_node=opts.src_node, src_path=opts.src_dir, |
107 |
wait_for_sync=opts.wait_for_sync, mac=opts.mac,
|
|
150 |
wait_for_sync=opts.wait_for_sync, |
|
108 | 151 |
file_storage_dir=opts.file_storage_dir, |
109 | 152 |
file_driver=opts.file_driver, |
110 | 153 |
iallocator=opts.iallocator, |
... | ... | |
140 | 183 |
make_option("-n", "--node", dest="node", |
141 | 184 |
help="Target node and optional secondary node", |
142 | 185 |
metavar="<pnode>[:<snode>]"), |
143 |
cli_option("-s", "--os-size", dest="size", help="Disk size, in MiB unless" |
|
144 |
" a suffix is used", |
|
145 |
default=20 * 1024, type="unit", metavar="<size>"), |
|
146 |
cli_option("--swap-size", dest="swap", help="Swap size", |
|
147 |
default=4 * 1024, type="unit", metavar="<size>"), |
|
148 | 186 |
keyval_option("-B", "--backend", dest="beparams", |
149 | 187 |
type="keyval", default={}, |
150 | 188 |
help="Backend parameters"), |
151 | 189 |
make_option("-t", "--disk-template", dest="disk_template", |
152 | 190 |
help="Custom disk setup (diskless, file, plain, drbd)", |
153 | 191 |
default=None, metavar="TEMPL"), |
154 |
make_option("-i", "--ip", dest="ip", |
|
155 |
help="IP address ('none' [default], 'auto', or specify address)", |
|
156 |
default='none', type="string", metavar="<ADDRESS>"), |
|
192 |
ikv_option("--disk", help="Disk information", |
|
193 |
default=[], dest="disks", |
|
194 |
action="append", |
|
195 |
type="identkeyval"), |
|
196 |
ikv_option("--net", help="NIC information", |
|
197 |
default=[], dest="nics", |
|
198 |
action="append", |
|
199 |
type="identkeyval"), |
|
200 |
make_option("--no-nics", default=False, action="store_true", |
|
201 |
help="Do not create any network cards for the instance"), |
|
157 | 202 |
make_option("--no-wait-for-sync", dest="wait_for_sync", default=True, |
158 | 203 |
action="store_false", help="Don't wait for sync (DANGEROUS!)"), |
159 |
make_option("-b", "--bridge", dest="bridge", |
|
160 |
help="Bridge to connect this instance to", |
|
161 |
default=None, metavar="<bridge>"), |
|
162 |
make_option("--mac", dest="mac", |
|
163 |
help="MAC address ('auto' [default], or specify address)", |
|
164 |
default='auto', type="string", metavar="<MACADDRESS>"), |
|
165 | 204 |
make_option("--src-node", dest="src_node", help="Source node", |
166 | 205 |
metavar="<node>"), |
167 | 206 |
make_option("--src-dir", dest="src_dir", help="Source directory", |
Also available in: Unified diff