Alessandro Pilotti dd6b4d74c5 Adds Windows Storage Manager API support
This is needed on Nano Server where VDS is not available.
The logic for extending the volumes was decoupled from the plugin to
a windows storage utility (VDS) alongside other extending utility which
is available on Nano and versions greater than ws2012/w8 (WSM).
According to the current Windows version, a suitable utility for extending
will be loaded through a factory manager.

Implements: blueprint windows-storage-manager
Co-Authored-By: Cosmin Poieana <cpoieana@cloudbasesolutions.com>
Change-Id: I7c8eea35a632c812e99808befb5e7528d66363cc
2015-09-14 03:36:51 +03:00

53 lines
2.1 KiB
Python

# Copyright 2013 Cloudbase Solutions Srl
#
# 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.
import wmi
from oslo_log import log as oslo_logging
from cloudbaseinit import exception
from cloudbaseinit.utils.windows.storage import base
LOG = oslo_logging.getLogger(__name__)
class WSMStorageManager(base.BaseStorageManager):
def __init__(self):
self._conn = wmi.WMI(moniker='//./Root/Microsoft/Windows/Storage')
def extend_volumes(self, volume_indexes=None):
volumes = self._conn.MSFT_Volume()
for idx, volume in enumerate(volumes, 1):
# TODO(alexpilotti): don't rely on the volumes WMI query order
if volume_indexes and idx not in volume_indexes:
continue
partitions = volume.associators(wmi_result_class='MSFT_Partition')
for partition in partitions:
(ret_val, _, size_max, _) = partition.GetSupportedSize()
if ret_val:
raise exception.CloudbaseInitException(
"GetSupportedSize failed with error: %s" % ret_val)
if size_max > partition.Size:
LOG.info('Extending partition "%(partition_number)s" '
'to %(size)s bytes' %
{'partition_number': partition.PartitionNumber,
'size': size_max})
(ret_val, _) = partition.Resize(size_max)
if ret_val:
raise exception.CloudbaseInitException(
"Resize failed with error: %s" % ret_val)