Skip to content

Commit ae289b0

Browse files
authored
Merge pull request #270 from hpe-container-platform-community/enable-kubectl
initial try
2 parents 947589a + 4084f9f commit ae289b0

File tree

3 files changed

+168
-105
lines changed

3 files changed

+168
-105
lines changed

hpecp/cli/k8scluster.py

+27
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __dir__(self):
6464
"statuses",
6565
"upgrade_cluster",
6666
"wait_for_status",
67+
"run_kubectl_command"
6768
]
6869

6970
def __init__(self):
@@ -551,3 +552,29 @@ def import_generic_cluster_with_json(
551552
json_content
552553
)
553554
)
555+
556+
@base.intercept_exception
557+
def run_kubectl_command(
558+
self, id, op, yaml
559+
):
560+
"""Run a kubectl command on k8s cluster.
561+
562+
Parameters
563+
------
564+
:param id: The k8s cluster ID, integer number in resource path /api/v2/k8scluster/<id>
565+
:param op: operation to pass to kubectl, one of 'create', 'delete', 'update'
566+
:param yaml: base64 encoded yaml file to operate
567+
568+
Returns
569+
-------
570+
TODO
571+
572+
Raises
573+
------
574+
APIException
575+
"""
576+
print(
577+
base.get_client().k8s_cluster.run_kubectl_command(
578+
id, op, yaml
579+
)
580+
)

hpecp/k8s_cluster.py

+36
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,39 @@ def import_generic_cluster_with_json(self, json):
671671
data=json,
672672
)
673673
return CaseInsensitiveDict(response.headers)["Location"]
674+
675+
def run_kubectl_command(self, id, op='create', yaml=''):
676+
"""Run a kubectl command on k8s cluster.
677+
678+
Parameters
679+
------
680+
id: str
681+
The k8s cluster ID (ID = 1 or 2 etc, not the base path as /api/v2/k8s_cluster/1)
682+
op: str
683+
op can be one of create,delete,update
684+
yaml: str
685+
base64 encoding of the yaml file
686+
687+
Returns
688+
-------
689+
TODO
690+
691+
Raises
692+
------
693+
APIException
694+
"""
695+
696+
data = {
697+
"op": op,
698+
"data": yaml
699+
}
700+
701+
response = self.client._request(
702+
url="/api/v2/k8scluster/{id}/kubectl",
703+
http_method="post",
704+
description=(
705+
"K8sClusterController/" "run_kubectl_command"
706+
),
707+
data=json,
708+
)
709+
return response.json()

tests/_HPECP-REST-API-SOAPUI.xml

+105-105
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,58 @@ def queryString = mockRequest.getRequest().getQueryString()
1515
log.info "QueryString: " + queryString
1616

1717

