Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cce scenario #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions playbooks/files/create_cce_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import sys

import openstack
from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])
dict = {
'metadata': {
'name': sys.argv[1]
},
'spec': {
'type': 'VirtualMachine',
'version': 'v1.11.7-r2',
'hostNetwork': {
'vpc': sys.argv[2],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vpc is currently renamed to router_id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I oriented my self @ the official docu. After now how this mapping is done, I see the point. Thanks for the hint. Changed it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich changed both values, but get "BadRequest" if I do this. Switching back works again.

(py36) ubuntu@tino-dev2:~/git/apimon-tests/playbooks/files$ python create_cce_cluster.py tino-cce1 26ca2783-dc40-4e3a-95b1-5a0756441e12 25d24fc8-d019-4a34-9fff-0a09fde6a9cb
Traceback (most recent call last):
  File "create_cce_cluster.py", line 37, in <module>
    cluster = conn.cce.create_cluster(**dict)
  File "/home/ubuntu/git/python-otcextensions/otcextensions/sdk/cce/v3/_proxy.py", line 58, in create_cluster
    _cluster.Cluster, prepend_key=False, **attrs
  File "/home/ubuntu/git/python-otcextensions/.tox/py36/lib/python3.6/site-packages/openstack/proxy.py", line 417, in _create
    return res.create(self, base_path=base_path)
  File "/home/ubuntu/git/python-otcextensions/otcextensions/sdk/cce/v3/_base.py", line 93, in create
    return super(Resource, self).create(session, prepend_key, base_path)
  File "/home/ubuntu/git/python-otcextensions/.tox/py36/lib/python3.6/site-packages/openstack/resource.py", line 1278, in create
    self._translate_response(response, has_body=has_body)
  File "/home/ubuntu/git/python-otcextensions/.tox/py36/lib/python3.6/site-packages/openstack/resource.py", line 1107, in _translate_response
    exceptions.raise_from_response(response, error_message=error_message)
  File "/home/ubuntu/git/python-otcextensions/.tox/py36/lib/python3.6/site-packages/openstack/exceptions.py", line 229, in raise_from_response
    http_status=http_status, request_id=request_id
openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: https://cce.eu-de.otc.t-systems.com/api/v3/projects/16d53a84a13b49529d2e2c3646691288/clusters, Bad Request

'subnet': sys.argv[3]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subnet => network_id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also changed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same like as mentioned above

},
'flavor': 'cce.s1.small',
'containerNetwork': {
'mode': 'overlay_l2',
'cidr': '172.16.0.0/16'
}
}
}

if (cluster is None):
cluster = conn.cce.create_cluster(**dict)
job = conn.cce.get_job(cluster.job_id)
conn.cce.wait_for_job(job)
45 changes: 45 additions & 0 deletions playbooks/files/create_cce_cluster_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3

import sys

import openstack
from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])
node = conn.cce.find_cluster_node(cluster, sys.argv[2])
dict = {
"metadata": {
"name": sys.argv[2]
},
"spec": {
"flavor": "s2.large.4",
"az": "eu-de-01",
"login": {
"sshKey": sys.argv[3]
},
"rootVolume": {
"size": 40,
"volumetype": "SATA"
},
"dataVolumes": [
{
"size": 100,
"volumetype": "SATA"
}
],
"count": 1
}
}

if cluster and (node is None):
node = conn.cce.create_cluster_node(cluster, **dict)
job = conn.cce.get_job(node.job_id)
conn.cce.wait_for_job(job)
23 changes: 23 additions & 0 deletions playbooks/files/delete_cce_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3

import sys
import time

import openstack
from otcextensions import sdk

openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])

timer = 0

if cluster:
conn.cce.delete_cluster(cluster)
time.sleep(100)
22 changes: 22 additions & 0 deletions playbooks/files/delete_cce_cluster_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3

import sys

import openstack
from otcextensions import sdk

openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])
node = conn.cce.find_cluster_node(cluster, sys.argv[2])

if cluster and node:
node = conn.cce.delete_cluster_node(cluster, node)
# job = conn.cce.get_job(node.job_id)
# conn.cce.wait_for_job(job)
16 changes: 16 additions & 0 deletions playbooks/files/find_cce_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

import openstack
import sys

from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])
17 changes: 17 additions & 0 deletions playbooks/files/find_cce_cluster_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3

import openstack
import sys

from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

cluster = conn.cce.find_cluster(sys.argv[1])
node = conn.cce.find_cluster_node(cluster, sys.argv[2])
15 changes: 15 additions & 0 deletions playbooks/files/get_cce_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3

import openstack
from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)


cluster = conn.cce.get_cluster('e9d8539e-c894-11e9-a4c3-0255ac101618')
80 changes: 80 additions & 0 deletions playbooks/files/get_cce_cluster_certificates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3

import re
import sys

import openstack
from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

# Search for corresponding cluster
cluster = conn.cce.find_cluster(sys.argv[1])

# Query Certificate information
certificates = conn.cce.get_cluster_certificates(cluster)

# Use RegEx to create kubectl conform configuration information
ca_regex = r"ca=(\w*\={,2}),"
client_certificate_regex = r"client_certificate=(\w*\={,2}),"
client_key_regex = r"client_key=(\w*\={,2}),"
internal_ip_regex = r"context={'name': 'internal', 'cluster': 'https://((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]):[0-9]{,5})"

ca_data = re.search(ca_regex, str(certificates))
client_certificate_data = re.search(client_certificate_regex,
str(certificates))
client_key_data = re.search(client_key_regex, str(certificates))
internal_ip_data = re.search(internal_ip_regex, str(certificates))

ca_data = ca_data.group(1)
client_certificate_data = client_certificate_data.group(1)
client_key_data = client_key_data.group(1)
internal_ip_data = "https://" + internal_ip_data.group(1)

# print("CA-data: " + ca_data)
# print("Client Cert Data: " + client_certificate_data)
# print("Client Key Data: " + client_key_data)
# print("IP Data: " + internal_ip_data)

kube_config = {
"kind": "Config",
"apiVersion": "v1",
"preferences": {
},
"clusters": [
{
"name": "internalCluster",
"cluster": {
"server": internal_ip_data,
"certificate-authority-data": ca_data
}
}
],
"users": [
{
"name": "user",
"user": {
"client-certificate-data": client_certificate_data,
"client-key-data": client_key_data
}
}
],
"contexts": [
{
"name": "internal",
"context": {
"cluster": "internalCluster",
"user": "user"
}
}
],
"current-context": "internal"
}

print(str(kube_config))
15 changes: 15 additions & 0 deletions playbooks/files/list_cce_clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3

import openstack
from otcextensions import sdk

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)

for cluster in conn.cce.clusters():
print(cluster)
19 changes: 19 additions & 0 deletions playbooks/files/wait_for_cce_cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

import openstack
from otcextensions import sdk

import sys

# openstack.enable_logging(True, http_debug=True)

# An 'otc' is a cloud connection with name 'otc' configured in the clouds.yaml
conn = openstack.connect()

# Register OTC Extensions
sdk.register_otc_extensions(conn)


cluster = conn.cce.find_cluster(sys.argv[1])
conn.cce.wait_for_cluster(cluster, status='Available',
failures=None, interval=10, wait=960)
Loading