[strongSwan] VICI python egg

Martin Willi martin at strongswan.org
Wed Apr 15 09:50:50 CEST 2015

Hi Noel,

> >>> foo=collections.OrderedDict(strongswan.list_sas())

> ValueError: need more than 1 value to unpack

list_sas() returns a generator over SA dictionaries, an iterable over a
list. Creating a dictionary from that does not make much sense, as there
in no key for the value. Instead, you could try:

> foo=list(strongswan.list_sas())
> for item in foo:
>   print item

But the good thing about the generator is that you don't have to hold
the whole list in memory, but process it directly:

> for item in strongswan.list_sas():
>   print item

> >>> bar.next()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> StopIteration

> >>> bar=strongswan.list_sas()
> >>> bar.next()
> vici.exception.SessionException: Unexpected response type 1, expected '5' (EVENT_CONFIRM)

Usually you don't want to iterate the generator by hand using next(),
but use for loops or other constructs working with iterable. If you do,
make sure to close() the generator after you are done to terminate the
underlying vici stream request. This is most likely a result from
incomplete iteration. You may have only one generator alive for a single
vici connection, as objects get streamed on demand over the socket.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <http://lists.strongswan.org/pipermail/users/attachments/20150415/5fe72bda/attachment.pgp>

More information about the Users mailing list