Learning to write reusable libraries

We need to write simple scripts to manipulate the configuration of our load balancers (i.e. merge nodes from pools, enable or disable traffic rules). The load balancer has a SOAP API (defined through a bunch of WSDL files) that is very comprehensive, but using it is quite low level, with a lot of manual error checking and list manipulation. It does not tend to create reusable, reliable code.

I would like to write a Python library to handle interactions with the SOAP interface, but I don't know where to start; all my coding experience is writing one-time monolithic programs for specific tasks. This is normal for small jobs, but it does not help me or my colleagues - every time we invent a wheel with a different number of spokes: ~)

The API already provides methods such as getPoolNames () and getDrainingNodes (), but they are a bit inconvenient to use. Most of them take a list of nodes and return another list, so (say), the development of which includes virtual servers, includes such things:

names = conn.getVirtualServerNames()
enabled = conn.getEnabled(names)
for i in range(0, len(names)):
    if (enabled[i]):
        print names[i]
conn.setEnabled(['www.example.com'], [0])

While something like this:

lb = LoadBalancer('hostname')
for name in [vs.name for vs in lb.virtualServers() if vs.isEnabled()]:
    print name
www = lb.virtualServer('www.example.com').disable()

more Pythonic and (IMHO) easier.

, : , 20- WSDL ( SOAPpy/suds ?) API .

( ), - , . , (, ), , . ? "" ?

+3
3

" , "

, . . . .

" , : , 20- WSDL ( SOAPpy/suds ?) API ."

  • , . . , , API.

  • 20- WSDL? -. . API - - , . WSDL , . One, Ten, Twenty API. , . .

  • ? . , . , , .

API , , . ( ), .

.

. - , . .

" , , - ?" , . .

API - , () , , () , .

+4

presentation API (, , ). . IIRC Java, .

+1

++, " ++".

In this book you will find instructions on creating a library by introducing a “physical” and “logical” design. For example, you will learn to align the hierarchy of your components, limit the dependence between components, and create levels of abstraction.

This is actually an IMHO software development book.

0
source

Source: https://habr.com/ru/post/1719262/


All Articles