Misspelling on the above lines... looks like some Autocomplete fail.
691 + """ Create and spawn the VM """
There are a number of docstrings which incorrectly have a space after and before the opening and closing """ marks. Please correct those. Should be like so:
"""Create and spawn the VM"""
For multi-line docstrings, we use the pep0257 recommendations, so:
"""Create and spawn the VM
This is a more descriptive description...
"""
or:
"""
Create and spawn the VM
This is a more descriptive description...
"""
or even:
"""
Create and spawn the VM
This is a more descriptive description...
"""
All of which will be identical once newline-trimmed, as most all doc-generation does.
There are already a number of fakes in the test suite(s). Was it necessary to create another one just for the vmwareapi? Can we use one of the existing ones?
1101 +class VimException(Exception):
1102 + """The VIM Exception class"""
The acronym VIM is a bit confusing, and it is used in a number of files in this patch. Most everyone associates VIM with the ViM editor (just Google what is (a) VIM). What does VIM stand for here?
This file smells a bit like Not Invented Here syndrome... I think it would be best to use an existing library for this type of functionality. Try checking out Eventlet's greenthread-aware Queue class: http://eventlet.net/doc/modules/queue.html.
Please don't do this. Use glance.client instead, which already handles chunked-encoding HTTP transfers for you. The code above (and associated ImageServiceFile in the same read_write_util.py has a number of errors regarding chunked transfer that have already been solved in glance.client. Please let me know if you need assistance using the glance.client.Client class (and more comments about this below...)
3372 + LOG.debug(_("Creating Virtual Disk of size "
3373 + "%(vmdk_file_size_in_kb)s KB and adapter type "
3374 + "%(adapter_type)s on the ESX host local store"
3375 + " %(data_store_name)s") %
3376 + {"vmdk_file_size_in_kb": vmdk_file_size_in_kb,
3377 + "adapter_type": adapter_type,
3378 + "data_store_name": data_store_name})
You do this in a few locations. Here's a little Python trick to make things like the above a bit more readable... when you have a format string with %(varname)s replacements, and all of the variables in the format string are in the local scope, you can just do this:
LOG.debug(_("Creating Virtual Disk of size " "%(vmdk_file_size_in_kb)s KB and adapter type " "%(adapter_type)s on the ESX host local store"
" %(data_store_name)s") % locals()))
3845 + def get_ajax_console(self, instance):
3846 + """ Return link to instance's ajax console """
3847 + return 'http://fakeajaxconsole/fake_url'
If you use glance.client instead of the home-grown GlanceHTTPReadFile, you could do this:
c = glance.client.Client(host, port)
read_file_handle, image_metadata = c.get_image(image_id)
Glance's Client returns a file object that reads the image data in chunks, just like a StringIO.StringIO would. So, IMHO, there's no reason for you to have the GlanceHTTPReadFile object or the ImageServiceFile object. Likewise, the GlanceHTTPWriteFile can be gotten rid of. Just do this:
c = glance.client.Client(host, port)
c.add_image(image_meta, image_data)
The reason is because by doing that, you override Glance's default backing store, which is probably not what you wanted to do :) For instance, if Glance is setup to use Swift as its backing store, you just overrode that setting, which should only be done in very specific scenarios, and I don't think this is one of them...
In addition, you had this in GlanceHTTPWriteFile:
2297 + conn.putheader("x-image-meta-type", "raw")
The type is no longer a base attribute in Glance. Use disk-format and/or container-format, like so:
Hi Sateesh!
Phew, this is a big patch! I commend you for being able to go through the VMWare SDK and SOAP API docs...
Some suggestions and style nits :)
47 +Currently supports Nova's flat networking model (Flat Manager).
You note in the description that you are supporting VLAN and FLAT. The above line is from the documentation. May want to correct the docs there.
601 + NetworkHelper. get_vlanid_ and_vswicth_ for_portgroup( session, bridge) and_vswicth_ for_portgroup( cls, session, pg_name):
2139 + def get_vlanid_
Misspelling on the above lines... looks like some Autocomplete fail.
691 + """ Create and spawn the VM """
There are a number of docstrings which incorrectly have a space after and before the opening and closing """ marks. Please correct those. Should be like so:
"""Create and spawn the VM"""
For multi-line docstrings, we use the pep0257 recommendations, so:
"""Create and spawn the VM
This is a more descriptive description...
"""
or:
"""
Create and spawn the VM
This is a more descriptive description...
"""
or even:
"""
Create and spawn the VM
This is a more descriptive description...
"""
All of which will be identical once newline-trimmed, as most all doc-generation does.
See http:// www.python. org/dev/ peps/pep- 0257/ for more details.
Some comments are like this:
03 + #Check if the vsiwtch associated is proper
and some are like this:
713 + # Get Nova record for VM
Please use the latter, with a space after the #.
857 === added file 'nova/tests/ vmwareapi/ db_fakes. py'
There are already a number of fakes in the test suite(s). Was it necessary to create another one just for the vmwareapi? Can we use one of the existing ones?
1101 +class VimException( Exception) :
1102 + """The VIM Exception class"""
The acronym VIM is a bit confusing, and it is used in a number of files in this patch. Most everyone associates VIM with the ViM editor (just Google what is (a) VIM). What does VIM stand for here?
1886 === added file 'nova/virt/ vmwareapi/ io_util. py'
This file smells a bit like Not Invented Here syndrome... I think it would be best to use an existing library for this type of functionality. Try checking out Eventlet's greenthread-aware Queue class: http:// eventlet. net/doc/ modules/ queue.html.
2279 +class GlanceHTTPWrite File(ImageServi ceFile) : s:%s/images/ %s" % (scheme, host, port, image_id) urlparse( base_url) HTTPConnection( netloc) HTTPSConnection (netloc) ("PUT", path) "User-Agent" , USER_AGENT) "Content- Length" , file_size) "Content- Type", "application/ octet-stream" ) "x-image- meta-store" , "file") "x-image- meta-is_ public" , "True") "x-image- meta-type" , "raw") "x-image- meta-size" , file_size) "x-image- meta-property- kernel_ id", "") "x-image- meta-property- ramdisk_ id", "") "x-image- meta-property- vmware_ ostype" , os_type) "x-image- meta-property- vmware_ adaptertype" , "x-image- meta-property- vmware_ image_version" , version) e.__init_ _(self, conn) handle. send(data)
2280 + """Glance file write handler class"""
2281 +
2282 + def __init__(self, host, port, image_id, file_size, os_type, adapter_type,
2283 + version=1, scheme="http"):
2284 + base_url = "%s://%
2285 + (scheme, netloc, path, params, query, fragment) = \
2286 + urlparse.
2287 + if scheme == "http":
2288 + conn = httplib.
2289 + elif scheme == "https":
2290 + conn = httplib.
2291 + conn.putrequest
2292 + conn.putheader(
2293 + conn.putheader(
2294 + conn.putheader(
2295 + conn.putheader(
2296 + conn.putheader(
2297 + conn.putheader(
2298 + conn.putheader(
2299 + conn.putheader(
2300 + conn.putheader(
2301 + conn.putheader(
2302 + conn.putheader(
2303 + adapter_type)
2304 + conn.putheader(
2305 + conn.endheaders()
2306 + ImageServiceFil
2307 +
2308 + def write(self, data):
2309 + """Write data to the file"""
2310 + self.file_
Please don't do this. Use glance.client instead, which already handles chunked-encoding HTTP transfers for you. The code above (and associated ImageServiceFile in the same read_write_util.py has a number of errors regarding chunked transfer that have already been solved in glance.client. Please let me know if you need assistance using the glance. client. Client class (and more comments about this below...)
2655 +def build_selcetion _spec(client_ factory, name): select_ spec = build_selcetion _spec(client_ factory, select_ spec = build_selcetion _spec(client_ factory, "rp_to_rp") select_ spec = build_selcetion _spec(client_ factory, "rp_to_vm")
2676 + visit_folders_
2699 + rp_to_rp_
2700 + rp_to_vm_
Misspelled method name and repeated. Autocomplete fail?
2830 +def get_properites_ for_a_collectio n_of_objects( vim, type, _for_a_ collection_ of_objects" ,
2090 + "get_properites
Another method mispelling and repeat.
3372 + LOG.debug( _("Creating Virtual Disk of size " file_size_ in_kb)s KB and adapter type " store_name) s") % file_size_ in_kb": vmdk_file_ size_in_ kb,
3373 + "%(vmdk_
3374 + "%(adapter_type)s on the ESX host local store"
3375 + " %(data_
3376 + {"vmdk_
3377 + "adapter_type": adapter_type,
3378 + "data_store_name": data_store_name})
You do this in a few locations. Here's a little Python trick to make things like the above a bit more readable... when you have a format string with %(varname)s replacements, and all of the variables in the format string are in the local scope, you can just do this:
LOG.debug( _("Creating Virtual Disk of size "
"% (vmdk_file_ size_in_ kb)s KB and adapter type "
"% (adapter_ type)s on the ESX host local store" store_name) s") % locals()))
" %(data_
3845 + def get_ajax_ console( self, instance): fakeajaxconsole /fake_url'
3846 + """ Return link to instance's ajax console """
3847 + return 'http://
The above is in the NON-fake vmops.py :)
4030 +def _get_glance_ image(image, instance, **kwargs): _("Downloading image %s from glance image server") % image) util.GlanceHTTP ReadFile( FLAGS.glance_ host, handle. get_size( ) util.VMWareHTTP WriteFile( get("data_ center_ name"), get("datastore_ name"), get("cookies" ), get("file_ path"), read_file_ handle, write_file_handle, file_size) _("Downloaded image %s from glance image server") % image)
4031 + """ Download image from the glance image server. """
4032 + LOG.debug(
4033 + read_file_handle = read_write_
4034 + FLAGS.glance_port,
4035 + image)
4036 + file_size = read_file_
4037 + write_file_handle = read_write_
4038 + kwargs.get("host"),
4039 + kwargs.
4040 + kwargs.
4041 + kwargs.
4042 + kwargs.
4043 + file_size)
4044 + start_transfer(
4045 + LOG.debug(
If you use glance.client instead of the home-grown GlanceHTTPReadFile, you could do this:
c = glance. client. Client( host, port) image_id)
read_file_handle, image_metadata = c.get_image(
Glance's Client returns a file object that reads the image data in chunks, just like a StringIO.StringIO would. So, IMHO, there's no reason for you to have the GlanceHTTPReadFile object or the ImageServiceFile object. Likewise, the GlanceHTTPWriteFile can be gotten rid of. Just do this:
c = glance. client. Client( host, port) image_meta, image_data)
c.add_image(
where image_meta is something like this:
{'name': <NAME>, format' : 'bare',
'vmware_ adaptertype' : <ADAPTER_TYPE>,
'vmware_ os_type' , <OS_TYPE>,
'vmware_ image_version' : <VERSION>}}
'is_public': True,
'disk_format': 'raw',
'container_
'size': <SIZE>,
'properties': {'kernel_id': "", 'ramdisk_id': "",
and image_data is a file-like object. Also, do NOT do this:
2295 + conn.putheader( "x-image- meta-store" , "file")
The reason is because by doing that, you override Glance's default backing store, which is probably not what you wanted to do :) For instance, if Glance is setup to use Swift as its backing store, you just overrode that setting, which should only be done in very specific scenarios, and I don't think this is one of them...
In addition, you had this in GlanceHTTPWrite File:
2297 + conn.putheader( "x-image- meta-type" , "raw")
The type is no longer a base attribute in Glance. Use disk-format and/or container-format, like so:
{'disk_format': 'raw', 'container_format': 'bare'}
You can read more about formats here: http:// glance. openstack. org/formats. html and the Glance client here: http:// glance. openstack. org/client. html
As a final note, I'd like to get Vishy to review the code in the Guest Tool on networking...
Cheers!
jay