Exemplo n.º 1
0
class XCLIResponseBuildingTest(unittest.TestCase):

    def _readfile(self, fname):
        fullname = os.path.join(os.path.dirname(__file__), 'response', fname)
        with codecs.open(fullname, encoding='utf-8') as text:
            return text.read()

    def readresponses(self):
        if getattr(self, 'XCLI_XML_RESULT_SUCCESS_CODES', None):
            return
        self.XCLI_XML_RESULT_SUCCESS_CODES = [self._readfile('success.txt')]
        self.XCLI_XML_RESULT_ERROR_CODES = [self._readfile('error.txt')]
        self.XCLI_XML_RESULT_ERROR_CODES_WITH_RETURN = [
            self._readfile('error_w_return1.txt'),
            self._readfile('error_w_return2.txt')]

    def setUp(self):
        self.readresponses()
        self.xcli_client = XCLIClient(
            Mock(), 'user', 'password', populate=False)

    def test_build_response_returns_xcli_response_upon_getting_success(self):
        for xcli_xml_result in self.XCLI_XML_RESULT_SUCCESS_CODES:
            response = self.xcli_client._build_response(
                fromstring(xcli_xml_result))
            self.assertIsInstance(response, XCLIResponse)
            self.assertGreater(len(response.as_list), 0)

    def test_build_response_raises_error_with_empty_return_value(self):
        for xcli_xml_result in self.XCLI_XML_RESULT_ERROR_CODES:
            try:
                self.xcli_client._build_response(fromstring(xcli_xml_result))
                self.fail('Should have raised an exception.')
            except CommandExecutionError as e:
                self.assertTrue(e.code is not None)
                self.assertIsInstance(e.return_value, XCLIResponse)
                self.assertEqual(len(e.return_value.as_list), 0)

    def test_build_response_raises_error_with_correctly_parsed_return(self):
        for xcli_xml_result in self.XCLI_XML_RESULT_ERROR_CODES_WITH_RETURN:
            try:
                self.xcli_client._build_response(fromstring(xcli_xml_result))
                self.fail('Should have raised an exception.')
            except CommandExecutionError as e:
                self.assertTrue(e.code is not None)
                self.assertIsInstance(e.return_value, XCLIResponse)
                self.assertGreater(len(e.return_value.as_list), 0)
    def _connect(self):
        logger.debug("connecting to endpoint")
        try:
            self.client = XCLIClient.connect_multiendpoint_ssl(
                self.user, self.password, self.endpoint)

        except xcli_errors.CredentialsError:
            raise controller_errors.CredentialsError(self.endpoint)
        except xcli_errors.XCLIError:
            raise controller_errors.CredentialsError(self.endpoint)
Exemplo n.º 3
0
"""
Usage examples of the XCLIClient.
"""

from pyxcli.client import XCLIClient

# Connect SSL to an XIV-Storage.
xcli_client = XCLIClient.connect_ssl('username', 'password', "mgmt_ip")

# extracting Volume list from XIV-Storage
# as list - getting all the volumes as a list element
volumes = xcli_client.cmd.vol_list().as_list
for vol in volumes:
    print(vol.name)

# Getting all of the pools
pools = xcli_client.cmd.pool_list().as_list
for pool in pools:
    print(pool.name)

# Create volume - return value is an XML object indicating if the
# command succeeded.
vol_result = xcli_client.cmd.vol_create(pool="pool_name",
                                        size=301,
                                        vol="vol_name")

# Add volume to performance class (return value is an XML object)
perf_class_result = xcli_client.cmd.perf_class_add_vol(perf_class="perf_class",
                                                       vol="vol_name")
Exemplo n.º 4
0
"""
Usage examples of the XCLIClient.
"""

from pyxcli.client import XCLIClient

# Connect SSL to an XIV-Storage.
xcli_client = XCLIClient.connect_ssl('username', 'password', "mgmt_ip")

# extracting Volume list from XIV-Storage
# as list - getting all the volumes as a list element
volumes = xcli_client.cmd.vol_list().as_list
for vol in volumes:
    print (vol.name)

# Getting all of the pools
pools = xcli_client.cmd.pool_list().as_list
for pool in pools:
    print (pool.name)

# Create volume - return value is an XML object indicating if the
# command succeeded.
vol_result = xcli_client.cmd.vol_create(pool="pool_name", size=301,
                                        vol="vol_name")

# Add volume to performance class (return value is an XML object)
perf_class_result = xcli_client.cmd.perf_class_add_vol(perf_class="perf_class",
                                                       vol="vol_name")
Exemplo n.º 5
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*

from pyxcli.client import XCLIClient
import json, sys

# Variable Arguments

ibm_user = sys.argv[1]
ibm_pass = sys.argv[2]
ibm_host_ip = sys.argv[3]

# Connect SSL to XIV - Storage
xcli_client = XCLIClient.connect_ssl(ibm_user, ibm_pass, ibm_host_ip)

result_dict = {}

# CMD command and create data lists for parsing

ups = xcli_client.cmd.ups_list().as_list

result_dict['ups'] = ups

ats = xcli_client.cmd.ats_list().as_list

result_dict['ats'] = ats

cna = xcli_client.cmd.cna_list().as_list

result_dict['cna'] = cna
Exemplo n.º 6
0
 def setUp(self):
     self.readresponses()
     self.xcli_client = XCLIClient(
         Mock(), 'user', 'password', populate=False)
Exemplo n.º 7
0
#!/usr/bin/python3.6

import os
from pyxcli.client import XCLIClient

user = os.environ["USERNAME"]
password = os.environ["PASSWORD"]
endpoint = os.environ["STORAGE_ARRAYS"]
pool = os.environ["POOL_NAME"]

client = XCLIClient.connect_multiendpoint_ssl(user, password, endpoint)

vol_list = client.cmd.vol_list(pool=pool).as_list

for vol in vol_list:
    print("deleting volume : {}".format(vol))
    client.cmd.vol_delete(vol=vol.name)