Comments (19)
There is a bug in the sample code. Working on a fix now.
from vsphere-automation-sdk-python.
Actually I can't reproduce this. This is my test run:
(py36) het-m03:vsphere-automation-sdk-python het$ python samples/vsphere/contentlibrary/vmtemplate/create_vm_template.py --server x.x.x.x --username [email protected] --password Admin!23 --datacentername Sample_DC_2 --resourcepoolname rp --datastorename "local-0 (1)" --vmname Sample_Basic_VM_for_Simple_Testbed -v
server: x.x.x.x
Found VM 'Sample_Basic_VM_for_Simple_Testbed' (vm-78)
Selecting ResourcePool 'resgroup-80'
Datastore MoId: datastore-67
Local library created, ID: 363f3e91-0573-4cef-82f8-a070bb6540f5
.....
Have you pull the latest changes and installed the new binding yet?
https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages
from vsphere-automation-sdk-python.
Yes i have pulled the latest code and installed the required packages but still getting this error i have actually modified code to use cluster instead of resource pool is this code not supported for cluster?
Found VM 'isp-7934' (vm-1801)
Detected cluster '7934' as domain-c1789
Datastore MoId: datastore-1795
Local library created, ID: 4f687373-4935-45e8-8e07-060a7e45aa8c
Traceback (most recent call last):
File "/autosrc/sanjay/vsphere-automation-sdk-python/samples/vsphere/common/sample_base.py", line 79, in run
attr() # calling the method
File "samples/vsphere/contentlibrary/vmtemplate/create_vm_template.py", line 125, in _execute
self.item_id = self.client.vmtx_service.create(create_spec)
File "/usr/local/lib/python3.5/dist-packages/com/vmware/vcenter/vm_template_client.py", line 2080, in create
'spec': spec,
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 317, in _invoke
return self._api_interface.native_invoke(ctx, _method_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 275, in native_invoke
self._rest_converter_mode)
com.vmware.vapi.std.errors_client.OperationNotFound: {data : None, messages : [LocalizableMessage(id='vapi.method.input.invalid.interface', default_message="Cannot find service 'com.vmware.vcenter.vm_template.library_items'.", args=['com.vmware.vcenter.vm_template.library_items'])]}
Traceback (most recent call last):
File "/autosrc/sanjay/vsphere-automation-sdk-python/samples/vsphere/common/sample_base.py", line 79, in run
attr() # calling the method
File "samples/vsphere/contentlibrary/vmtemplate/create_vm_template.py", line 125, in _execute
self.item_id = self.client.vmtx_service.create(create_spec)
File "/usr/local/lib/python3.5/dist-packages/com/vmware/vcenter/vm_template_client.py", line 2080, in create
'spec': spec,
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 317, in _invoke
return self._api_interface.native_invoke(ctx, _method_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 275, in native_invoke
self._rest_converter_mode)
com.vmware.vapi.std.errors_client.OperationNotFound: {data : None, messages : [LocalizableMessage(id='vapi.method.input.invalid.interface', default_message="Cannot find service 'com.vmware.vcenter.vm_template.library_items'.", args=['com.vmware.vcenter.vm_template.library_items'])]}
from vsphere-automation-sdk-python.
Yes i have pulled the latest code and installed the required packages but still getting this error i have actually modified code to use cluster instead of resource pool is this code not supported for cluster?
Found VM 'isp-7934' (vm-1801)
Detected cluster '7934' as domain-c1789
Datastore MoId: datastore-1795
Local library created, ID: 4f687373-4935-45e8-8e07-060a7e45aa8c
Traceback (most recent call last):
File "/autosrc/sanjay/vsphere-automation-sdk-python/samples/vsphere/common/sample_base.py", line 79, in run
attr() # calling the method
File "samples/vsphere/contentlibrary/vmtemplate/create_vm_template.py", line 125, in _execute
self.item_id = self.client.vmtx_service.create(create_spec)
File "/usr/local/lib/python3.5/dist-packages/com/vmware/vcenter/vm_template_client.py", line 2080, in create
'spec': spec,
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 317, in _invoke
return self._api_interface.native_invoke(ctx, _method_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 275, in native_invoke
self._rest_converter_mode)
com.vmware.vapi.std.errors_client.OperationNotFound: {data : None, messages : [LocalizableMessage(id='vapi.method.input.invalid.interface', default_message="Cannot find service 'com.vmware.vcenter.vm_template.library_items'.", args=['com.vmware.vcenter.vm_template.library_items'])]}
Traceback (most recent call last):
File "/autosrc/sanjay/vsphere-automation-sdk-python/samples/vsphere/common/sample_base.py", line 79, in run
attr() # calling the method
File "samples/vsphere/contentlibrary/vmtemplate/create_vm_template.py", line 125, in _execute
self.item_id = self.client.vmtx_service.create(create_spec)
File "/usr/local/lib/python3.5/dist-packages/com/vmware/vcenter/vm_template_client.py", line 2080, in create
'spec': spec,
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 317, in _invoke
return self._api_interface.native_invoke(ctx, _method_name, kwargs)
File "/usr/local/lib/python3.5/dist-packages/vmware/vapi/bindings/stub.py", line 275, in native_invoke
self._rest_converter_mode)
com.vmware.vapi.std.errors_client.OperationNotFound: {data : None, messages : [LocalizableMessage(id='vapi.method.input.invalid.interface', default_message="Cannot find service 'com.vmware.vcenter.vm_template.library_items'.", args=['com.vmware.vcenter.vm_template.library_items'])]}
from vsphere-automation-sdk-python.
Cluster should work too. Can you share your modified code?
from vsphere-automation-sdk-python.
Can you try if the original version with resource pool works for you?
from vsphere-automation-sdk-python.
#!/usr/bin/env python
"""
Copyright VMware, Inc. 2017-2018. All Rights Reserved.
SPDX-License-Identifier: MIT
DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""
author = 'VMware, Inc.'
vcenter_version = '6.6.2+'
from com.vmware.vcenter.vm_template_client import (
LibraryItems as VmtxLibraryItem)
from vmware.vapi.vsphere.client import create_vsphere_client
from samples.vsphere.common.id_generator import rand
from samples.vsphere.common.sample_base import SampleBase
from samples.vsphere.common.ssl_helper import get_unverified_session
from samples.vsphere.contentlibrary.lib.cls_api_client import ClsApiClient
from samples.vsphere.contentlibrary.lib.cls_api_helper import ClsApiHelper
from samples.vsphere.vcenter.helper.cluster_helper import (get_cluster)
from samples.vsphere.vcenter.helper.vm_helper import get_vm
class CreateVmTemplate(SampleBase):
"""
Demonstrates how to create a library item containing a virtual machine
template from a virtual machine.
Prerequisites:
- A virtual machine
- A datacenter
- A cluster
- A datastore
"""
def init(self):
SampleBase.init(self, self.doc)
self.servicemanager = None
self.client = None
self.helper = None
self.vm_name = None
self.datastore_name = None
self.library_name = 'demo-vmtx-lib'
self.item_name = None
self.item_id = None
def _options(self):
self.argparser.add_argument('-vmname', '--vmname',
required=True,
help='The name of the source VM from '
'which to create a library item')
self.argparser.add_argument('-datacentername', '--datacentername',
required=True,
help='The name of the datacenter in which '
'to place the VM template')
self.argparser.add_argument('-clustername', '--clustername',
required=True,
help='The name of the cluster in '
'the datacenter in which to place '
'the VM template')
self.argparser.add_argument('-datastorename', '--datastorename',
required=True,
help='The name of the datastore in which '
'to create a library and VM template')
self.argparser.add_argument('-itemname', '--itemname',
help='The name of the library item to '
'create. The item will contain a '
'VM template.')
def _setup(self):
# Required arguments
self.vm_name = self.args.vmname
self.datacenter_name = self.args.datacentername
self.cluster_name = self.args.clustername
self.datastore_name = self.args.datastorename
# Optional arguments
self.item_name = (self.args.itemname if self.args.itemname
else rand('vmtx-item-'))
self.servicemanager = self.get_service_manager()
self.client = ClsApiClient(self.servicemanager)
self.helper = ClsApiHelper(self.client, self.skip_verification)
session = get_unverified_session() if self.skip_verification else None
self.vsphere_client = create_vsphere_client(server=self.server,
username=self.username,
password=self.password,
session=session)
def _execute(self):
# Get the identifiers
vm_id = get_vm(self.vsphere_client, self.vm_name)
assert vm_id
cluster_id = get_cluster(self.vsphere_client,
self.datacenter_name,
self.cluster_name)
assert cluster_id
# Create a library
storage_backings = self.helper.create_storage_backings(
self.servicemanager, self.datastore_name)
self.library_id = self.helper.create_local_library(storage_backings,
self.library_name)
# Build the create specification
create_spec = VmtxLibraryItem.CreateSpec()
create_spec.source_vm = vm_id
create_spec.library = self.library_id
create_spec.name = self.item_name
create_spec.placement = VmtxLibraryItem.CreatePlacementSpec(
cluster=cluster_id)
# Create a new library item from the source VM
self.item_id = self.client.vmtx_service.create(create_spec)
print("Created VM template item '{0}' with ID: {1}".format(
self.item_name, self.item_id))
# Retrieve the library item info
info = self.client.vmtx_service.get(self.item_id)
print('VM template guest OS: {0}'.format(info.guest_os))
def _cleanup(self):
if self.library_id:
self.client.local_library_service.delete(self.library_id)
print('Deleted library ID: {0}'.format(self.library_id))
def main():
sample = CreateVmTemplate()
sample.main()
if name == 'main':
main()
from vsphere-automation-sdk-python.
Still can't reproduce the issue:
Found VM 'Sample_Basic_VM_for_Simple_Testbed' (vm-78)
Detected cluster 'Cluster1' as domain-c46
Datastore MoId: datastore-68
Local library created, ID: c2f9868a-6498-468e-897c-df0761bba2e5
Created VM template item 'vmtx-item-WNDFY' with ID: 2f2bf9f6-6b0c-41af-b445-12d220d471bd
VM template guest OS: WINDOWS_9_64
disconnecting the session
Can you post the result of "pip list"?
from vsphere-automation-sdk-python.
this is the pip list
asn1crypto (0.24.0)
attrs (17.4.0)
Automat (0.6.0)
beautifulsoup4 (4.5.1)
certifi (2018.1.18)
cffi (1.11.5)
chardet (3.0.4)
click (6.7)
command-not-found (0.3)
constantly (15.1.0)
cryptography (2.2.2)
Cython (0.24.1)
extras (1.0.0)
falcon (1.0.0)
fixtures (3.0.0)
Flask (0.12.2)
gevent (1.1.2)
greenlet (0.4.10)
gunicorn (19.6.0)
html5lib (1.0.1)
hyperlink (18.0.0)
idna (2.6)
incremental (17.5.0)
itsdangerous (0.24)
Jinja2 (2.10)
language-selector (0.1)
language-selector (0.1)
linecache2 (1.0.0)
lxml (4.2.1)
MarkupSafe (1.0)
pbr (3.1.1)
pip (9.0.3)
pyasn1 (0.4.2)
pyasn1-modules (0.2.1)
pycparser (2.18)
pycurl (7.43.0)
pygobject (3.20.0)
pyOpenSSL (17.5.0)
python-apt (1.1.0b1+ubuntu0.16.4.1)
python-debian (0.1.27)
python-mimeparse (1.6.0)
python-systemd (231)
pyvmomi (6.5.0.2017.5.post1)
requests (2.18.4)
service-identity (17.0.0)
setuptools (39.0.1)
simplejson (3.13.2)
six (1.11.0)
ssh-import-id (5.5)
statsd (3.2.1)
suds-jurko (0.6)
tabulate (0.8.2)
testtools (2.3.0)
traceback2 (1.4.0)
Twisted (17.9.0)
ufw (0.35)
ujson (1.35)
unattended-upgrades (0.1)
unittest2 (1.1.0)
urllib3 (1.22)
vapi-client-bindings (1.1.0)
vapi-runtime (2.9.0)
vapi-vmc-client (2.9.0)
vmc-client-bindings (1.1.0)
webencodings (0.5.1)
Werkzeug (0.14.1)
wheel (0.29.0)
zope.interface (4.4.3)
from vsphere-automation-sdk-python.
I have got the same error with original resource pool code too,
when i go to this path /usr/local/lib/python3.5/dist-packages/com/vmware/vcenterr. i dont have this file in there does that matter ""vm_template.library_items'"' because i am getting this error ????
Exception: {data : None, messages : [LocalizableMessage(args=['com.vmware.vcenter.vm_template.library_items'], default_message="Cannot find service 'com.vmware.vcenter.vm_template.library_items'.", id='vapi.method.input.invalid.interface')]}
do we need any specific version of vsphere any limitations?
from vsphere-automation-sdk-python.
VM Templates from content library was added into VMware Cloud on AWS (VMC) only at the moment, are you running it against VMC?
from vsphere-automation-sdk-python.
No I am not running against VMC . i am running against my on premise instance
from vsphere-automation-sdk-python.
This API has not yet made it to an on-premise release, if you want to work with templates in Python the only way to do this at the moment is to use PyvMomi and use the VM Template functionality, VMTemlates in CL are currently only in VMC. Unless you are looking to work with OVFs published to CL?
from vsphere-automation-sdk-python.
if OVFs works fine i will work with that
from vsphere-automation-sdk-python.
Great, you can find them here: https://github.com/vmware/vsphere-automation-sdk-python/tree/master/samples/vsphere/contentlibrary
from vsphere-automation-sdk-python.
Thank you so much for taking time
from vsphere-automation-sdk-python.
can you also please send me the link of pyvmomi samples to create vm from a template
from vsphere-automation-sdk-python.
@sanjay1839 Please check this example for deploying VM from template using Pyvmomi - https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/clone_vm.py
from vsphere-automation-sdk-python.
from vsphere-automation-sdk-python.
Related Issues (20)
- [question] how to list custom_attributes for vm? HOT 1
- Air Gap Installation Issue HOT 3
- No LICENSE.txt file in the package HOT 4
- Support communication with vCenter Server via kerberos authenticated proxy sever HOT 1
- pip install vsphere-automation-sdk-python is broken. HOT 3
- vcenter.iso.iso_path.get_datastore_path() missing HOT 3
- from vmware.vapi.vsphere.client import create_vsphere_client HOT 8
- How to get VM Hardware of a OVF Template in Content Library HOT 5
- Not able to create ticket for Web console for newly created VM HOT 6
- Possible problem with Python 3.12? HOT 7
- Use "com" folder as an implicit namespace HOT 2
- How to get list of running Tasks ? HOT 2
- How to get list of running Tasks using vsphere-automation-sdk-python? HOT 1
- Add "Rename" to VM operations HOT 1
- issue with installation HOT 2
- How to Get VM current CPU and Memory Usage by Python SDK HOT 1
- Outdated pip package HOT 1
- No Module Named 'vmware' HOT 4
- Failure to Create Session with vSphere Client Using Self-Signed Certificate HOT 6
- ModuleNotFoundError: No module named 'vmware.vapi'; 'vmware' is not a package HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vsphere-automation-sdk-python.