Revision 0f1a06e3 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
2776 | 2776 |
|
2777 | 2777 |
def _GenerateDiskTemplate(cfg, template_name, |
2778 | 2778 |
instance_name, primary_node, |
2779 |
secondary_nodes, disk_sz, swap_sz): |
|
2779 |
secondary_nodes, disk_sz, swap_sz, |
|
2780 |
file_storage_dir, file_driver): |
|
2780 | 2781 |
"""Generate the entire disk layout for a given template type. |
2781 | 2782 |
|
2782 | 2783 |
""" |
... | ... | |
2808 | 2809 |
drbd_sdb_dev = _GenerateDRBD8Branch(cfg, primary_node, remote_node, |
2809 | 2810 |
swap_sz, names[2:4], "sdb") |
2810 | 2811 |
disks = [drbd_sda_dev, drbd_sdb_dev] |
2812 |
elif template_name == constants.DT_FILE: |
|
2813 |
if len(secondary_nodes) != 0: |
|
2814 |
raise errors.ProgrammerError("Wrong template configuration") |
|
2815 |
|
|
2816 |
file_sda_dev = objects.Disk(dev_type=constants.LD_FILE, size=disk_sz, |
|
2817 |
iv_name="sda", logical_id=(file_driver, |
|
2818 |
"%s/sda" % file_storage_dir)) |
|
2819 |
file_sdb_dev = objects.Disk(dev_type=constants.LD_FILE, size=swap_sz, |
|
2820 |
iv_name="sdb", logical_id=(file_driver, |
|
2821 |
"%s/sdb" % file_storage_dir)) |
|
2822 |
disks = [file_sda_dev, file_sdb_dev] |
|
2811 | 2823 |
else: |
2812 | 2824 |
raise errors.ProgrammerError("Invalid disk template '%s'" % template_name) |
2813 | 2825 |
return disks |
... | ... | |
2834 | 2846 |
""" |
2835 | 2847 |
info = _GetInstanceInfoText(instance) |
2836 | 2848 |
|
2849 |
if instance.disk_template == constants.DT_FILE: |
|
2850 |
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
|
2851 |
result = rpc.call_file_storage_dir_create(instance.primary_node, |
|
2852 |
file_storage_dir) |
|
2853 |
|
|
2854 |
if not result: |
|
2855 |
logger.Error("Could not connect to node '%s'" % inst.primary_node) |
|
2856 |
return False |
|
2857 |
|
|
2858 |
if not result[0]: |
|
2859 |
logger.Error("failed to create directory '%s'" % file_storage_dir) |
|
2860 |
return False |
|
2861 |
|
|
2837 | 2862 |
for device in instance.disks: |
2838 | 2863 |
logger.Info("creating volume %s for instance %s" % |
2839 | 2864 |
(device.iv_name, instance.name)) |
... | ... | |
2879 | 2904 |
" continuing anyway" % |
2880 | 2905 |
(device.iv_name, node)) |
2881 | 2906 |
result = False |
2907 |
|
|
2908 |
if instance.disk_template == constants.DT_FILE: |
|
2909 |
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1]) |
|
2910 |
if not rpc.call_file_storage_dir_remove(instance.primary_node, |
|
2911 |
file_storage_dir): |
|
2912 |
logger.Error("could not remove directory '%s'" % file_storage_dir) |
|
2913 |
result = False |
|
2914 |
|
|
2882 | 2915 |
return result |
2883 | 2916 |
|
2884 | 2917 |
|
... | ... | |
2994 | 3027 |
if self.op.disk_template not in constants.DISK_TEMPLATES: |
2995 | 3028 |
raise errors.OpPrereqError("Invalid disk template name") |
2996 | 3029 |
|
3030 |
if (self.op.file_driver and |
|
3031 |
not self.op.file_driver in constants.FILE_DRIVER): |
|
3032 |
raise errors.OpPrereqError("Invalid file driver name '%s'" % |
|
3033 |
self.op.file_driver) |
|
3034 |
|
|
3035 |
if self.op.file_storage_dir and os.path.isabs(self.op.file_storage_dir): |
|
3036 |
raise errors.OpPrereqError("File storage directory not a relative" |
|
3037 |
" path") |
|
3038 |
|
|
2997 | 3039 |
if self.op.disk_template in constants.DTS_NET_MIRROR: |
2998 | 3040 |
if getattr(self.op, "snode", None) is None: |
2999 | 3041 |
raise errors.OpPrereqError("The networked disk templates need" |
... | ... | |
3014 | 3056 |
constants.DT_PLAIN: self.op.disk_size + self.op.swap_size, |
3015 | 3057 |
# 256 MB are added for drbd metadata, 128MB for each drbd device |
3016 | 3058 |
constants.DT_DRBD8: self.op.disk_size + self.op.swap_size + 256, |
3059 |
constants.DT_FILE: None, |
|
3017 | 3060 |
} |
3018 | 3061 |
|
3019 | 3062 |
if self.op.disk_template not in req_size_dict: |
... | ... | |
3130 | 3173 |
else: |
3131 | 3174 |
network_port = None |
3132 | 3175 |
|
3176 |
# build the full file storage dir path |
|
3177 |
file_storage_dir = os.path.normpath(os.path.join( |
|
3178 |
self.sstore.GetFileStorageDir(), |
|
3179 |
self.op.file_storage_dir, instance)) |
|
3180 |
|
|
3181 |
|
|
3133 | 3182 |
disks = _GenerateDiskTemplate(self.cfg, |
3134 | 3183 |
self.op.disk_template, |
3135 | 3184 |
instance, pnode_name, |
3136 | 3185 |
self.secondaries, self.op.disk_size, |
3137 |
self.op.swap_size) |
|
3186 |
self.op.swap_size, |
|
3187 |
file_storage_dir, |
|
3188 |
self.op.file_driver) |
|
3138 | 3189 |
|
3139 | 3190 |
iobj = objects.Instance(name=instance, os=self.op.os_type, |
3140 | 3191 |
primary_node=pnode_name, |
Also available in: Unified diff