Community

API Phyton on OSX broken?

Hi, We have been using Phyton scripts on OSX without any issues for some time now. But suddenly (do not know if it happened after the latest OSX security fixes) the stopped working. Example, we use this script to list and get the servers and their IPs:

from operator import attrgetter

import profitbricks_client


def main():
    client = profitbricks_client.get_profitbricks_client(api_version='1.3')
    datacenter_ids = [dc.dataCenterId for dc in client.getAllDataCenters()]
    for datacenter_id in datacenter_ids:
        datacenter = client.getDataCenter(dataCenterId=datacenter_id)
        print datacenter.dataCenterName + ':'
        servers = sorted(datacenter.servers, key=attrgetter('serverName'))
        for server in [s for s in servers if hasattr(s, 'ips')]:
            print server.serverName + '   ' + ' '.join(server.ips)
        print


if __name__ == '__main__':
    main()

and when we run it now we get a whole bunch of errors like:

profit ip.py:37: Traceback (most recent call last): main()
profit ip.py:25:  client = profitbricks_client.get_profitbricks_client(api_version='1.3')
profitbricks_client.py:829:  endpoint = get_endpoint(api_version, endpoint, config, store_endpoint)
profitbricks_client.py:691:  _retreive_support_matrix_file())
profitbricks_client.py:582:  older, newer, supported = _parse_support_matrix(support_matrix_file, client_version)
profitbricks_client.py:853: profitbricks_client.SupportMatrixMalformedException: Failed to parse https://api.profitbricks.com/support_matrix.ini. This file is malformed. Please contact support. You can work around this issue by specifying an endpoint with --endpoint.

Any ideas what happened? Thanks! Nathan

 
  • **bold**
  • _italics_
  • `code`
  • ```code block```
  • # Heading 1
  • ## Heading 2
  • > Quote
 

Hello - I am wondering if you are using an older Python Client Library that talks to the SOAP API rather than REST.

The following code should gather the IP information that you are seeking using the current Python client library. ( https://devops.profitbricks.com/libraries/python/ )

import os
from profitbricks.client import ProfitBricksService

username = os.getenv('PROFITBRICKS_USERNAME')
password = os.getenv('PROFITBRICKS_PASSWORD')

client = ProfitBricksService(username=username, password=password)

datacenters = client.list_datacenters()
print 'Number of Datacenters: {0}'.format(len(datacenters))

for dc in datacenters['items']:
    print 'Datacenter: {0}'.format(dc['properties']['name'])
    servers = client.list_servers(datacenter_id=dc['id'])
    for server in servers['items']:
        print '  Server: {0}'.format(server['properties']['name'])
        nics = client.list_nics(datacenter_id=dc['id'], server_id=server['id'])
        for nic in nics['items']:
            if len(nic['properties']['ips']):
                for ips in nic['properties']['ips']:
                    if nic['properties']['name']:
                        print '    {0}: {1}'.format(
                            nic['properties']['name'], ips)
                    else:
                        print '    NIC: {0}'.format(ips)
            else:
                print '    No IP currently assigned.'
    print