# a10sdk-python - Adding members to a Service Group

**URL:** <https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434>\
**Category:** System\
**Tags:** a10sdk, python\
**Created:** [March 10, 2017, 8:00am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434 "2017-03-10T08:00:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 10, 2017, 8:00am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/1 "2017-03-10T08:00:10Z")

</div>

Hello, I’m trying to add members to a Service Group using the [a10sdk-python](https://github.com/a10networks/a10sdk-python) modules but can’t get it to work. Here’s my code:

```auto
from a10sdk.core.slb.slb_server import Server
from a10sdk.core.slb.slb_server_port import Port
from a10sdk.core.slb.slb_service_group_member import Member

def add_servers(k8s_env,new_servers,new_ips,a10_session):
    server_tuples = [server for server in zip(new_servers,new_ips)]
    for server in server_tuples:
        real_server = Server(name=server[0], host=server[1], DeviceProxy=a10_session)
        health_check = "www-" + k8s_env + "-thesting"
        service_group = "www-" + k8s_env + "-thesting"
        real_port = Port(port_number="80", protocol="tcp", health_check=health_check, DeviceProxy=a10_session)
        service_group_member = Member(name=server[0], port=80, DeviceProxy=a10_session)
        real_server.create()
        real_port.create(name=server[0])
        service_group_member.create(name=service_group)

```

Creating new Real Servers and Real Ports is no problem but I just don’t manage to add this newly created Real Server to an existing Service Group. So if anyone has any pointers or clues I’d be happy to hear! Thanks in advance! Best, Jeremy

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 11, 2017, 10:31am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/2 "2017-03-11T10:31:22Z")

</div>

Hi Jeremy,

I do have examples for AXAPI3.0 which works with ACOS 4.0.0 onwards, are you using that version or ACOS 2.7.0 onwards which uses AXAPI 2.0?

will help you more once i know.

Best Regards,

Eddie Bellamy A10 SE UK

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 11, 2017, 1:56pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/3 "2017-03-11T13:56:24Z")

</div>

Hello Eddie,

Thanks for the quick reply! I’m using aXAPIv3 with ACOS 4.1.0-P5.

Best,

Jeremy

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 13, 2017, 1:50pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/4 "2017-03-13T13:50:54Z")

</div>

Hi Jeremy,

been checking your A10 SDK which is using URLLIB, my examples are using HTTPLIB within python, please can you send me the error you are getting so we can take a closer look.

please inform me if you want to see my working example using HTTPLIB.

best regards,

Eddie

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 13, 2017, 4:01pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/5 "2017-03-13T16:01:50Z")

</div>

Hi Jeremy,

I have ran your scripts and all is OK, my layout for the zip file was new\_servers and new\_ips, new\_servers were constructed s1, s2, s3 and new\_ips ‘192.168.10.10’, ‘192.168.10.11’, ‘192.168.10.12’  
what I don’t know is your zip file name structure, but calling my 2 lists together into a zip file worked like your script above.

hope this helps.

best Regards,

Eddie

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 13, 2017, 4:17pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/6 "2017-03-13T16:17:19Z")

</div>

Hello Eddie,

I’d like to stick with the a10sdk-python modules as those are part of the official A10 Python SDK. And adding real servers and real ports works indeed, it’s adding existing real servers to a service group that I can’t get to work ☹  
And I’m not sure what you mean by zip file name structure, I use zip() to create a list of tuples with the server name and the server IP.

Best,

Jeremy

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 13, 2017, 10:28pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/7 "2017-03-13T22:28:02Z")

</div>

HI Jeremy,

I will take a look tomorrow.

yes i did mean zip()  
BR

Eddie

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 14, 2017, 8:55am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/8 "2017-03-14T08:55:05Z")

</div>

Hello Eddie,

Thanks for your help. In the meanwhile I’ll keep debugging too. If I find something interesting I will post it here.

Best,

Jeremy

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 14, 2017, 10:38am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/9 "2017-03-14T10:38:26Z")

