exoscale / cs

A simple, yet powerful CloudStack API client for python and the command-line.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

security group with internal sg as source

sebgoa opened this issue · comments

Hey folks,

what's the syntax with cs if we want to create a sg rule where a security group is the source.
I know we can do it through your UI but never quite got it from the API.

thx

The syntax is a bit weird but you can use the HTTP parameters cloudstack accepts directly. This does the trick:

$ authorizeSecurityGroupIngress protocol=TCP securityGroupName=default \
    usersecuritygrouplist[0].account=your account \
    usersecuritygrouplist[0].group=other \
    startport=22 endport=22

thanks got it.

Reopening this :) For security group this works fine and in python I go for example:

                cs.authorizeSecurityGroupIngress(securitygroupname=sg_name,
                                                 protocol=protocol,
                                                 startport=s_port,
                                                 endport=e_port,
                                                 icmpcode = icmpcode,
                                                 icmptype = icmptype,
                                                 cidrlist = cidr,
                                                 usersecuritygrouplist = [{'account':account,'group':name}]
                                                )

but for tags it fails, it seems I cannot pass a list of dict to the tags arg like:

taglist=[{'key':tag[1],'value':tag[2]}]
cs.createTags(resourcetype=resourcetype, resourceids=resourceids, tags=taglist)

and if I try to do something like:

taglist=[{'key':tag[1],'value':tag[2]}]
cs.createTags(resourcetype=resourcetype, resourceids=resourceids, tags0.key=tag[1], tags0.value=tag[2])

it fails too as this is not permitted by python

The first example is correct: a list of dicts is the expected way. What error are you getting?

for security group it works fine, but to create Tags, it fails. I have a method like this:

resourcetype = 'UserVM'
resourceids = _getvmidfromname(cs, tag[0])
taglist=[{'key':tag[1],'value':tag[2]}]
print type(taglist)
cs.createTags(resourcetype=resourcetype, resourceids=resourceids, tags=taglist)

The error is:

Traceback (most recent call last):
  File "./infra.py", line 215, in <module>
    sys.exit(main())
  File "./infra.py", line 212, in main
    if results.tag is not None: tagmachine(cs, results.tag)
  File "./infra.py", line 177, in tagmachine
    cs.createTags(resourcetype=resourcetype, resourceids=resourceids, tags=taglist)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-    packages/cs.py", line 103, in handler
    return self._request(command, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cs.py", line 116, in _request
    kwargs = transform(kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cs.py", line 79, in transform
    raise ValueError(type(value))
ValueError: <type 'dict'>

I am guessing it's a cloudstack thing...

What's the content of the resourceids variable? One of the kwargs to createTags() is a dict, and it looks like resourceids is the only candidate (resourcetype is a str, tags a list). resourceids needs to be a list.

My bad, that was the error indeed :) I got focused on this map thing...