+# Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
---\r
-- name: install lvm2 external package when lvm backend enabled\r
+- name: install lvm2 ang tgt external package when lvm backend enabled\r
apt:\r
- name: lvm2\r
+ name: "{{ item }}"\r
+ state: present\r
+ with_items:\r
+ - lvm2\r
+ - tgt\r
+ - thin-provisioning-tools\r
+\r
+- name: configure lvm section in opensds global info if specify lvm backend\r
+ shell: |\r
+ cat >> opensds.conf <<OPENSDS_GLOABL_CONFIG_DOC\r
+\r
+ [lvm]\r
+ name = {{ lvm_name }}\r
+ description = {{ lvm_description }}\r
+ driver_name = {{ lvm_driver_name }}\r
+ config_path = {{ lvm_config_path }}\r
+ args:\r
+ chdir: "{{ opensds_config_dir }}"\r
+ ignore_errors: yes\r
\r
-- name: copy opensds lvm backend file if specify lvm backend\r
+- name: copy opensds lvm backend file to lvm config path if specify lvm backend\r
copy:\r
src: ../../../group_vars/lvm/lvm.yaml\r
dest: "{{ lvm_config_path }}"\r
\r
-- name: check if volume group existed\r
- shell: vgdisplay {{ vg_name }}\r
- ignore_errors: yes\r
- register: vg_existed\r
+- name: create directory to volume group file\r
+ file:\r
+ path: "{{ opensds_work_dir }}/volumegroups"\r
+ state: directory\r
+ recurse: yes\r
+\r
+- name: create volume group in thin mode\r
+ shell:\r
+ _raw_params: |\r
+ function _create_lvm_volume_group {\r
+ local vg=$1\r
+ local size=$2\r
+\r
+ local backing_file={{ opensds_work_dir }}/volumegroups/${vg}.img\r
+ if ! sudo vgs $vg; then\r
+ # Only create if the file doesn't already exists\r
+ [[ -f $backing_file ]] || truncate -s $size $backing_file\r
+ local vg_dev\r
+ vg_dev=`sudo losetup -f --show $backing_file`\r
+\r
+ # Only create physical volume if it doesn't already exist\r
+ if ! sudo pvs $vg_dev; then\r
+ sudo pvcreate $vg_dev\r
+ fi\r
\r
-- name: create a volume group and initialize it\r
- lvg:\r
- vg: "{{ vg_name }}"\r
- pvs: "{{ pv_devices }}"\r
- when: vg_existed is undefined or vg_existed.rc != 0\r
+ # Only create volume group if it doesn't already exist\r
+ if ! sudo vgs $vg; then\r
+ sudo vgcreate $vg $vg_dev\r
+ fi\r
+ fi\r
+ }\r
+ modprobe dm_thin_pool\r
+ _create_lvm_volume_group {{ opensds_volume_group }} 10G\r
+ args:\r
+ executable: /bin/bash\r
+ become: true\r