</div>

Hi Jeremy.

My colleague John has also been looking at this.

your config works 100% as long as you have pre-created Service-Group and Health Monitor.  
once your initial config creates the new Servers with names, all to port 80, they can be added to an existing Service group.

if you are still having issues, then it would be worth going to [support@a10networks.com](mailto:support@a10networks.com)

best regards,

Eddie

---

<div class="post-metadata">

**Author:** ![ebellamy\_a10networks.com](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@ebellamy\_a10networks.com](https://community.a10networks.com/u/ebellamy_a10networks.com)\
**Post date:** [March 14, 2017, 10:39am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/10 "2017-03-14T10:39:54Z")

</div>

HI Jeremy,

one extra note, not sure if you have tried this, you can use the command “show audit” to check how the API is getting implemented on the A10 Appliance.

best regards,

Eddie

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 17, 2017, 8:40am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/11 "2017-03-17T08:40:49Z")

</div>

Hello Eddie,

Thanks for the pointers to help debugging the issue. Haven’t had the time to dive into this again. Whenever I have new info I’ll let you know.

Jeremy

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 25, 2017, 9:43am UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/12 "2017-03-25T09:43:48Z")

</div>

Hello Eddie, `show audit` showed me this: `Mar 24 2017 17:05:56 [someapiuser] axapi: [1490375156997751] POST: /axapi/v3/slb/service-group/name-servicegroup/member/name-servicegroup` That won’t work of course, the `{name}` template entry is used for both the service group and the server name. So I worked around this by explicitly setting the `a10_url` variable:

```auto
def add_servers(k8s_env,new_servers,new_ips,a10_session):
    server_tuples = [server for server in zip(new_servers,new_ips)]
    for server in server_tuples:
        real_server = Server(name=server[0], host=server[1], DeviceProxy=a10_session)
        health_check = "www-" + k8s_env + "-thesting"
        service_group = "www-" + k8s_env + "-thesting"
        a10_url = "/axapi/v3/slb/service-group/" + service_group + "/member/{name}+{port}"
        real_port = Port(port_number="80", protocol="tcp", health_check=health_check, DeviceProxy=a10_session)
        service_group_member = Member(name=server[0], port=80, a10_url=a10_url, DeviceProxy=a10_session)
        real_server.create()
        real_port.create(name=server[0])
        service_group_member.create()

```

And then my servers get added to service group successfully. So thanks for the `show audit` tip! And this topic can be marked as solved. Best, Jeremy

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/a10_community/original/1X/bb9f186d33804d3044a0374e589f49fdf3be1328.png) [@system](https://community.a10networks.com/u/system)\
**Post date:** [March 25, 2017, 7:53pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/13 "2017-03-25T19:53:20Z")

</div>

Hey Jeremy,

Thank you! You are correct. I’ve been trying to figure out how to remove a server from a service-group for almost 2 weeks. The way the class is built, I think it’s impossible to use it for this purpose w/o modifying the url as you’ve shown me here. I didn’t think to update the a10\_url, so thank you very much. I can now add and remove servers from a service-group.

service\_group = “WEBSRVRS”

```auto
a10\_url = "/axapi/v3/slb/service-group/" \+ service\_group \+ "/member/\{name\}\+\{port\}"
service\_group\_member = Member(name="MINT20", port=ServicePort, a10\_url=a10\_url, DeviceProxy=dp)
service\_group\_member.delete(name="MINT20",port=ServicePort)

```

---

<div class="post-metadata">

**Author:** ![autostatic](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@autostatic](https://community.a10networks.com/u/autostatic)\
**Post date:** [March 27, 2017, 1:53pm UTC](https://community.a10networks.com/t/a10sdk-python-adding-members-to-a-service-group/434/14 "2017-03-27T13:53:20Z")

</div>

Hello @tjones, so I wasn’t the only one trying to figure out how to get this to work. Glad to hear my post was helpful!
