コード例 #1
0
    def test_create_with_APIException(self, mock_post):

        with self.assertRaises(APIException):
            get_client().k8s_cluster.create(
                name="a",
                k8shosts_config=[
                    K8sClusterHostConfig("/api/v2/worker/k8shost/1", "master")
                ],
            )
コード例 #2
0
    def test_create(self, mock_post):

        with self.assertRaisesRegexp(
                AssertionError,
                "'name' must be provided and must be a string"):
            get_client().k8s_cluster.create()

        with self.assertRaisesRegexp(
                AssertionError, "'description' if provided, must be a string"):
            get_client().k8s_cluster.create(name="a", description=1)

        with self.assertRaisesRegexp(
                AssertionError, "'k8s_version' if provided, must be a string"):
            get_client().k8s_cluster.create(name="a", k8s_version=1)

        with self.assertRaisesRegexp(AssertionError,
                                     "'pod_network_range' must be a string"):
            get_client().k8s_cluster.create(name="a", pod_network_range=1)

        with self.assertRaisesRegexp(
                AssertionError, "'service_network_range' must be a string"):
            get_client().k8s_cluster.create(name="a", service_network_range=1)

        with self.assertRaisesRegexp(AssertionError,
                                     "'pod_dns_domain' must be a string"):
            get_client().k8s_cluster.create(name="a", pod_dns_domain=1)

        with self.assertRaisesRegexp(
                AssertionError,
                "'persistent_storage_local' must be True or False"):
            get_client().k8s_cluster.create(name="a",
                                            persistent_storage_local=1)

        with self.assertRaisesRegexp(
                AssertionError,
                "'persistent_storage_nimble_csi' must be True or False",
        ):
            get_client().k8s_cluster.create(name="a",
                                            persistent_storage_nimble_csi=1)

        with self.assertRaisesRegexp(AssertionError,
                                     "'k8shosts_config' must be a list"):
            get_client().k8s_cluster.create(name="a", k8shosts_config=1)

        with self.assertRaisesRegexp(
                AssertionError,
                "'k8shosts_config' must have at least one item"):
            get_client().k8s_cluster.create(name="a", k8shosts_config=[])

        with self.assertRaisesRegexp(
                AssertionError,
                "'k8shosts_config' item '0' is not of type K8sClusterHostConfig",
        ):
            get_client().k8s_cluster.create(name="a", k8shosts_config=[1, 2])

        # pylint: disable=anomalous-backslash-in-string
        with self.assertRaisesRegexp(
                AssertionError,
            (
                "'node' must have format"
                " '\/api\/v2\/worker\/k8shost\/\[0-9\]\+'"  # noqa: W605
            ),
        ):
            get_client().k8s_cluster.create(
                name="a", k8shosts_config=[K8sClusterHostConfig("a", "b")])

        with self.assertRaisesRegexp(
                AssertionError,
                "'role' must one of \['master, worker'\]",  # noqa: W605
        ):
            get_client().k8s_cluster.create(
                name="a",
                k8shosts_config=[
                    K8sClusterHostConfig("/api/v2/worker/k8shost/1", "b")
                ],
            )

        # Finally we can create a cluster
        id = get_client().k8s_cluster.create(
            name="a",
            k8shosts_config=[
                K8sClusterHostConfig("/api/v2/worker/k8shost/1", "master")
            ],
        )
        self.assertEqual(id, "/api/v2/k8scluster/99")

        # now with a description
        id = get_client().k8s_cluster.create(
            name="a",
            k8shosts_config=[
                K8sClusterHostConfig("/api/v2/worker/k8shost/1", "master")
            ],
            description="Cluster Description",
        )
        self.assertEqual(id, "/api/v2/k8scluster/99")

        # now with a k8s version
        id = get_client().k8s_cluster.create(
            name="a",
            k8shosts_config=[
                K8sClusterHostConfig("/api/v2/worker/k8shost/1", "master")
            ],
            k8s_version="1.18.0",
        )
        self.assertEqual(id, "/api/v2/k8scluster/99")

        # now with a k8s version
        id = get_client().k8s_cluster.create(
            name="a",
            k8shosts_config=[
                K8sClusterHostConfig("/api/v2/worker/k8shost/1", "master")
            ],
            k8s_version="1.18.0",
            addons=["picasso"],
        )
        self.assertEqual(id, "/api/v2/k8scluster/99")
コード例 #3
0
import textwrap

client = ContainerPlatformClient(username='******',
                                 password='******',
                                 api_host='127.0.0.1',
                                 api_port=8080,
                                 use_ssl=True,
                                 verify_ssl='/certs/hpecp-ca-cert.pem')

client.create_session()

print(client.k8s_worker.get_k8shosts().tabulate())

try:
    k8shosts_config = [
        K8sClusterHostConfig(4, 'worker'),
        K8sClusterHostConfig(5, 'master')
    ]
    k8s_cluster_id = client.k8s_cluster.create(name='def',
                                               description='my cluster',
                                               k8s_version='1.17.0',
                                               k8shosts_config=k8shosts_config)
    print('creating cluster id: ' + k8s_cluster_id)
except APIException as e:
    text = """APIException(
        Backend API Response -> {}
        HTTP Method -> {}
        Request URL -> {}
        Request Data -> [{}]
    )"""
    print(