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

Include complete data in to_dict() methods #111

Open
aqiank opened this issue May 12, 2021 · 9 comments
Open

Include complete data in to_dict() methods #111

aqiank opened this issue May 12, 2021 · 9 comments

Comments

@aqiank
Copy link

aqiank commented May 12, 2021

Hi, I couldn't seem to find the Python API for getting storage details which is documented here. Did I overlook it or is it simply not implemented yet?

@ajmyyra
Copy link
Member

ajmyyra commented May 17, 2021

Hi there! The functionality is available through the CloudManager with manager.get_storage(storage.uuid). There are some other storage examples here. Before using, CloudManager needs be be initialized and there are examples for in in the main Readme.

Could you try this out? Happy to help if you run into any problems with it.

@aqiank
Copy link
Author

aqiank commented May 17, 2021

Hi @ajmyyra, when I use manager.get_storage(storage.uuid).to_dict(), it returns this:

{
    "tier": "maxiops",
    "title": "xxx",
    "size": 16,
    "zone": "xxx"
}

But when I use the documented API via requests, it returns this:

{
    "storage": {
        "access": "private",
        "backup_rule": {},
        "backups": {
            "backup": []
        },
        "license": 0,
        "servers": {
            "server": [
                "xxx"
            ]
        },
        "size": 16,
        "state": "online",
        "tier": "maxiops",
        "title": "xxx",
        "type": "normal",
        "uuid": "xxx",
        "zone": "xxx"
    }
}

So it seems like they are not equivalent?

@ajmyyra
Copy link
Member

ajmyyra commented May 17, 2021

Hi,

As Storage is an object, getting a dict out of it is not that straightforward. Using it on its own should give you a lot more details:

>>> import upcloud_api
>>> manager = upcloud_api.CloudManager('username', 'password')
>>> storage = manager.get_storage('STORAGE_UUID')
>>> vars(storage)
{'uuid': 'STORAGE_UUID', 'title': 'Storage title', 'size': 50, 'cloud_manager': <upcloud_api.cloud_manager.CloudManager object at 0x7fc1902adbe0>, 'access': 'private', 'backup_rule': {}, 'backups': {'backup': []}, 'license': 0, 'part_of_plan': 'yes', 'servers': {'server': ['SERVER_ID']}, 'state': 'online', 'tier': 'maxiops', 'type': 'normal', 'zone': 'ZONE'}

@aqiank
Copy link
Author

aqiank commented May 17, 2021

Hmm is there a reason that those other fields are left out of the to_dict() output?

@ajmyyra
Copy link
Member

ajmyyra commented May 18, 2021

Currently to_dict() function in storage objects is used for creating a JSON object that includes the relevant items for the storage objects in the UpCloud server API. If you want your object as a dictionary, can't you just create it from the object with .__dict__? So for example:

>>> import upcloud_api
>>> manager = upcloud_api.CloudManager('username', 'password')
>>> stor = manager.get_storage('STORAGE_UUID')
>>> dictified_storage = stor.__dict__
>>> type(dictified_storage)
<class 'dict'>

@aqiank
Copy link
Author

aqiank commented May 18, 2021

Yes, I could but it seems like it's not very intuitive to have to do that when there's a method called to_dict() which seems like it should do the same thing. This information is also not documented anywhere in the documentation. Might be just me being non-Python expert though.

@ajmyyra
Copy link
Member

ajmyyra commented May 18, 2021

Yup, it's hard to disagree with you on this. The only excuse is that it's not documented as it's meant as an internal function. We should change it to work as you would expect but as this would be a breaking change, we'll need to wait for the next larger release to do it. Could you create a separate issue for this change (and adding similar to_dict() functionality to other objects as well) or modify the title of this one, so we can track this change better?

@aqiank aqiank changed the title Missing function for getting storage details Include complete data in to_dict() methods May 19, 2021
@aqiank
Copy link
Author

aqiank commented May 19, 2021

Sure, I've renamed the title. Let me know if it's a suitable title and thanks!

@ajmyyra
Copy link
Member

ajmyyra commented May 19, 2021

It is, thank you! Hopefully we can get back to this in the near future.

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

No branches or pull requests

3 participants