[OpenStack-fr] requete sur l'API openstack en python
Tristan Le Toullec
tristan.letoullec at cnrs.fr
Mer 7 Oct 08:10:24 UTC 2020
Bonjour Guillaume,
tu souhaites donc caster ton objet de type SecurityGroup vers un
dictionnaire python.
Tu dois pouvoir utiliser quelque chose comme cela (attention, non testé) :
liste = []
for i in results:
liste.append(vars(i))
Ou bien sa forme contracté :
liste = [ vars(i) for i in results ]
Bonne journée,
Tristan
Le 06/10/2020 à 17:38, COMTE Guillaume a écrit :
>
> Bonjour à tous,
>
> Je me connect à l’API comme ceci :
>
> client = connection.Connection(
>
> project_id=creddict["project_id"],
>
> cloud=creddict[“cloud”],
>
> region=creddict["region"],
>
> ak=creddict["access_key"],
>
> sk=creddict["secret_key"]
>
> )
>
> Ensuite je fait un call à :
>
> Result = client.network.security_groups()
>
> Et la structure que je reçois est un générateur dont chaque éléments
> de ce type :
>
> For i in Result :
>
> Print(Result)
>
> L’affichage est le suivant :
>
> openstack.network.v2.security_group.SecurityGroup(id=XXX,
> name=SG_TEST, description=created on 2019/06/03 13:08:37.195 +0000,
> tenant_id=YYYY, security_group_rules=[{'id': ZZZZ’, 'direction':
> 'ingress', 'protocol': 'tcp', 'ethertype': 'IPv4', 'description': '',
> 'remote_group_id': None, 'remote_ip_prefix': '0.0.0.0/0', 'tenant_id':
> 'TTTTT', 'port_range_max': 666, 'port_range_min': 666,
> 'security_group_id': GGGG', 'remote_address_group_id': None}, {'id':
> FFFFF', 'direction': 'egress', 'protocol': None, 'ethertype': 'IPv6',
> 'description': None, 'remote_group_id': None, 'remote_ip_prefix':
> None, 'tenant_id': 'AAAA', 'port_range_max': None, 'port_range_min':
> None, 'security_group_id': CCCCC', 'remote_address_group_id': None},
> {'id': ‘SSSSS', 'direction': 'egress', 'protocol': None, 'ethertype':
> 'IPv4', 'description': None, 'remote_group_id': None,
> 'remote_ip_prefix': None, 'tenant_id': 'LLLLL', 'port_range_max':
> None, 'port_range_min': None, 'security_group_id': ‘FFFFFF’,
> 'remote_address_group_id': None}], created_at=2019-06-03T13:08:38,
> updated_at=2019-06-03T13:08:38)
>
> Si je veux l’une des informations que je vois dans ce print, je suis
> « obligé » de fait le call par exemple : Result.description pour
> obtenir la description.
>
> Je voudrais en fait récupérer tout ce qu’il se trouve entre les
> parenthèses afin d’alimenter une liste.
>
> J’arrive pas à voir quelle astuce python me permettrait de faire ça,
> ni si j’utilise la bonne classe afin d’obtenir sous forme de liste les
> informations que je vois que je touche du doigt mais qui se trouve
> entre les parenthèses de openstack.network.v2.security_group.SecurityGroup
>
> Merci d’avance,
>
> /Cordialement / Best Regards, /
>
>
> Guillaume COMTE
>
> 3DEXPERIENCEforAll
>
>
>
> Office: +33 1 6162 5251
> guillaume.comte at 3ds.com <mailto:Guillaume.COMTE at 3ds.com>
>
>
>
>
> 3DS Logo
>
>
>
> *3DS.COM* <http://www.3ds.com>
>
>
> /Dassault Systèmes SE/| /10, Rue Marcel Dassault, Paris Campus/ |
> /78140 Vélizy-Villacoublay/ | /France/
>
> /Cordialement / Best Regards, /
>
>
> Guillaume COMTE
>
> 3DEXPERIENCEforAll
>
>
>
> Office: +33 1 6162 5251
> guillaume.comte at 3ds.com <mailto:Guillaume.COMTE at 3ds.com>
>
>
>
>
> 3DS Logo
>
>
>
> *3DS.COM* <http://www.3ds.com>
>
>
> /Dassault Systèmes SE/| /10, Rue Marcel Dassault, Paris Campus/ |
> /78140 Vélizy-Villacoublay/ | /France/
>
> This email and any attachments are intended solely for the use of the
> individual or entity to whom it is addressed and may be confidential
> and/or privileged.
>
> If you are not one of the named recipients or have received this email
> in error,
>
> (i) you should not read, disclose, or copy it,
>
> (ii) please notify sender of your receipt by reply email and delete
> this email and all attachments,
>
> (iii) Dassault Systèmes does not accept or assume any liability or
> responsibility for any use of or reliance on this email.
>
>
> Please be informed that your personal data are processed according to
> our data privacy policy as described on our website. Should you have
> any questions related to personal data protection, please contact 3DS
> Data Protection Officer at 3DS.compliance-privacy at 3ds.com
> <mailto:3DS.compliance-privacy at 3ds.com>
>
>
> For other languages, go to https://www.3ds.com/terms/email-disclaimer
>
>
> _______________________________________________
> OpenStack-fr mailing list
> OpenStack-fr at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-fr
-------------- section suivante --------------
Une pièce jointe HTML a été nettoyée...
URL: <http://lists.openstack.org/pipermail/openstack-fr/attachments/20201007/83a53333/attachment-0001.html>
-------------- section suivante --------------
Une pièce jointe autre que texte a été nettoyée...
Nom: image001.jpg
Type: image/jpeg
Taille: 949 octets
Desc: non disponible
URL: <http://lists.openstack.org/pipermail/openstack-fr/attachments/20201007/83a53333/attachment-0002.jpg>
-------------- section suivante --------------
Une pièce jointe autre que texte a été nettoyée...
Nom: image002.png
Type: image/png
Taille: 7915 octets
Desc: non disponible
URL: <http://lists.openstack.org/pipermail/openstack-fr/attachments/20201007/83a53333/attachment-0001.png>
-------------- section suivante --------------
Une pièce jointe autre que texte a été nettoyée...
Nom: image003.jpg
Type: image/jpeg
Taille: 954 octets
Desc: non disponible
URL: <http://lists.openstack.org/pipermail/openstack-fr/attachments/20201007/83a53333/attachment-0003.jpg>
-------------- section suivante --------------
Une pièce jointe autre que texte a été nettoyée...
Nom: tristan_letoullec.vcf
Type: text/x-vcard
Taille: 222 octets
Desc: non disponible
URL: <http://lists.openstack.org/pipermail/openstack-fr/attachments/20201007/83a53333/attachment-0001.vcf>
Plus d'informations sur la liste de diffusion OpenStack-fr