18-
/*
19-
// Script dispatcher is used to select a response based on the incoming request.
20-
// Here are few examples showing how to match based on path, query param, header and body
21-
22-
// Match based on path
23-
def requestPath = mockRequest.getPath()
24-
log.info "Path: "+ requestPath
25-
26-
if( requestPath.contains("json") )
27-
{
28-
// return the name of the response you want to dispatch
29-
return "JSON Response"
30-
}
31-
32-
33-
// Match based on query parameter
34-
def queryString = mockRequest.getRequest().getQueryString()
35-
log.info "QueryString: " + queryString
36-
37-
if( queryString.contains("stockholm") )
38-
{
39-
// return the name of the response you want to dispatch
40-
return "Response Stockholm"
41-
}
42-
else if( queryString.contains("london") )
43-
{
44-
// return the name of the response you want to dispatch
45-
return "Response London"
46-
}
47-
48-
49-
// Match based on header
50-
def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Accept-Encoding")
51-
log.info "AcceptEncoding Header List: " + acceptEncodingHeaderList
52-
53-
if( acceptEncodingHeaderList.contains("gzip,deflate") )
54-
{
55-
// return the name of the response you want to dispatch
56-
return "GZiped Response"
57-
}
58-
59-
60-
// Match based on body
61-
def requestBody = mockRequest.getRequestContent()
62-
log.info "Request body: " + requestBody
63-
64-
if( requestBody.contains("some data") )
65-
{
66-
// return the name of the response you want to dispatch
67-
return "Response N"
68-
}
69-
*/
18+
/*
19+
// Script dispatcher is used to select a response based on the incoming request.
20+
// Here are few examples showing how to match based on path, query param, header and body
21+
22+
// Match based on path
23+
def requestPath = mockRequest.getPath()
24+
log.info "Path: "+ requestPath
25+
26+
if( requestPath.contains("json") )
27+
{
28+
// return the name of the response you want to dispatch
29+
return "JSON Response"
30+
}
31+
32+
33+
// Match based on query parameter
34+
def queryString = mockRequest.getRequest().getQueryString()
35+
log.info "QueryString: " + queryString
36+
37+
if( queryString.contains("stockholm") )
38+
{
39+
// return the name of the response you want to dispatch
40+
return "Response Stockholm"
41+
}
42+
else if( queryString.contains("london") )
43+
{
44+
// return the name of the response you want to dispatch
45+
return "Response London"
46+
}
47+
48+
49+
// Match based on header
50+
def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Accept-Encoding")
51+
log.info "AcceptEncoding Header List: " + acceptEncodingHeaderList
52+
53+
if( acceptEncodingHeaderList.contains("gzip,deflate") )
54+
{
55+
// return the name of the response you want to dispatch
56+
return "GZiped Response"
57+
}
58+
59+
60+
// Match based on body
61+
def requestBody = mockRequest.getRequestContent()
62+
log.info "Request body: " + requestBody
63+
64+
if( requestBody.contains("some data") )
65+
{
66+
// return the name of the response you want to dispatch
67+
return "Response N"
68+
}
69+
*/
7070
</con:dispatchPath><con:response name="Success Reponse" id="c2e01668-af95-4107-a0ee-e7e3bb76f9cd" httpResponseStatus="200" mediaType="application/json"><con:settings/><con:responseContent>{
7171
"_links": {
7272
"self": {
@@ -205,56 +205,56 @@ if( requestBody.contains("some data") )
205205
return "Response N"
206206
}
207207
*/
208-
</con:dispatchPath><con:response name="Login Success Response" id="64361075-ae39-4ed8-8fbd-e837ad26e2bf" httpResponseStatus="200" mediaType="application/json"><con:settings/><con:responseContent/><con:header><con:name>location</con:name><con:value>/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c7</con:value></con:header></con:response><con:response name="Login Failed Reponse" id="30731a63-ba64-41c1-820d-fbee088e4023" httpResponseStatus="401"><con:settings/><con:responseContent/></con:response></con:restMockAction><con:restMockAction name="/api/v1/license" method="GET" resourcePath="/api/v1/license" id="777458a5-c2f1-434f-bc62-93536aec73b0"><con:settings/><con:dispatchStyle>SEQUENCE</con:dispatchStyle><con:dispatchPath>/*
209-
// Script dispatcher is used to select a response based on the incoming request.
210-
// Here are few examples showing how to match based on path, query param, header and body
211-
212-
// Match based on path
213-
def requestPath = mockRequest.getPath()
214-
log.info "Path: "+ requestPath
215-
216-
if( requestPath.contains("json") )
217-
{
218-
// return the name of the response you want to dispatch
219-
return "JSON Response"
220-
}
221-
222-
223-
// Match based on query parameter
224-
def queryString = mockRequest.getRequest().getQueryString()
225-
log.info "QueryString: " + queryString
226-
227-
if( queryString.contains("stockholm") )
228-
{
229-
// return the name of the response you want to dispatch
230-
return "Response Stockholm"
231-
}
232-
else if( queryString.contains("london") )
233-
{
234-
// return the name of the response you want to dispatch
235-
return "Response London"
236-
}
237-
238-
239-
// Match based on header
240-
def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Accept-Encoding")
241-
log.info "AcceptEncoding Header List: " + acceptEncodingHeaderList
242-
243-
if( acceptEncodingHeaderList.contains("gzip,deflate") )
244-
{
245-
// return the name of the response you want to dispatch
246-
return "GZiped Response"
247-
}
248-
249-
250-
// Match based on body
251-
def requestBody = mockRequest.getRequestContent()
252-
log.info "Request body: " + requestBody
253-
254-
if( requestBody.contains("some data") )
255-
{
256-
// return the name of the response you want to dispatch
257-
return "Response N"
258-
}
259-
*/
260-
</con:dispatchPath><con:response name="Success Response" id="99316eed-7a8f-43b6-8b94-14c737654ed9" httpResponseStatus="200"><con:settings/><con:responseContent/></con:response></con:restMockAction></con:restMockService><con:properties/><con:wssContainer/><con:oAuth2ProfileContainer/><con:oAuth1ProfileContainer/></con:soapui-project>
208+
</con:dispatchPath><con:response name="Login Success Response" id="64361075-ae39-4ed8-8fbd-e837ad26e2bf" httpResponseStatus="200" mediaType="application/json"><con:settings/><con:responseContent/><con:header><con:name>location</con:name><con:value>/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c7</con:value></con:header></con:response><con:response name="Login Failed Reponse" id="30731a63-ba64-41c1-820d-fbee088e4023" httpResponseStatus="401"><con:settings/><con:responseContent/></con:response></con:restMockAction><con:restMockAction name="/api/v2/license" method="GET" resourcePath="/api/v2/license" id="777458a5-c2f1-434f-bc62-93536aec73b0"><con:settings/><con:dispatchStyle>SEQUENCE</con:dispatchStyle><con:dispatchPath>/*
209+
// Script dispatcher is used to select a response based on the incoming request.
210+
// Here are few examples showing how to match based on path, query param, header and body
211+
212+
// Match based on path
213+
def requestPath = mockRequest.getPath()
214+
log.info "Path: "+ requestPath
215+
216+
if( requestPath.contains("json") )
217+
{
218+
// return the name of the response you want to dispatch
219+
return "JSON Response"
220+
}
221+
222+
223+
// Match based on query parameter
224+
def queryString = mockRequest.getRequest().getQueryString()
225+
log.info "QueryString: " + queryString
226+
227+
if( queryString.contains("stockholm") )
228+
{
229+
// return the name of the response you want to dispatch
230+
return "Response Stockholm"
231+
}
232+
else if( queryString.contains("london") )
233+
{
234+
// return the name of the response you want to dispatch
235+
return "Response London"
236+
}
237+
238+
239+
// Match based on header
240+
def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Accept-Encoding")
241+
log.info "AcceptEncoding Header List: " + acceptEncodingHeaderList
242+
243+
if( acceptEncodingHeaderList.contains("gzip,deflate") )
244+
{
245+
// return the name of the response you want to dispatch
246+
return "GZiped Response"
247+
}
248+
249+
250+
// Match based on body
251+
def requestBody = mockRequest.getRequestContent()
252+
log.info "Request body: " + requestBody
253+
254+
if( requestBody.contains("some data") )
255+
{
256+
// return the name of the response you want to dispatch
257+
return "Response N"
258+
}
259+
*/
260+
</con:dispatchPath><con:response name="Success Response" id="99316eed-7a8f-43b6-8b94-14c737654ed9" httpResponseStatus="200"><con:settings/><con:responseContent/></con:response></con:restMockAction></con:restMockService><con:properties/><con:wssContainer/><con:oAuth2ProfileContainer/><con:oAuth1ProfileContainer/></con:soapui-project>

0 commit comments

Comments
 (0)