Skip to content

Conversation

@nmaludy
Copy link
Contributor

@nmaludy nmaludy commented Jun 30, 2017

Fix for #2

This parses the custom digitalocean objects and converts them into dicts and lists so StackStorm can understand them.

@nmaludy
Copy link
Contributor Author

nmaludy commented Jun 30, 2017

Before This Fix

[root@stackstorm ~]# st2 run digitalocean.get_all_droplets
.
id: 5955c366a814c00bdd89a618
status: succeeded
parameters: None
result: 
  exit_code: 0
  result: None
  stderr: ''
  stdout: ''

After This Fix

[root@stackstorm st2]# st2 run digitalocean.get_all_droplets
.
id: 5955cc86a814c00bdd89a63c
status: succeeded
parameters: None
result: 
  exit_code: 0
  result:
  - action_ids: []
    backup_ids: []
    backups: false
    created_at: '2017-04-18T20:11:18Z'
    disk: 20
    end_point: https://api.digitalocean.com/v2/
    features: []
    id: 12345
    image:
      created_at: '2017-03-03T16:10:57Z'
      distribution: Ubuntu
      id: 1234
      min_disk_size: 20
      name: LAMP on 14.04
      public: true
      regions:
      - nyc1
      - sfo1
      - nyc2
      - ams2
      - sgp1
      - lon1
      - nyc3
      - ams3
      - fra1
      - tor1
      - sfo2
      - blr1
      size_gigabytes: 0.5
      slug: lamp
      type: snapshot
    ip_address: x.x.x.x
    ip_v6_address: null
    ipv6: false
    kernel: null
    locked: false
    memory: 512
    monitoring: null
    name: sendy
    networks:
      v4:
      - gateway: x.x.x.x
        ip_address: x.x.x.x
        netmask: 255.255.255.0
        type: public
      v6: []
    next_backup_window: null
    private_ip_address: null
    private_networking: false
    region:
      available: true
      features:
      - private_networking
      - backups
      - ipv6
      - metadata
      - install_agent
      name: New York 2
      sizes:
      - 512mb
      - 1gb
      - 2gb
      - 4gb
      - 8gb
      - 16gb
      - 32gb
      - 48gb
      - 64gb
      slug: nyc2
    size:
      available: true
      disk: 20
      memory: 512
      price_hourly: 0.00744
      price_monthly: 5.0
      regions:
      - ams2
      - ams3
      - blr1
      - fra1
      - lon1
      - nyc1
      - nyc2
      - nyc3
      - sfo1
      - sfo2
      - sgp1
      - tor1
      slug: 512mb
      transfer: 1.0
      vcpus: 1
    size_slug: 512mb
    snapshot_ids: []
    ssh_keys: []
    status: active
    tags:
    - emailer
    - spamtester
    token: ******
    user_data: null
    vcpus: 1
    volume_ids: []
    volumes: []
  stderr: ''
  stdout: ''

@Kami
Copy link
Contributor

Kami commented Jun 30, 2017

LGTM,

But some test cases for function which converts those custom objects would be nice :)

# The results received from the digitalocean module are
# custom python objects that StackStorm doesn't recognize.
# The following code converts them into dicts & lists
json_str = json.dumps(digitalocean_results, default=digitalocean_obj_to_dict)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would also throw if an object contains an attribute which is datetime class instance or instance of another class which is not JSON serializable, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's correct.

Any other thoughts or idiomatic ways of converting custom python objects into dicts/lists?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing simple I can think of.

This should work for now, as long as the class doesn't contain attributes which are not JSON serializable.

Otherwise the best way would probably be to manually build up the dict and exclude those attributes (we already do this in some other places like aws pack, etc.).

@nmaludy
Copy link
Contributor Author

nmaludy commented Jul 13, 2017

@Kami I took some time and wrote unit tests for the functionality i added. When doing this i noticed there were no unit tests at all for this pack so i went ahead and did a first pass at some tests. Unfortunately i'm not too familiar with this pack or with Digital Ocean so any comments/suggestions are appreciated.

@Kami
Copy link
Contributor

Kami commented Jul 17, 2017

Great, thanks for working on the tests - will have a look shortly :)

@@ -0,0 +1,3 @@
## Pack Contributors
* st2dev info@stackstorm.com
* Encore Technologies code@encore.tech
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also add this to contributors field (array) in pack.yaml :)

@Kami Kami merged commit 154f3c6 into StackStorm-Exchange:master Jul 17, 2017
@Kami
Copy link
Contributor

Kami commented Jul 17, 2017

Merged - thanks.

Will also add you as a contributor to this repo :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants