Skip to content

CP-44477 Add Typescript bindings for XenAPI #5623

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

Closed
wants to merge 2 commits into from

Conversation

acefei
Copy link
Contributor

@acefei acefei commented May 10, 2024

In this PR, I implemented the Typescript bindings for XenAPI whose usage is almost identical to the Python XenAPI, except it's asynchronous and requires async/await.

CC @Zhengchai @qinzhang22

Signed-off-by: Fei Su <fei.su@cloud.com>
Copy link
Contributor

@lindig lindig left a comment

Choose a reason for hiding this comment

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

I can't review the JS part but think this is a nice addition. The problem with the Python approach is that it is quite low level and does not provide a convenient API - but it gets you off the ground.

@psafont
Copy link
Member

psafont commented May 10, 2024

Needs feedback from the interfaces team @kc284 @danilo-delbusso

@acefei
Copy link
Contributor Author

acefei commented May 10, 2024

I can't review the JS part but think this is a nice addition. The problem with the Python approach is that it is quite low level and does not provide a convenient API - but it gets you off the ground.

I agree that the lack of an intuitive API with Python approach, particularly when the user uses it within IDEs, can't auto pop-up code completion as the methods are dynamic.

However, with the help of Python, many examples and code snippets are easily available online for developers to refer to, which will definitely speed up the development process.

@contificate
Copy link
Contributor

I agree that the lack of an intuitive API with Python approach, particularly when the user uses it within IDEs, can't auto pop-up code completion as the methods are dynamic.

I can't say I have used the Python API, but - if it is as you say - then, in principle, it could be improved with forwarding stubs generated from the JSON backend.

I did this for something else as of very recently, which features autocomplete:
2024-05-10-110003_737x218_scrot

headers: { "content-type": "application/json" },
body: JSON.stringify(request),
});
if (response.status === 200) {
Copy link
Member

Choose a reason for hiding this comment

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

we cannot rely on the response status in jsonrpc and xapi.

see for instance this failed task.get_result call. the call has failed, but we get a 200 status

> POST /jsonrpc HTTP/1.1
> Host: 10.71.144.44
> Content-Type: application/json
> User-Agent: insomnia/9.0.0
> Accept: */*
> Content-Length: 181

| {
| 	"id": 1,
| 	"method": "task.get_result",
| 	"jsonrpc": "2.0",
| 	"params": [
| 		"OpaqueRef:123",
| 		"OpaqueRef:123"
| 	]
| }

* TLSv1.2 (IN), TLS header, Supplemental data (23):
* Mark bundle as not supporting multiuse

< HTTP/1.1 200 OK
< content-length: 129
< connection: keep-alive
< cache-control: no-cache, no-store
< content-type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With


* Received 129 B chunk
* Connection #0 to host 10.71.144.44 left intact

Ideally we'd have an error type for xapi exceptions (can be a generic one), and one for HTTP errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

To add a bit to the above comment, we should check whether the response Json contains Error and if it does throw an exception containing the Message and Data, otherwise the user would have to do that for every call.

Copy link
Member

Choose a reason for hiding this comment

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

since this is the first time that you're adding this library, please also add eslint so we can keep this codebase clean :)


For more example usage, please find in tests folder.
```
$ git clone git@github.com:acefei/xen-api-ts.git
Copy link
Contributor

@kc284 kc284 May 10, 2024

Choose a reason for hiding this comment

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

To make things simpler for the users, we're trying to minimise the number of places where people can find xenserver-sdk/xen-api documentation and help. You may want to consider moving your examples (importing the whole git history if you want) to a new folder typescript within this repo https://github.com/xenserver/xenserver-samples which is also linked from the official XenServer developer documentation. Let me know and I'll add you to the maintainers list.

Copy link
Contributor

@kc284 kc284 left a comment

Choose a reason for hiding this comment

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

As above.

P.S. Thanks for adding this, it will be very useful for people developing web interfaces for XS to finally have support from the upstream project.

@acefei
Copy link
Contributor Author

acefei commented May 13, 2024

Thanks all for your comments, that is really helpful, I will update this in next OIL day.

Signed-off-by: Fei Su <fei.su@cloud.com>
@acefei acefei force-pushed the private/feis/CP-44477 branch from a8e9c8a to 4e09cf9 Compare May 27, 2024 06:33
@psafont
Copy link
Member

psafont commented Aug 5, 2024

@danilo-delbusso This is in need of a review, is that correct?

@kc284
Copy link
Contributor

kc284 commented Aug 5, 2024

If I remember well there were some of the requested changes still missing from the latest push, will need to re-check, but, yes, review is needed.

@psafont
Copy link
Member

psafont commented Aug 5, 2024

Thanks! If there have been outstanding comment for so long, then I think it's better to close it. When there's an impetus to continue with the work, it can be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants