Skip to content

Include complete data in to_dict() methods #111

Open

Description

@aqiank

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?

Activity

  1. ajmyyra commented on May 17, 2021

    @ajmyyra
    Contributor

    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.

  2. aqiank commented on May 17, 2021

    @aqiank
    Author

    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?

  3. ajmyyra commented on May 17, 2021

    @ajmyyra
    Contributor

    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'}
    
  4. aqiank commented on May 17, 2021

    @aqiank
    Author

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

  5. ajmyyra commented on May 18, 2021

    @ajmyyra
    Contributor

    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'>
    
  6. aqiank commented on May 18, 2021

    @aqiank
    Author

    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.

  7. ajmyyra commented on May 18, 2021

    @ajmyyra
    Contributor

    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?

  8. changed the title [-]Missing function for getting storage details[/-] [+]Include complete data in to_dict() methods[/+] on May 19, 2021
  9. aqiank commented on May 19, 2021

    @aqiank
    Author

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

  10. ajmyyra commented on May 19, 2021

    @ajmyyra
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions