pycloudsigma icon indicating copy to clipboard operation
pycloudsigma copied to clipboard

Allow credentials and datacenter to be overridden in code

Open vpetersson opened this issue 11 years ago • 1 comments

Having the credentials stored in a config file makes sense for most situations. However, if working with multiple DCs, it would be handy if one would be able to override these settings in code.

This is already possible to some extent, but if one were to provide this data, the library should not complain about the config file being missing.

vpetersson avatar Feb 25 '14 22:02 vpetersson

I agree with vpetersson. Meanwhile here's a workaround: http://blog.sourcepole.ch/2016/11/22/manually-initializing-the-pycloudsigma-module/

Nota bene, the presented workaround only works because no other parts of the code are accessing any config settings during module import.

In case that some parts of the code would access config parameters during import, then this workaround would cease to work and the parts that access the config parameters would need to be rerun (or reinstantiated respectively).

However seeing that this nice module hasn't seen any updates in two years (which is a pity - it could need more extensive documentation), the prospect of the workaround failing in the future does not seem to be so threatening... ;-)

(Thanks to the authors for the useful module!)

tpo avatar Nov 22 '16 13:11 tpo

An example to override the credentials

from cloudsigma.resource import Server


location1_credentials = dict(
    api_endpoint="https://zrh.cloudsigma.com/api/2.0/",
    username="[email protected]",
    password="******")

location2_credentials = dict(
    api_endpoint="https://gva.cloudsigma.com/api/2.0/",
    username="[email protected]",
    password="******")

location1_client = Server(**location1_credentials)
print("ZRH Servers")
print(len(location1_client.list()))

location2_client = Server(**location2_credentials)
print("GVA Servers")
print(len(location2_client.list()))

jjlopez avatar Aug 13 '24 01:08 jjlopez