Skip to content

image-copy: first commit - #8

Merged
Derek Bekoe (derekbekoe) merged 5 commits into
Azure:masterfrom
tamirkamara:master
Oct 31, 2017
Merged

image-copy: first commit#8
Derek Bekoe (derekbekoe) merged 5 commits into
Azure:masterfrom
tamirkamara:master

Conversation

@tamirkamara

Copy link
Copy Markdown
Contributor


def load_params(_):
with ParametersContext('image copy') as c:
c.register('source_resource_group_name', '--source-resource-group-name', help='Name of the resource gorup of the source resource')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just make it --source-resource-group or maybe --source-group. --source-resource-group-name is too long.


def load_params(_):
with ParametersContext('image copy') as c:
c.register('source_resource_group_name', '--source-resource-group-name', help='Name of the resource gorup of the source resource')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo gorup to group

with ParametersContext('image copy') as c:
c.register('source_resource_group_name', '--source-resource-group-name', help='Name of the resource gorup of the source resource')
c.register('source_object_name', '--source-object-name', help='The name of the image or vm resource')
c.register('target_location', '--target-location', help='Comma seperated location list to create the image in')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo seperated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use nargs=+ and it would be space-separated since that's what we use elsewhere in CLI.
For example https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/commands/parameters.py#L209

c.register('source_resource_group_name', '--source-resource-group-name', help='Name of the resource gorup of the source resource')
c.register('source_object_name', '--source-object-name', help='The name of the image or vm resource')
c.register('target_location', '--target-location', help='Comma seperated location list to create the image in')
c.register('source_type', '--source-type', help='image (default) or vm')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the (default) for?
Not sure if I understand the help text fully and maybe it's not that clear?

c.register('source_object_name', '--source-object-name', help='The name of the image or vm resource')
c.register('target_location', '--target-location', help='Comma seperated location list to create the image in')
c.register('source_type', '--source-type', help='image (default) or vm')
c.register('target_resource_group_name', '--target-resource-group-name', help='Name of the resource group to create images in')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove name from '--target-resource-group-name at least.


source_os_disk_id = json_cmd_output['storageProfile']['osDisk']['managedDisk']['id']
source_os_type = json_cmd_output['storageProfile']['osDisk']['osType']
logger.debug("source_os_disk_id: " + source_os_disk_id + " source_os_type: " + source_os_type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger prefers lazy loading of arguments so:

logger.debug("source_os_disk_id: %s source_os_type: %s", source_os_disk_id, source_os_type)

pool.close()
pool.join()
except KeyboardInterrupt:
print('xxx - parent')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove?

except KeyboardInterrupt:
print('xxx - parent')
logger.warn('User cancelled the operation')
if 'true' in cleanup:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cleanup is defined as action='store_true' then this would simply be if cleanup with is a lot less likely to break e.g. with letter casing.

print('xxx - parent')
logger.warn('User cancelled the operation')
if 'true' in cleanup:
logger.warn('To cleanup temporary resources look for ones tagged with "image-copy-extension"')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if you actually print the command to do this.

az resource list --tag ...

Comment thread src/image-copy/setup.py Outdated
license='MIT',
author='Tamir Kamara',
author_email='tamir.kamara@microsoft.com',
url='https://github.com/ORG/REPO',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@derekbekoe

Copy link
Copy Markdown
Member

Tamir Kamara (@tamirkamara) Thanks for the PR!
I added some comments.

@@ -0,0 +1,3 @@
{
"azext.minCliVersion": "2.0.12"
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this.
I know it was in the example but not needed in this case.

c.register('source_resource_group_name', '--source-resource-group', help='Name of the resource group of the source resource')
c.register('source_object_name', '--source-object-name', help='The name of the image or vm resource')
c.register('target_location', '--target-location', nargs='+', help='Space separated location list to create the image in (use location short codes like westeurope etc.)')
c.register('source_type', '--source-type', default='image', help='image or vm')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add choices=['image', 'vm'] if those are the only two allowed values.

json_output = json.loads(cmd_output)
return json_output
else:
raise CLIError("Command returned an unexpected empty string.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add which command to this error message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one later on - this raises an exception in the try-catch block and the catch prints the cmd


# tag newly created resources
if 'create' in cmd and ('container' not in cmd):
full_cmd += ['--tags', 'created_by=image-copy-extension']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense.
Consider adding one line comment for this to explain?


if 'false' in cmd_output:
# create the target resource group
logger.warn("Creating resource group: %s", )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the actual value here it seems

Comment thread src/image-copy/setup.py Outdated
url='https://github.com/Azure/azure-cli-extensions',
classifiers=CLASSIFIERS,
packages=find_packages(),
package_data={'azext_imagecopy': ['azext_metadata.json']},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants