def list_branches(dlpx_obj): """ List all branches on a given engine :param dlpx_obj: Virtualization Engine session object """ try: header = '\nBranch Name, Data Layout, Reference, End Time' js_data_layout = '' js_branches = branch.get_all(dlpx_obj.server_session) print header for js_branch in js_branches: js_end_time = operation.get(dlpx_obj.server_session, js_branch.first_operation).end_time if re.search('TEMPLATE', js_branch.data_layout): js_data_layout = find_obj_name(dlpx_obj.server_session, template, js_branch.data_layout) elif re.search('CONTAINER', js_branch.data_layout): js_data_layout = find_obj_name(dlpx_obj.server_session, container, js_branch.data_layout) print_info('{} {}, {}, {}'.format(js_branch._name[0], js_data_layout, js_branch.reference, js_end_time)) except (DlpxException, HttpError, RequestError) as e: print_exception('\nERROR: JS Branches could not be listed. The ' 'error was:\n\n{}'.format(e))
def create_bookmark(dlpx_obj, bookmark_name, source_layout, branch_name=None, tag=None, description=None): """ Create the JS Bookmark :param dlpx_obj: Virtualization Engine session object :type dlpx_obj: lib.GetSession.GetSession :param bookmark_name: Name of the bookmark to create :type bookmark_name: basestring :param source_layout: Name of the source (template or container) to use :type source_layout: basestring :param branch_name: Name of the branch to use :type branch_name: basestring :param tag_name: Tag to use for the bookmark :type tag: basestring :param description: Description of the bookmark :type description: basestring """ branch_ref = None source_layout_ref = None engine_name = dlpx_obj.dlpx_engines.keys()[0] js_bookmark_params = JSBookmarkCreateParameters() if branch_name: try: source_layout_ref = find_obj_by_name(dlpx_obj.server_session, template, source_layout).reference except DlpxException: source_layout_ref = find_obj_by_name(dlpx_obj.server_session, container, source_layout).reference #import pdb;pdb.set_trace() for branch_obj in branch.get_all(dlpx_obj.server_session): if branch_name == branch_obj.name and \ source_layout_ref == branch_obj.data_layout: branch_ref = branch_obj.reference break if branch_ref is None: raise DlpxException('Set the --data_layout parameter equal to ' 'the data layout of the bookmark.\n') elif branch_name is None: try: (source_layout_ref, branch_ref) = find_obj_by_name(dlpx_obj.server_session, template, source_layout, True) except DlpxException: (source_layout_ref, branch_ref) = find_obj_by_name(dlpx_obj.server_session, container, source_layout, True) if branch_ref is None: raise DlpxException('Could not find {} in engine {}'.format( branch_name, engine_name)) js_bookmark_params.bookmark = JSBookmark() js_bookmark_params.bookmark.name = bookmark_name js_bookmark_params.bookmark.branch = branch_ref if tag: js_bookmark_params.bookmark.tags = list() js_bookmark_params.bookmark.tags.append(tag) if description: js_bookmark_params.bookmark.description = description js_bookmark_params.timeline_point_parameters = { 'sourceDataLayout': source_layout_ref, 'type': 'JSTimelinePointLatestTimeInput' } try: bookmark.create(dlpx_obj.server_session, js_bookmark_params) dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job print_info( 'JS Bookmark {} was created successfully.'.format(bookmark_name)) except (DlpxException, RequestError, HttpError) as e: print_exception('\nThe bookmark {} was not created. The error ' 'was:\n\n{}'.format(bookmark_name, e))
def create_bookmark(dlpx_obj, bookmark_name, source_layout, branch_name=None, tags=None, description=None): """ Create the JS Bookmark :param dlpx_obj: Virtualization Engine session object :type dlpx_obj: lib.GetSession.GetSession :param bookmark_name: Name of the bookmark to create :type bookmark_name: basestring :param source_layout: Name of the source (template or container) to use :type source_layout: basestring :param branch_name: Name of the branch to use :type branch_name: basestring :param tag_name: Tag to use for the bookmark :type tag: basestring :param description: Description of the bookmark :type description: basestring """ branch_ref = None source_layout_ref = None engine_name = dlpx_obj.dlpx_engines.keys()[0] js_bookmark_params = JSBookmarkCreateParameters() if branch_name: try: source_layout_ref = find_obj_by_name(dlpx_obj.server_session, template, source_layout).reference except DlpxException: source_layout_ref = find_obj_by_name( dlpx_obj.server_session, container, source_layout).reference #import pdb;pdb.set_trace() for branch_obj in branch.get_all(dlpx_obj.server_session): if branch_name == branch_obj.name and \ source_layout_ref == branch_obj.data_layout: branch_ref = branch_obj.reference break if branch_ref is None: raise DlpxException('Set the --data_layout parameter equal to ' 'the data layout of the bookmark.\n') elif branch_name is None: try: (source_layout_ref, branch_ref) = find_obj_by_name( dlpx_obj.server_session, template, source_layout, True) except DlpxException: (source_layout_ref, branch_ref) = find_obj_by_name( dlpx_obj.server_session, container, source_layout, True) if branch_ref is None: raise DlpxException('Could not find {} in engine {}'.format( branch_name, engine_name)) js_bookmark_params.bookmark = JSBookmark() js_bookmark_params.bookmark.name = bookmark_name js_bookmark_params.bookmark.branch = branch_ref if tags: js_bookmark_params.bookmark.tags = tags.split(',') if description: js_bookmark_params.bookmark.description = description js_bookmark_params.timeline_point_parameters = { 'sourceDataLayout': source_layout_ref, 'type': 'JSTimelinePointLatestTimeInput'} try: bookmark.create(dlpx_obj.server_session, js_bookmark_params) dlpx_obj.jobs[engine_name] = dlpx_obj.server_session.last_job print_info('JS Bookmark {} was created successfully.'.format( bookmark_name)) except (DlpxException, RequestError, HttpError) as e: print_exception('\nThe bookmark {} was not created. The error ' 'was:\n\n{}'.format(bookmark_name, e))