#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
OpenNebula Driver for Linstor
Copyright 2019 LINBIT USA LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import print_function

import sys
import os

from one import util, consts
from one.datastore import Datastore
from one.extender import deploy, get_device_path
from linstor import SizeCalc

SIZE = sys.argv[1]
FORMAT = sys.argv[2]
DST = sys.argv[3]
VM_ID = sys.argv[4]
DS_ID = sys.argv[5]


def main():
    util.log_info("Entering tm/mkimage on {h} size {s}.".format(h=DST, s=SIZE))

    disk_id = DST.split(".")[-1].strip()

    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()

    datastore = Datastore(util.show_ds(DS_ID))

    res_name = consts.VOLATILE_PREFIX + "-vm{vm_id}-disk{disk_id}".format(vm_id=VM_ID, disk_id=disk_id)

    resource = deploy(
        linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name,
        vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group
    )

    resource.activate(dst_host)

    device_path = get_device_path(resource)

    if FORMAT and FORMAT != "raw":
        mkfs_command = 'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'.format(
            device_path,
            FORMAT,
            SizeCalc.convert(resource.volumes[0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB))

        rc = util.ssh_exec_and_log(
            host=dst_host,
            cmd=mkfs_command,
            error_msg="Error mkimage {}, on {}".format(device_path, dst_host))

        if rc != 0:
            sys.exit(rc)

    # link drbd device
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)

    util.log_info("Leaving tm/mkimage successfully.")


if __name__ == "__main__":
    util.run_main(main)

6b3934c1a1e7db09a524005485ced8b1a218dc0d
<mask token>


def main():
    util.log_info('Entering tm/mkimage on {h} size {s}.'.format(h=DST, s=SIZE))
    disk_id = DST.split('.')[-1].strip()
    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()
    datastore = Datastore(util.show_ds(DS_ID))
    res_name = consts.VOLATILE_PREFIX + '-vm{vm_id}-disk{disk_id}'.format(vm_id
        =VM_ID, disk_id=disk_id)
    resource = deploy(linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name, vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group)
    resource.activate(dst_host)
    device_path = get_device_path(resource)
    if FORMAT and FORMAT != 'raw':
        mkfs_command = (
            'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'
            .format(device_path, FORMAT, SizeCalc.convert(resource.volumes[
            0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB)))
        rc = util.ssh_exec_and_log(host=dst_host, cmd=mkfs_command,
            error_msg='Error mkimage {}, on {}'.format(device_path, dst_host))
        if rc != 0:
            sys.exit(rc)
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)
    util.log_info('Leaving tm/mkimage successfully.')


<mask token>

<mask token>


def main():
    util.log_info('Entering tm/mkimage on {h} size {s}.'.format(h=DST, s=SIZE))
    disk_id = DST.split('.')[-1].strip()
    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()
    datastore = Datastore(util.show_ds(DS_ID))
    res_name = consts.VOLATILE_PREFIX + '-vm{vm_id}-disk{disk_id}'.format(vm_id
        =VM_ID, disk_id=disk_id)
    resource = deploy(linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name, vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group)
    resource.activate(dst_host)
    device_path = get_device_path(resource)
    if FORMAT and FORMAT != 'raw':
        mkfs_command = (
            'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'
            .format(device_path, FORMAT, SizeCalc.convert(resource.volumes[
            0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB)))
        rc = util.ssh_exec_and_log(host=dst_host, cmd=mkfs_command,
            error_msg='Error mkimage {}, on {}'.format(device_path, dst_host))
        if rc != 0:
            sys.exit(rc)
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)
    util.log_info('Leaving tm/mkimage successfully.')


if __name__ == '__main__':
    util.run_main(main)

<mask token>
SIZE = sys.argv[1]
FORMAT = sys.argv[2]
DST = sys.argv[3]
VM_ID = sys.argv[4]
DS_ID = sys.argv[5]


