Giter Club home page Giter Club logo

Comments (2)

fgbulsoni avatar fgbulsoni commented on August 16, 2024

Issue here seems to be that server_profile['osDeploymentSettings']['osCustomAttributes'] is a list of dicts, so its indexes would actually be numbers.

In the case presented:

profile_to_update['osDeploymentSettings']['osCustomAttributes'] = dict(name='key2',value='new2')
profile_updated = oneview_client.server_profiles.update(resource=profile_to_update, id_or_uri=profile_to_update['uri'])

This first line is actively rewriting all the contents of profile_to_update['osDeploymentSettings']['osCustomAttributes'] to match the new value of dict(name='key2',value='new2').

Changing only the second value could be achieved by pointing to the specific position we want changed, 1 in this case, since lists start at 0:

profile_to_update['osDeploymentSettings']['osCustomAttributes'][1] = dict(name='key2',value='new2')

A worse case is when we aren't sure which position we actually want to change, just the value of the key.

In that case, one option is to iterate through each item of the list and if the key matches what we want, we alter the value referenced by that key:

>>> my_list
[{'name': 'key1', 'value': 'value1'}, {'name': 'key2', 'value': 'value2'}, {'name': 'key3', 'value': 'value3'}]
>>> for i in my_list:
...     if i['name'] is 'key2':
...             i['value'] = 'new_value'
...
>>> my_list
[{'name': 'key1', 'value': 'value1'}, {'name': 'key2', 'value': 'new_value'}, {'name': 'key3', 'value': 'value3'}]

So, for now "updating select custom attributes" can be achieved in relatively straightforward ways. Not entirely sure how much benefit a helper method would bring.

@kmullican, let me know your thoughts on this after these solutions.

from python-hponeview.

fgbulsoni avatar fgbulsoni commented on August 16, 2024

This feature request has been idle for a while and it appears to be resolved by this comment, so I'm closing it down.

If the solution provided does not satisfy your needs, this issue should be reopened or referenced through a new issue.

from python-hponeview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.