vmware-archive / pyvcloud

Python SDK for VMware vCloud Director
https://vmware.github.io/pyvcloud
Other
170 stars 190 forks source link

Nic deletion fails after update #781

Closed dn1s closed 3 years ago

dn1s commented 3 years ago

After rebuilding an existing container we experienced the issue that it's not possible to delete nics anymore.

Code snipped we use to delete a nic:

vm_name = vm_resource.get('name')
vm      = VM(client, resource=vm_resource)
delNic  = vm.delete_nic(int(nic_index))
result  = client.get_task_monitor().wait_for_status(task=delNic)

Error message:

<Error xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas
.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" x
mlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.c
om/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1
.5" xmlns:ns9="http://www.vmware.com/vcloud/versions" majorErrorCode="400" message="[ 1ac2d842-f419-42b9-a202-e1274b9750dc ] H
TTP 400 Bad Request&#xA; - Illegal to have multiple roots (start tag in epilog?).&#xA; at [row,col {unknown-source}]: [1,1323]
" minorErrorCode="BAD_REQUEST"/>

this used to work like a charm. But after rebuilding the container it keeps on forgetting the end tag of network connection section instead it adds whole Vapp Resource to the request which fails obviously:

<NetworkConnectionSection xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" xmlns:ns9="http://www.vmware.com/vcloud/versions" href="https://vcd_url/api/vApp/vm-cb5335cd-b994-4c8b-9639-7c8a18b1737a/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml" ovf:required="false"><ovf:Info>Specifies the available VM network connections</ovf:Info><PrimaryNetworkConnectionIndex>0</PrimaryNetworkConnectionIndex><Link rel="edit" href="https://vcd_url/api/vApp/vm-cb5335cd-b994-4c8b-9639-7c8a18b1737a/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+xml"/><Link rel="edit" href="https://vcd_url/api/vApp/vm-cb5335cd-b994-4c8b-9639-7c8a18b1737a/networkConnectionSection/" type="application/vnd.vmware.vcloud.networkConnectionSection+json"/></NetworkConnectionSection><GuestCustomizationSection href="https://vcd_url/api/vApp/vm-cb5335cd-b994-4c8b-9639-7c8a18b1737a/guestCustomizationSection/" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml" ovf:required="false"><ovf:Info>Specifies Guest OS Customization Settings</ovf:Info><Enabled>false</Enabled>

shortend

Installed pip packages:

Package                Version
---------------------- ------------
appdirs                1.4.4
bcrypt                 3.2.0
CacheControl           0.12.6
certifi                2021.5.30
cffi                   1.14.6
chardet                4.0.0
ciso8601               2.2.0
colorama               0.4.4
contextlib2            0.6.0
cryptography           2.8
debtcollector          2.2.0
defusedxml             0.7.1
distlib                0.3.1
distro                 1.5.0
gitdb                  4.0.7
GitPython              3.1.18
html5lib               1.1
humanfriendly          9.2
idna                   3.1
importlib-metadata     4.6.3
infoblox-client        0.5.0
iso8601                0.1.16
jeepney                0.7.1
jira                   3.0.1
keyring                23.0.1
lockfile               0.12.2
lxml                   4.6.3
msgpack                1.0.2
netaddr                0.8.0
netifaces              0.11.0
oauthlib               3.1.1
ordered-set            4.0.2
oslo.config            8.7.1
oslo.context           3.3.0
oslo.i18n              5.0.1
oslo.log               4.6.0
oslo.serialization     4.1.0
oslo.utils             4.9.2
packaging              20.9
paramiko               2.7.2
pbr                    5.6.0
pep517                 0.9.1
pip                    21.2.2
progress               1.5
pycparser              2.20
pycryptodome           3.10.1
Pygments               2.9.0
pyinotify              0.9.6
PyNaCl                 1.4.0
pyparsing              2.4.7
python-dateutil        2.8.2
pytoml                 0.1.21
pytz                   2021.1
pyvcloud               23.0.2
PyYAML                 5.4.1
requests               2.25.1
requests-oauthlib      1.3.0
requests-toolbelt      0.9.1
retrying               1.3.3
rfc3986                1.5.0
ruamel.yaml            0.17.10
ruamel.yaml.clib       0.2.6
SecretStorage          3.3.1
setuptools             51.3.3
six                    1.16.0
smmap                  4.0.0
stevedore              3.3.0
toml                   0.10.2
unittest-xml-reporting 3.0.4
urllib3                1.26.6
vcd-api-schemas-type   10.3.0.dev72
webencodings           0.5.1
wrapt                  1.12.1
zipp                   3.5.0

Pinning versions did not help in the slightest. I don't understand why the parser would randomly break there and only in this function.

Used software: vCloud Director version: 9.7.0.14534864 python3.8

dn1s commented 3 years ago

Dockerfile:

FROM alpine:latest

WORKDIR /app

RUN apk add --no-cache python3
RUN apk add --no-cache gcc
RUN apk add --no-cache openssh-client
RUN apk add --no-cache git
RUN apk add --no-cache python3-dev
RUN apk add --no-cache musl-dev
RUN apk add --no-cache openssl-dev
RUN apk add --no-cache libffi-dev
RUN apk add --no-cache make
RUN apk add --no-cache libxml2-dev
RUN apk add --no-cache libxslt-dev
RUN apk add --no-cache libxslt
RUN apk add --no-cache libffi
RUN apk add --no-cache libxml2
RUN apk add --no-cache py3-pip
RUN apk add --no-cache cargo

RUN pip3 install --upgrade pip

RUN pip3 install pyvcloud
RUN pip3 install ciso8601
RUN pip3 install GitPython
RUN pip3 install infoblox-client
RUN pip3 install jira
RUN pip3 install paramiko
RUN pip3 install ruamel.yaml
RUN pip3 install PyCryptodome

# Clean up some unneeded packages
RUN apk del --no-cache cargo
RUN apk del --no-cache gcc
RUN apk del --no-cache python3-dev
RUN apk del --no-cache musl-dev
RUN apk del --no-cache openssl-dev
RUN apk del --no-cache make
RUN apk del --no-cache libxslt-dev
RUN apk del --no-cache libxml2-dev

# mkdir tmp && cp -av ../../python_helper_modules/*{py,json} tmp/
COPY *py ./
COPY tmp/*py ./modules/
COPY tmp/*json ./modules/

ENV PATH="/app:${PATH}"

ADD ./bash_aliases /app/bash_aliases

# This will create a ssh agent inside container
# necessary to manage puppet ENC repo
ENTRYPOINT ssh-agent > env ; source env ; rm env ; /bin/ash -l
dn1s commented 3 years ago

Fix was to update to python 3.9.5 from alpine 3.14 repo.