def main():
    util.log_info('Entering tm/mkimage on {h} size {s}.'.format(h=DST, s=SIZE))
    disk_id = DST.split('.')[-1].strip()
    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()
    datastore = Datastore(util.show_ds(DS_ID))
    res_name = consts.VOLATILE_PREFIX + '-vm{vm_id}-disk{disk_id}'.format(vm_id
        =VM_ID, disk_id=disk_id)
    resource = deploy(linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name, vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group)
    resource.activate(dst_host)
    device_path = get_device_path(resource)
    if FORMAT and FORMAT != 'raw':
        mkfs_command = (
            'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'
            .format(device_path, FORMAT, SizeCalc.convert(resource.volumes[
            0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB)))
        rc = util.ssh_exec_and_log(host=dst_host, cmd=mkfs_command,
            error_msg='Error mkimage {}, on {}'.format(device_path, dst_host))
        if rc != 0:
            sys.exit(rc)
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)
    util.log_info('Leaving tm/mkimage successfully.')


if __name__ == '__main__':
    util.run_main(main)

<mask token>
from __future__ import print_function
import sys
import os
from one import util, consts
from one.datastore import Datastore
from one.extender import deploy, get_device_path
from linstor import SizeCalc
SIZE = sys.argv[1]
FORMAT = sys.argv[2]
DST = sys.argv[3]
VM_ID = sys.argv[4]
DS_ID = sys.argv[5]


def main():
    util.log_info('Entering tm/mkimage on {h} size {s}.'.format(h=DST, s=SIZE))
    disk_id = DST.split('.')[-1].strip()
    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()
    datastore = Datastore(util.show_ds(DS_ID))
    res_name = consts.VOLATILE_PREFIX + '-vm{vm_id}-disk{disk_id}'.format(vm_id
        =VM_ID, disk_id=disk_id)
    resource = deploy(linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name, vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group)
    resource.activate(dst_host)
    device_path = get_device_path(resource)
    if FORMAT and FORMAT != 'raw':
        mkfs_command = (
            'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'
            .format(device_path, FORMAT, SizeCalc.convert(resource.volumes[
            0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB)))
        rc = util.ssh_exec_and_log(host=dst_host, cmd=mkfs_command,
            error_msg='Error mkimage {}, on {}'.format(device_path, dst_host))
        if rc != 0:
            sys.exit(rc)
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)
    util.log_info('Leaving tm/mkimage successfully.')


if __name__ == '__main__':
    util.run_main(main)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
OpenNebula Driver for Linstor
Copyright 2019 LINBIT USA LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from __future__ import print_function

import sys
import os

from one import util, consts
from one.datastore import Datastore
from one.extender import deploy, get_device_path
from linstor import SizeCalc

SIZE = sys.argv[1]
FORMAT = sys.argv[2]
DST = sys.argv[3]
VM_ID = sys.argv[4]
DS_ID = sys.argv[5]


def main():
    util.log_info("Entering tm/mkimage on {h} size {s}.".format(h=DST, s=SIZE))

    disk_id = DST.split(".")[-1].strip()

    dst_host = util.arg_host(DST).strip()
    dst_path = util.arg_path(DST).strip()
    dst_dir = os.path.dirname(dst_path).strip()

    datastore = Datastore(util.show_ds(DS_ID))

    res_name = consts.VOLATILE_PREFIX + "-vm{vm_id}-disk{disk_id}".format(vm_id=VM_ID, disk_id=disk_id)

    resource = deploy(
        linstor_controllers=datastore.linstor_controllers,
        resource_name=res_name,
        vlm_size_str='{s}Mib'.format(s=SIZE),
        resource_group=datastore.linstor_resource_group
    )

    resource.activate(dst_host)

    device_path = get_device_path(resource)

    if FORMAT and FORMAT != "raw":
        mkfs_command = 'set -e ; export PATH=/usr/sbin:/sbin:$PATH ; $(mkfs_command "{0}" "{1}" "{2}")'.format(
            device_path,
            FORMAT,
            SizeCalc.convert(resource.volumes[0].size, SizeCalc.UNIT_B, SizeCalc.UNIT_MiB))

        rc = util.ssh_exec_and_log(
            host=dst_host,
            cmd=mkfs_command,
            error_msg="Error mkimage {}, on {}".format(device_path, dst_host))

        if rc != 0:
            sys.exit(rc)

    # link drbd device
    util.link_file(dst_host, dst_dir, dst_path, device_path, res_name)

    util.log_info("Leaving tm/mkimage successfully.")


if __name__ == "__main__":
    util.run_main(main)
