repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/sphinx_.py
EventHandlers.builder_inited
def builder_inited(app): """Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object. """ # Add this extension's _templates directory to Sphinx. templates_dir = os.path.join(os.path.dirname(__file__), '_templates') app.builder.templates.pathchain.insert(0, templates_dir) app.builder.templates.loaders.insert(0, SphinxFileSystemLoader(templates_dir)) app.builder.templates.templatepathlen += 1 # Add versions.html to sidebar. if '**' not in app.config.html_sidebars: app.config.html_sidebars['**'] = StandaloneHTMLBuilder.default_sidebars + ['versions.html'] elif 'versions.html' not in app.config.html_sidebars['**']: app.config.html_sidebars['**'].append('versions.html')
python
def builder_inited(app): """Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object. """ # Add this extension's _templates directory to Sphinx. templates_dir = os.path.join(os.path.dirname(__file__), '_templates') app.builder.templates.pathchain.insert(0, templates_dir) app.builder.templates.loaders.insert(0, SphinxFileSystemLoader(templates_dir)) app.builder.templates.templatepathlen += 1 # Add versions.html to sidebar. if '**' not in app.config.html_sidebars: app.config.html_sidebars['**'] = StandaloneHTMLBuilder.default_sidebars + ['versions.html'] elif 'versions.html' not in app.config.html_sidebars['**']: app.config.html_sidebars['**'].append('versions.html')
[ "def", "builder_inited", "(", "app", ")", ":", "# Add this extension's _templates directory to Sphinx.", "templates_dir", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ",", "'_templates'", ")", "app", ".", "...
Update the Sphinx builder. :param sphinx.application.Sphinx app: Sphinx application object.
[ "Update", "the", "Sphinx", "builder", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/sphinx_.py#L47-L62
train
37,500
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/sphinx_.py
EventHandlers.env_updated
def env_updated(cls, app, env): """Abort Sphinx after initializing config and discovering all pages to build. :param sphinx.application.Sphinx app: Sphinx application object. :param sphinx.environment.BuildEnvironment env: Sphinx build environment. """ if cls.ABORT_AFTER_READ: config = {n: getattr(app.config, n) for n in (a for a in dir(app.config) if a.startswith('scv_'))} config['found_docs'] = tuple(str(d) for d in env.found_docs) config['master_doc'] = str(app.config.master_doc) cls.ABORT_AFTER_READ.put(config) sys.exit(0)
python
def env_updated(cls, app, env): """Abort Sphinx after initializing config and discovering all pages to build. :param sphinx.application.Sphinx app: Sphinx application object. :param sphinx.environment.BuildEnvironment env: Sphinx build environment. """ if cls.ABORT_AFTER_READ: config = {n: getattr(app.config, n) for n in (a for a in dir(app.config) if a.startswith('scv_'))} config['found_docs'] = tuple(str(d) for d in env.found_docs) config['master_doc'] = str(app.config.master_doc) cls.ABORT_AFTER_READ.put(config) sys.exit(0)
[ "def", "env_updated", "(", "cls", ",", "app", ",", "env", ")", ":", "if", "cls", ".", "ABORT_AFTER_READ", ":", "config", "=", "{", "n", ":", "getattr", "(", "app", ".", "config", ",", "n", ")", "for", "n", "in", "(", "a", "for", "a", "in", "dir...
Abort Sphinx after initializing config and discovering all pages to build. :param sphinx.application.Sphinx app: Sphinx application object. :param sphinx.environment.BuildEnvironment env: Sphinx build environment.
[ "Abort", "Sphinx", "after", "initializing", "config", "and", "discovering", "all", "pages", "to", "build", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/sphinx_.py#L65-L76
train
37,501
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/sphinx_.py
EventHandlers.html_page_context
def html_page_context(cls, app, pagename, templatename, context, doctree): """Update the Jinja2 HTML context, exposes the Versions class instance to it. :param sphinx.application.Sphinx app: Sphinx application object. :param str pagename: Name of the page being rendered (without .html or any file extension). :param str templatename: Page name with .html. :param dict context: Jinja2 HTML context. :param docutils.nodes.document doctree: Tree of docutils nodes. """ assert templatename or doctree # Unused, for linting. cls.VERSIONS.context = context versions = cls.VERSIONS this_remote = versions[cls.CURRENT_VERSION] banner_main_remote = versions[cls.BANNER_MAIN_VERSION] if cls.SHOW_BANNER else None # Update Jinja2 context. context['bitbucket_version'] = cls.CURRENT_VERSION context['current_version'] = cls.CURRENT_VERSION context['github_version'] = cls.CURRENT_VERSION context['html_theme'] = app.config.html_theme context['scv_banner_greatest_tag'] = cls.BANNER_GREATEST_TAG context['scv_banner_main_ref_is_branch'] = banner_main_remote['kind'] == 'heads' if cls.SHOW_BANNER else None context['scv_banner_main_ref_is_tag'] = banner_main_remote['kind'] == 'tags' if cls.SHOW_BANNER else None context['scv_banner_main_version'] = banner_main_remote['name'] if cls.SHOW_BANNER else None context['scv_banner_recent_tag'] = cls.BANNER_RECENT_TAG context['scv_is_branch'] = this_remote['kind'] == 'heads' context['scv_is_greatest_tag'] = this_remote == versions.greatest_tag_remote context['scv_is_recent_branch'] = this_remote == versions.recent_branch_remote context['scv_is_recent_ref'] = this_remote == versions.recent_remote context['scv_is_recent_tag'] = this_remote == versions.recent_tag_remote context['scv_is_root'] = cls.IS_ROOT context['scv_is_tag'] = this_remote['kind'] == 'tags' context['scv_show_banner'] = cls.SHOW_BANNER context['versions'] = versions context['vhasdoc'] = versions.vhasdoc context['vpathto'] = versions.vpathto # Insert banner into body. if cls.SHOW_BANNER and 'body' in context: parsed = app.builder.templates.render('banner.html', context) context['body'] = parsed + context['body'] # Handle overridden css_files. css_files = context.setdefault('css_files', list()) if '_static/banner.css' not in css_files: css_files.append('_static/banner.css') # Handle overridden html_static_path. if STATIC_DIR not in app.config.html_static_path: app.config.html_static_path.append(STATIC_DIR) # Reset last_updated with file's mtime (will be last git commit authored date). if app.config.html_last_updated_fmt is not None: file_path = app.env.doc2path(pagename) if os.path.isfile(file_path): lufmt = app.config.html_last_updated_fmt or getattr(locale, '_')('%b %d, %Y') mtime = datetime.datetime.fromtimestamp(os.path.getmtime(file_path)) context['last_updated'] = format_date(lufmt, mtime, language=app.config.language, warn=app.warn)
python
def html_page_context(cls, app, pagename, templatename, context, doctree): """Update the Jinja2 HTML context, exposes the Versions class instance to it. :param sphinx.application.Sphinx app: Sphinx application object. :param str pagename: Name of the page being rendered (without .html or any file extension). :param str templatename: Page name with .html. :param dict context: Jinja2 HTML context. :param docutils.nodes.document doctree: Tree of docutils nodes. """ assert templatename or doctree # Unused, for linting. cls.VERSIONS.context = context versions = cls.VERSIONS this_remote = versions[cls.CURRENT_VERSION] banner_main_remote = versions[cls.BANNER_MAIN_VERSION] if cls.SHOW_BANNER else None # Update Jinja2 context. context['bitbucket_version'] = cls.CURRENT_VERSION context['current_version'] = cls.CURRENT_VERSION context['github_version'] = cls.CURRENT_VERSION context['html_theme'] = app.config.html_theme context['scv_banner_greatest_tag'] = cls.BANNER_GREATEST_TAG context['scv_banner_main_ref_is_branch'] = banner_main_remote['kind'] == 'heads' if cls.SHOW_BANNER else None context['scv_banner_main_ref_is_tag'] = banner_main_remote['kind'] == 'tags' if cls.SHOW_BANNER else None context['scv_banner_main_version'] = banner_main_remote['name'] if cls.SHOW_BANNER else None context['scv_banner_recent_tag'] = cls.BANNER_RECENT_TAG context['scv_is_branch'] = this_remote['kind'] == 'heads' context['scv_is_greatest_tag'] = this_remote == versions.greatest_tag_remote context['scv_is_recent_branch'] = this_remote == versions.recent_branch_remote context['scv_is_recent_ref'] = this_remote == versions.recent_remote context['scv_is_recent_tag'] = this_remote == versions.recent_tag_remote context['scv_is_root'] = cls.IS_ROOT context['scv_is_tag'] = this_remote['kind'] == 'tags' context['scv_show_banner'] = cls.SHOW_BANNER context['versions'] = versions context['vhasdoc'] = versions.vhasdoc context['vpathto'] = versions.vpathto # Insert banner into body. if cls.SHOW_BANNER and 'body' in context: parsed = app.builder.templates.render('banner.html', context) context['body'] = parsed + context['body'] # Handle overridden css_files. css_files = context.setdefault('css_files', list()) if '_static/banner.css' not in css_files: css_files.append('_static/banner.css') # Handle overridden html_static_path. if STATIC_DIR not in app.config.html_static_path: app.config.html_static_path.append(STATIC_DIR) # Reset last_updated with file's mtime (will be last git commit authored date). if app.config.html_last_updated_fmt is not None: file_path = app.env.doc2path(pagename) if os.path.isfile(file_path): lufmt = app.config.html_last_updated_fmt or getattr(locale, '_')('%b %d, %Y') mtime = datetime.datetime.fromtimestamp(os.path.getmtime(file_path)) context['last_updated'] = format_date(lufmt, mtime, language=app.config.language, warn=app.warn)
[ "def", "html_page_context", "(", "cls", ",", "app", ",", "pagename", ",", "templatename", ",", "context", ",", "doctree", ")", ":", "assert", "templatename", "or", "doctree", "# Unused, for linting.", "cls", ".", "VERSIONS", ".", "context", "=", "context", "ve...
Update the Jinja2 HTML context, exposes the Versions class instance to it. :param sphinx.application.Sphinx app: Sphinx application object. :param str pagename: Name of the page being rendered (without .html or any file extension). :param str templatename: Page name with .html. :param dict context: Jinja2 HTML context. :param docutils.nodes.document doctree: Tree of docutils nodes.
[ "Update", "the", "Jinja2", "HTML", "context", "exposes", "the", "Versions", "class", "instance", "to", "it", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/sphinx_.py#L79-L134
train
37,502
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
cli
def cli(config, **options): """Build versioned Sphinx docs for every branch and tag pushed to origin. Supports only building locally with the "build" sub command or build and push to a remote with the "push" sub command. For more information for either run them with their own --help. The options below are global and must be specified before the sub command name (e.g. -N build ...). \f :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param dict options: Additional Click options. """ def pre(rel_source): """To be executed in a Click sub command. Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py. """ # Setup logging. if not NO_EXECUTE: setup_logging(verbose=config.verbose, colors=not config.no_colors) log = logging.getLogger(__name__) # Change current working directory. if config.chdir: os.chdir(config.chdir) log.debug('Working directory: %s', os.getcwd()) else: config.update(dict(chdir=os.getcwd()), overwrite=True) # Get and verify git root. try: config.update(dict(git_root=get_root(config.git_root or os.getcwd())), overwrite=True) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError # Look for local config. if config.no_local_conf: config.update(dict(local_conf=None), overwrite=True) elif not config.local_conf: candidates = [p for p in (os.path.join(s, 'conf.py') for s in rel_source) if os.path.isfile(p)] if candidates: config.update(dict(local_conf=candidates[0]), overwrite=True) else: log.debug("Didn't find a conf.py in any REL_SOURCE.") elif os.path.basename(config.local_conf) != 'conf.py': log.error('Path "%s" must end with conf.py.', config.local_conf) raise HandledError config['pre'] = pre # To be called by Click sub commands. config.update(options)
python
def cli(config, **options): """Build versioned Sphinx docs for every branch and tag pushed to origin. Supports only building locally with the "build" sub command or build and push to a remote with the "push" sub command. For more information for either run them with their own --help. The options below are global and must be specified before the sub command name (e.g. -N build ...). \f :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param dict options: Additional Click options. """ def pre(rel_source): """To be executed in a Click sub command. Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py. """ # Setup logging. if not NO_EXECUTE: setup_logging(verbose=config.verbose, colors=not config.no_colors) log = logging.getLogger(__name__) # Change current working directory. if config.chdir: os.chdir(config.chdir) log.debug('Working directory: %s', os.getcwd()) else: config.update(dict(chdir=os.getcwd()), overwrite=True) # Get and verify git root. try: config.update(dict(git_root=get_root(config.git_root or os.getcwd())), overwrite=True) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError # Look for local config. if config.no_local_conf: config.update(dict(local_conf=None), overwrite=True) elif not config.local_conf: candidates = [p for p in (os.path.join(s, 'conf.py') for s in rel_source) if os.path.isfile(p)] if candidates: config.update(dict(local_conf=candidates[0]), overwrite=True) else: log.debug("Didn't find a conf.py in any REL_SOURCE.") elif os.path.basename(config.local_conf) != 'conf.py': log.error('Path "%s" must end with conf.py.', config.local_conf) raise HandledError config['pre'] = pre # To be called by Click sub commands. config.update(options)
[ "def", "cli", "(", "config", ",", "*", "*", "options", ")", ":", "def", "pre", "(", "rel_source", ")", ":", "\"\"\"To be executed in a Click sub command.\n\n Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help\n\n ...
Build versioned Sphinx docs for every branch and tag pushed to origin. Supports only building locally with the "build" sub command or build and push to a remote with the "push" sub command. For more information for either run them with their own --help. The options below are global and must be specified before the sub command name (e.g. -N build ...). \f :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param dict options: Additional Click options.
[ "Build", "versioned", "Sphinx", "docs", "for", "every", "branch", "and", "tag", "pushed", "to", "origin", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L121-L173
train
37,503
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
build_options
def build_options(func): """Add "build" Click options to function. :param function func: The function to wrap. :return: The wrapped function. :rtype: function """ func = click.option('-a', '--banner-greatest-tag', is_flag=True, help='Override banner-main-ref to be the tag with the highest version number.')(func) func = click.option('-A', '--banner-recent-tag', is_flag=True, help='Override banner-main-ref to be the most recent committed tag.')(func) func = click.option('-b', '--show-banner', help='Show a warning banner.', is_flag=True)(func) func = click.option('-B', '--banner-main-ref', help="Don't show banner on this ref and point banner URLs to this ref. Default master.")(func) func = click.option('-i', '--invert', help='Invert/reverse order of versions.', is_flag=True)(func) func = click.option('-p', '--priority', type=click.Choice(('branches', 'tags')), help="Group these kinds of versions at the top (for themes that don't separate them).")(func) func = click.option('-r', '--root-ref', help='The branch/tag at the root of DESTINATION. Will also be in subdir. Default master.')(func) func = click.option('-s', '--sort', multiple=True, type=click.Choice(('semver', 'alpha', 'time')), help='Sort versions. Specify multiple times to sort equal values of one kind.')(func) func = click.option('-t', '--greatest-tag', is_flag=True, help='Override root-ref to be the tag with the highest version number.')(func) func = click.option('-T', '--recent-tag', is_flag=True, help='Override root-ref to be the most recent committed tag.')(func) func = click.option('-w', '--whitelist-branches', multiple=True, help='Whitelist branches that match the pattern. Can be specified more than once.')(func) func = click.option('-W', '--whitelist-tags', multiple=True, help='Whitelist tags that match the pattern. Can be specified more than once.')(func) return func
python
def build_options(func): """Add "build" Click options to function. :param function func: The function to wrap. :return: The wrapped function. :rtype: function """ func = click.option('-a', '--banner-greatest-tag', is_flag=True, help='Override banner-main-ref to be the tag with the highest version number.')(func) func = click.option('-A', '--banner-recent-tag', is_flag=True, help='Override banner-main-ref to be the most recent committed tag.')(func) func = click.option('-b', '--show-banner', help='Show a warning banner.', is_flag=True)(func) func = click.option('-B', '--banner-main-ref', help="Don't show banner on this ref and point banner URLs to this ref. Default master.")(func) func = click.option('-i', '--invert', help='Invert/reverse order of versions.', is_flag=True)(func) func = click.option('-p', '--priority', type=click.Choice(('branches', 'tags')), help="Group these kinds of versions at the top (for themes that don't separate them).")(func) func = click.option('-r', '--root-ref', help='The branch/tag at the root of DESTINATION. Will also be in subdir. Default master.')(func) func = click.option('-s', '--sort', multiple=True, type=click.Choice(('semver', 'alpha', 'time')), help='Sort versions. Specify multiple times to sort equal values of one kind.')(func) func = click.option('-t', '--greatest-tag', is_flag=True, help='Override root-ref to be the tag with the highest version number.')(func) func = click.option('-T', '--recent-tag', is_flag=True, help='Override root-ref to be the most recent committed tag.')(func) func = click.option('-w', '--whitelist-branches', multiple=True, help='Whitelist branches that match the pattern. Can be specified more than once.')(func) func = click.option('-W', '--whitelist-tags', multiple=True, help='Whitelist tags that match the pattern. Can be specified more than once.')(func) return func
[ "def", "build_options", "(", "func", ")", ":", "func", "=", "click", ".", "option", "(", "'-a'", ",", "'--banner-greatest-tag'", ",", "is_flag", "=", "True", ",", "help", "=", "'Override banner-main-ref to be the tag with the highest version number.'", ")", "(", "fu...
Add "build" Click options to function. :param function func: The function to wrap. :return: The wrapped function. :rtype: function
[ "Add", "build", "Click", "options", "to", "function", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L176-L207
train
37,504
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
override_root_main_ref
def override_root_main_ref(config, remotes, banner): """Override root_ref or banner_main_ref with tags in config if user requested. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param iter remotes: List of dicts from Versions.remotes. :param bool banner: Evaluate banner main ref instead of root ref. :return: If root/main ref exists. :rtype: bool """ log = logging.getLogger(__name__) greatest_tag = config.banner_greatest_tag if banner else config.greatest_tag recent_tag = config.banner_recent_tag if banner else config.recent_tag if greatest_tag or recent_tag: candidates = [r for r in remotes if r['kind'] == 'tags'] if candidates: multi_sort(candidates, ['semver' if greatest_tag else 'time']) config.update({'banner_main_ref' if banner else 'root_ref': candidates[0]['name']}, overwrite=True) else: flag = '--banner-main-ref' if banner else '--root-ref' log.warning('No git tags with docs found in remote. Falling back to %s value.', flag) ref = config.banner_main_ref if banner else config.root_ref return ref in [r['name'] for r in remotes]
python
def override_root_main_ref(config, remotes, banner): """Override root_ref or banner_main_ref with tags in config if user requested. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param iter remotes: List of dicts from Versions.remotes. :param bool banner: Evaluate banner main ref instead of root ref. :return: If root/main ref exists. :rtype: bool """ log = logging.getLogger(__name__) greatest_tag = config.banner_greatest_tag if banner else config.greatest_tag recent_tag = config.banner_recent_tag if banner else config.recent_tag if greatest_tag or recent_tag: candidates = [r for r in remotes if r['kind'] == 'tags'] if candidates: multi_sort(candidates, ['semver' if greatest_tag else 'time']) config.update({'banner_main_ref' if banner else 'root_ref': candidates[0]['name']}, overwrite=True) else: flag = '--banner-main-ref' if banner else '--root-ref' log.warning('No git tags with docs found in remote. Falling back to %s value.', flag) ref = config.banner_main_ref if banner else config.root_ref return ref in [r['name'] for r in remotes]
[ "def", "override_root_main_ref", "(", "config", ",", "remotes", ",", "banner", ")", ":", "log", "=", "logging", ".", "getLogger", "(", "__name__", ")", "greatest_tag", "=", "config", ".", "banner_greatest_tag", "if", "banner", "else", "config", ".", "greatest_...
Override root_ref or banner_main_ref with tags in config if user requested. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param iter remotes: List of dicts from Versions.remotes. :param bool banner: Evaluate banner main ref instead of root ref. :return: If root/main ref exists. :rtype: bool
[ "Override", "root_ref", "or", "banner_main_ref", "with", "tags", "in", "config", "if", "user", "requested", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L210-L234
train
37,505
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
push
def push(ctx, config, rel_source, dest_branch, rel_dest, **options): """Build locally and then push to remote branch. First the build sub command is invoked which takes care of building all versions of your documentation in a temporary directory. If that succeeds then all built documents will be pushed to a remote branch. REL_SOURCE is the path to the docs directory relative to the git root. If the source directory has moved around between git tags you can specify additional directories. DEST_BRANCH is the branch name where generated docs will be committed to. The branch will then be pushed to remote. If there is a race condition with another job pushing to remote the docs will be re-generated and pushed again. REL_DEST is the path to the directory that will hold all generated docs for all versions relative to the git roof of DEST_BRANCH. To pass options to sphinx-build (run for every branch/tag) use a double hyphen (e.g. push docs gh-pages . -- -D setting=value). \f :param click.core.Context ctx: Click context. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py (e.g. docs). :param str dest_branch: Branch to clone and push to. :param str rel_dest: Relative path (to git root) to write generated docs to. :param dict options: Additional Click options. """ if 'pre' in config: config.pop('pre')(rel_source) config.update({k: v for k, v in options.items() if v}) if config.local_conf: config.update(read_local_conf(config.local_conf), ignore_set=True) if NO_EXECUTE: raise RuntimeError(config, rel_source, dest_branch, rel_dest) log = logging.getLogger(__name__) # Clone, build, push. for _ in range(PUSH_RETRIES): with TempDir() as temp_dir: log.info('Cloning %s into temporary directory...', dest_branch) try: clone(config.git_root, temp_dir, config.push_remote, dest_branch, rel_dest, config.grm_exclude) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError log.info('Building docs...') ctx.invoke(build, rel_source=rel_source, destination=os.path.join(temp_dir, rel_dest)) versions = config.pop('versions') log.info('Attempting to push to branch %s on remote repository.', dest_branch) try: if commit_and_push(temp_dir, config.push_remote, versions): return except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError log.warning('Failed to push to remote repository. Retrying in %d seconds...', PUSH_SLEEP) time.sleep(PUSH_SLEEP) # Failed if this is reached. log.error('Ran out of retries, giving up.') raise HandledError
python
def push(ctx, config, rel_source, dest_branch, rel_dest, **options): """Build locally and then push to remote branch. First the build sub command is invoked which takes care of building all versions of your documentation in a temporary directory. If that succeeds then all built documents will be pushed to a remote branch. REL_SOURCE is the path to the docs directory relative to the git root. If the source directory has moved around between git tags you can specify additional directories. DEST_BRANCH is the branch name where generated docs will be committed to. The branch will then be pushed to remote. If there is a race condition with another job pushing to remote the docs will be re-generated and pushed again. REL_DEST is the path to the directory that will hold all generated docs for all versions relative to the git roof of DEST_BRANCH. To pass options to sphinx-build (run for every branch/tag) use a double hyphen (e.g. push docs gh-pages . -- -D setting=value). \f :param click.core.Context ctx: Click context. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py (e.g. docs). :param str dest_branch: Branch to clone and push to. :param str rel_dest: Relative path (to git root) to write generated docs to. :param dict options: Additional Click options. """ if 'pre' in config: config.pop('pre')(rel_source) config.update({k: v for k, v in options.items() if v}) if config.local_conf: config.update(read_local_conf(config.local_conf), ignore_set=True) if NO_EXECUTE: raise RuntimeError(config, rel_source, dest_branch, rel_dest) log = logging.getLogger(__name__) # Clone, build, push. for _ in range(PUSH_RETRIES): with TempDir() as temp_dir: log.info('Cloning %s into temporary directory...', dest_branch) try: clone(config.git_root, temp_dir, config.push_remote, dest_branch, rel_dest, config.grm_exclude) except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError log.info('Building docs...') ctx.invoke(build, rel_source=rel_source, destination=os.path.join(temp_dir, rel_dest)) versions = config.pop('versions') log.info('Attempting to push to branch %s on remote repository.', dest_branch) try: if commit_and_push(temp_dir, config.push_remote, versions): return except GitError as exc: log.error(exc.message) log.error(exc.output) raise HandledError log.warning('Failed to push to remote repository. Retrying in %d seconds...', PUSH_SLEEP) time.sleep(PUSH_SLEEP) # Failed if this is reached. log.error('Ran out of retries, giving up.') raise HandledError
[ "def", "push", "(", "ctx", ",", "config", ",", "rel_source", ",", "dest_branch", ",", "rel_dest", ",", "*", "*", "options", ")", ":", "if", "'pre'", "in", "config", ":", "config", ".", "pop", "(", "'pre'", ")", "(", "rel_source", ")", "config", ".", ...
Build locally and then push to remote branch. First the build sub command is invoked which takes care of building all versions of your documentation in a temporary directory. If that succeeds then all built documents will be pushed to a remote branch. REL_SOURCE is the path to the docs directory relative to the git root. If the source directory has moved around between git tags you can specify additional directories. DEST_BRANCH is the branch name where generated docs will be committed to. The branch will then be pushed to remote. If there is a race condition with another job pushing to remote the docs will be re-generated and pushed again. REL_DEST is the path to the directory that will hold all generated docs for all versions relative to the git roof of DEST_BRANCH. To pass options to sphinx-build (run for every branch/tag) use a double hyphen (e.g. push docs gh-pages . -- -D setting=value). \f :param click.core.Context ctx: Click context. :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py (e.g. docs). :param str dest_branch: Branch to clone and push to. :param str rel_dest: Relative path (to git root) to write generated docs to. :param dict options: Additional Click options.
[ "Build", "locally", "and", "then", "push", "to", "remote", "branch", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L332-L395
train
37,506
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
ClickGroup.get_params
def get_params(self, ctx): """Sort order of options before displaying. :param click.core.Context ctx: Click context. :return: super() return value. """ self.params.sort(key=self.custom_sort) return super(ClickGroup, self).get_params(ctx)
python
def get_params(self, ctx): """Sort order of options before displaying. :param click.core.Context ctx: Click context. :return: super() return value. """ self.params.sort(key=self.custom_sort) return super(ClickGroup, self).get_params(ctx)
[ "def", "get_params", "(", "self", ",", "ctx", ")", ":", "self", ".", "params", ".", "sort", "(", "key", "=", "self", ".", "custom_sort", ")", "return", "super", "(", "ClickGroup", ",", "self", ")", ".", "get_params", "(", "ctx", ")" ]
Sort order of options before displaying. :param click.core.Context ctx: Click context. :return: super() return value.
[ "Sort", "order", "of", "options", "before", "displaying", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L54-L62
train
37,507
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
ClickGroup.main
def main(self, *args, **kwargs): """Main function called by setuptools. :param list args: Passed to super(). :param dict kwargs: Passed to super(). :return: super() return value. """ argv = kwargs.pop('args', click.get_os_args()) if '--' in argv: pos = argv.index('--') argv, self.overflow = argv[:pos], tuple(argv[pos + 1:]) else: argv, self.overflow = argv, tuple() return super(ClickGroup, self).main(args=argv, *args, **kwargs)
python
def main(self, *args, **kwargs): """Main function called by setuptools. :param list args: Passed to super(). :param dict kwargs: Passed to super(). :return: super() return value. """ argv = kwargs.pop('args', click.get_os_args()) if '--' in argv: pos = argv.index('--') argv, self.overflow = argv[:pos], tuple(argv[pos + 1:]) else: argv, self.overflow = argv, tuple() return super(ClickGroup, self).main(args=argv, *args, **kwargs)
[ "def", "main", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "argv", "=", "kwargs", ".", "pop", "(", "'args'", ",", "click", ".", "get_os_args", "(", ")", ")", "if", "'--'", "in", "argv", ":", "pos", "=", "argv", ".", "index...
Main function called by setuptools. :param list args: Passed to super(). :param dict kwargs: Passed to super(). :return: super() return value.
[ "Main", "function", "called", "by", "setuptools", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L64-L78
train
37,508
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/__main__.py
ClickGroup.invoke
def invoke(self, ctx): """Inject overflow arguments into context state. :param click.core.Context ctx: Click context. :return: super() return value. """ if self.overflow: ctx.ensure_object(Config).update(dict(overflow=self.overflow)) return super(ClickGroup, self).invoke(ctx)
python
def invoke(self, ctx): """Inject overflow arguments into context state. :param click.core.Context ctx: Click context. :return: super() return value. """ if self.overflow: ctx.ensure_object(Config).update(dict(overflow=self.overflow)) return super(ClickGroup, self).invoke(ctx)
[ "def", "invoke", "(", "self", ",", "ctx", ")", ":", "if", "self", ".", "overflow", ":", "ctx", ".", "ensure_object", "(", "Config", ")", ".", "update", "(", "dict", "(", "overflow", "=", "self", ".", "overflow", ")", ")", "return", "super", "(", "C...
Inject overflow arguments into context state. :param click.core.Context ctx: Click context. :return: super() return value.
[ "Inject", "overflow", "arguments", "into", "context", "state", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/__main__.py#L80-L89
train
37,509
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/lib.py
Config.from_context
def from_context(cls): """Retrieve this class' instance from the current Click context. :return: Instance of this class. :rtype: Config """ try: ctx = click.get_current_context() except RuntimeError: return cls() return ctx.find_object(cls)
python
def from_context(cls): """Retrieve this class' instance from the current Click context. :return: Instance of this class. :rtype: Config """ try: ctx = click.get_current_context() except RuntimeError: return cls() return ctx.find_object(cls)
[ "def", "from_context", "(", "cls", ")", ":", "try", ":", "ctx", "=", "click", ".", "get_current_context", "(", ")", "except", "RuntimeError", ":", "return", "cls", "(", ")", "return", "ctx", ".", "find_object", "(", "cls", ")" ]
Retrieve this class' instance from the current Click context. :return: Instance of this class. :rtype: Config
[ "Retrieve", "this", "class", "instance", "from", "the", "current", "Click", "context", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/lib.py#L81-L91
train
37,510
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/lib.py
Config.update
def update(self, params, ignore_set=False, overwrite=False): """Set instance values from dictionary. :param dict params: Click context params. :param bool ignore_set: Skip already-set values instead of raising AttributeError. :param bool overwrite: Allow overwriting already-set values. """ log = logging.getLogger(__name__) valid = {i[0] for i in self} for key, value in params.items(): if not hasattr(self, key): raise AttributeError("'{}' object has no attribute '{}'".format(self.__class__.__name__, key)) if key not in valid: message = "'{}' object does not support item assignment on '{}'" raise AttributeError(message.format(self.__class__.__name__, key)) if key in self._already_set: if ignore_set: log.debug('%s already set in config, skipping.', key) continue if not overwrite: message = "'{}' object does not support item re-assignment on '{}'" raise AttributeError(message.format(self.__class__.__name__, key)) setattr(self, key, value) self._already_set.add(key)
python
def update(self, params, ignore_set=False, overwrite=False): """Set instance values from dictionary. :param dict params: Click context params. :param bool ignore_set: Skip already-set values instead of raising AttributeError. :param bool overwrite: Allow overwriting already-set values. """ log = logging.getLogger(__name__) valid = {i[0] for i in self} for key, value in params.items(): if not hasattr(self, key): raise AttributeError("'{}' object has no attribute '{}'".format(self.__class__.__name__, key)) if key not in valid: message = "'{}' object does not support item assignment on '{}'" raise AttributeError(message.format(self.__class__.__name__, key)) if key in self._already_set: if ignore_set: log.debug('%s already set in config, skipping.', key) continue if not overwrite: message = "'{}' object does not support item re-assignment on '{}'" raise AttributeError(message.format(self.__class__.__name__, key)) setattr(self, key, value) self._already_set.add(key)
[ "def", "update", "(", "self", ",", "params", ",", "ignore_set", "=", "False", ",", "overwrite", "=", "False", ")", ":", "log", "=", "logging", ".", "getLogger", "(", "__name__", ")", "valid", "=", "{", "i", "[", "0", "]", "for", "i", "in", "self", ...
Set instance values from dictionary. :param dict params: Click context params. :param bool ignore_set: Skip already-set values instead of raising AttributeError. :param bool overwrite: Allow overwriting already-set values.
[ "Set", "instance", "values", "from", "dictionary", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/lib.py#L102-L125
train
37,511
Robpol86/sphinxcontrib-versioning
sphinxcontrib/versioning/lib.py
TempDir.cleanup
def cleanup(self): """Recursively delete directory.""" shutil.rmtree(self.name, onerror=lambda *a: os.chmod(a[1], __import__('stat').S_IWRITE) or os.unlink(a[1])) if os.path.exists(self.name): raise IOError(17, "File exists: '{}'".format(self.name))
python
def cleanup(self): """Recursively delete directory.""" shutil.rmtree(self.name, onerror=lambda *a: os.chmod(a[1], __import__('stat').S_IWRITE) or os.unlink(a[1])) if os.path.exists(self.name): raise IOError(17, "File exists: '{}'".format(self.name))
[ "def", "cleanup", "(", "self", ")", ":", "shutil", ".", "rmtree", "(", "self", ".", "name", ",", "onerror", "=", "lambda", "*", "a", ":", "os", ".", "chmod", "(", "a", "[", "1", "]", ",", "__import__", "(", "'stat'", ")", ".", "S_IWRITE", ")", ...
Recursively delete directory.
[ "Recursively", "delete", "directory", "." ]
920edec0ac764081b583a2ecf4e6952762b9dbf2
https://github.com/Robpol86/sphinxcontrib-versioning/blob/920edec0ac764081b583a2ecf4e6952762b9dbf2/sphinxcontrib/versioning/lib.py#L165-L169
train
37,512
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/trunk.py
NexusMDTrunkHandler.update_subports
def update_subports(self, port): """Set port attributes for trunk subports. For baremetal deployments only, set the neutron port attributes during the bind_port event. """ trunk_details = port.get('trunk_details') subports = trunk_details['sub_ports'] host_id = port.get(bc.dns.DNSNAME) context = bc.get_context() el_context = context.elevated() for subport in subports: bc.get_plugin().update_port(el_context, subport['port_id'], {'port': {bc.portbindings.HOST_ID: host_id, 'device_owner': bc.trunk_consts.TRUNK_SUBPORT_OWNER}}) # Set trunk to ACTIVE status. trunk_obj = bc.trunk_objects.Trunk.get_object( el_context, id=trunk_details['trunk_id']) trunk_obj.update(status=bc.trunk_consts.ACTIVE_STATUS)
python
def update_subports(self, port): """Set port attributes for trunk subports. For baremetal deployments only, set the neutron port attributes during the bind_port event. """ trunk_details = port.get('trunk_details') subports = trunk_details['sub_ports'] host_id = port.get(bc.dns.DNSNAME) context = bc.get_context() el_context = context.elevated() for subport in subports: bc.get_plugin().update_port(el_context, subport['port_id'], {'port': {bc.portbindings.HOST_ID: host_id, 'device_owner': bc.trunk_consts.TRUNK_SUBPORT_OWNER}}) # Set trunk to ACTIVE status. trunk_obj = bc.trunk_objects.Trunk.get_object( el_context, id=trunk_details['trunk_id']) trunk_obj.update(status=bc.trunk_consts.ACTIVE_STATUS)
[ "def", "update_subports", "(", "self", ",", "port", ")", ":", "trunk_details", "=", "port", ".", "get", "(", "'trunk_details'", ")", "subports", "=", "trunk_details", "[", "'sub_ports'", "]", "host_id", "=", "port", ".", "get", "(", "bc", ".", "dns", "."...
Set port attributes for trunk subports. For baremetal deployments only, set the neutron port attributes during the bind_port event.
[ "Set", "port", "attributes", "for", "trunk", "subports", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/trunk.py#L52-L74
train
37,513
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.read_static_uplink
def read_static_uplink(self): """Read the static uplink from file, if given.""" if self.node_list is None or self.node_uplink_list is None: return for node, port in zip(self.node_list.split(','), self.node_uplink_list.split(',')): if node.strip() == self.host_name: self.static_uplink = True self.static_uplink_port = port.strip() return
python
def read_static_uplink(self): """Read the static uplink from file, if given.""" if self.node_list is None or self.node_uplink_list is None: return for node, port in zip(self.node_list.split(','), self.node_uplink_list.split(',')): if node.strip() == self.host_name: self.static_uplink = True self.static_uplink_port = port.strip() return
[ "def", "read_static_uplink", "(", "self", ")", ":", "if", "self", ".", "node_list", "is", "None", "or", "self", ".", "node_uplink_list", "is", "None", ":", "return", "for", "node", ",", "port", "in", "zip", "(", "self", ".", "node_list", ".", "split", ...
Read the static uplink from file, if given.
[ "Read", "the", "static", "uplink", "from", "file", "if", "given", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L168-L177
train
37,514
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.vdp_vlan_change_cb
def vdp_vlan_change_cb(self, port_uuid, lvid, vdp_vlan, fail_reason): """Callback function for updating the VDP VLAN in DB. """ LOG.info("Vlan change CB lvid %(lvid)s VDP %(vdp)s", {'lvid': lvid, 'vdp': vdp_vlan}) self.update_vm_result(port_uuid, constants.RESULT_SUCCESS, lvid=lvid, vdp_vlan=vdp_vlan, fail_reason=fail_reason)
python
def vdp_vlan_change_cb(self, port_uuid, lvid, vdp_vlan, fail_reason): """Callback function for updating the VDP VLAN in DB. """ LOG.info("Vlan change CB lvid %(lvid)s VDP %(vdp)s", {'lvid': lvid, 'vdp': vdp_vlan}) self.update_vm_result(port_uuid, constants.RESULT_SUCCESS, lvid=lvid, vdp_vlan=vdp_vlan, fail_reason=fail_reason)
[ "def", "vdp_vlan_change_cb", "(", "self", ",", "port_uuid", ",", "lvid", ",", "vdp_vlan", ",", "fail_reason", ")", ":", "LOG", ".", "info", "(", "\"Vlan change CB lvid %(lvid)s VDP %(vdp)s\"", ",", "{", "'lvid'", ":", "lvid", ",", "'vdp'", ":", "vdp_vlan", "}"...
Callback function for updating the VDP VLAN in DB.
[ "Callback", "function", "for", "updating", "the", "VDP", "VLAN", "in", "DB", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L200-L206
train
37,515
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.process_bulk_vm_event
def process_bulk_vm_event(self, msg, phy_uplink): """Process the VM bulk event usually after a restart. """ LOG.info("In processing Bulk VM Event status %s", msg) time.sleep(3) if (not self.uplink_det_compl or phy_uplink not in self.ovs_vdp_obj_dict): # This condition shouldn't be hit as only when uplink is obtained, # save_uplink is called and that in turns calls this process_bulk. LOG.error("Uplink Port Event not received," "yet in bulk process") return ovs_vdp_obj = self.ovs_vdp_obj_dict[phy_uplink] for vm_dict in msg.msg_dict.get('vm_bulk_list'): if vm_dict['status'] == 'down': ovs_vdp_obj.pop_local_cache(vm_dict['port_uuid'], vm_dict['vm_mac'], vm_dict['net_uuid'], vm_dict['local_vlan'], vm_dict['vdp_vlan'], vm_dict['segmentation_id']) vm_msg = VdpQueMsg(constants.VM_MSG_TYPE, port_uuid=vm_dict['port_uuid'], vm_mac=vm_dict['vm_mac'], net_uuid=vm_dict['net_uuid'], segmentation_id=vm_dict['segmentation_id'], status=vm_dict['status'], oui=vm_dict['oui'], phy_uplink=phy_uplink) self.process_vm_event(vm_msg, phy_uplink)
python
def process_bulk_vm_event(self, msg, phy_uplink): """Process the VM bulk event usually after a restart. """ LOG.info("In processing Bulk VM Event status %s", msg) time.sleep(3) if (not self.uplink_det_compl or phy_uplink not in self.ovs_vdp_obj_dict): # This condition shouldn't be hit as only when uplink is obtained, # save_uplink is called and that in turns calls this process_bulk. LOG.error("Uplink Port Event not received," "yet in bulk process") return ovs_vdp_obj = self.ovs_vdp_obj_dict[phy_uplink] for vm_dict in msg.msg_dict.get('vm_bulk_list'): if vm_dict['status'] == 'down': ovs_vdp_obj.pop_local_cache(vm_dict['port_uuid'], vm_dict['vm_mac'], vm_dict['net_uuid'], vm_dict['local_vlan'], vm_dict['vdp_vlan'], vm_dict['segmentation_id']) vm_msg = VdpQueMsg(constants.VM_MSG_TYPE, port_uuid=vm_dict['port_uuid'], vm_mac=vm_dict['vm_mac'], net_uuid=vm_dict['net_uuid'], segmentation_id=vm_dict['segmentation_id'], status=vm_dict['status'], oui=vm_dict['oui'], phy_uplink=phy_uplink) self.process_vm_event(vm_msg, phy_uplink)
[ "def", "process_bulk_vm_event", "(", "self", ",", "msg", ",", "phy_uplink", ")", ":", "LOG", ".", "info", "(", "\"In processing Bulk VM Event status %s\"", ",", "msg", ")", "time", ".", "sleep", "(", "3", ")", "if", "(", "not", "self", ".", "uplink_det_compl...
Process the VM bulk event usually after a restart.
[ "Process", "the", "VM", "bulk", "event", "usually", "after", "a", "restart", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L241-L269
train
37,516
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.is_openstack_running
def is_openstack_running(self): """Currently it just checks for the presence of both the bridges. """ try: if (ovs_vdp.is_bridge_present(self.br_ex, self.root_helper) and ovs_vdp.is_bridge_present(self.br_integ, self.root_helper)): return True else: return False except Exception as e: LOG.error("Exception in is_openstack_running %s", str(e)) return False
python
def is_openstack_running(self): """Currently it just checks for the presence of both the bridges. """ try: if (ovs_vdp.is_bridge_present(self.br_ex, self.root_helper) and ovs_vdp.is_bridge_present(self.br_integ, self.root_helper)): return True else: return False except Exception as e: LOG.error("Exception in is_openstack_running %s", str(e)) return False
[ "def", "is_openstack_running", "(", "self", ")", ":", "try", ":", "if", "(", "ovs_vdp", ".", "is_bridge_present", "(", "self", ".", "br_ex", ",", "self", ".", "root_helper", ")", "and", "ovs_vdp", ".", "is_bridge_present", "(", "self", ".", "br_integ", ","...
Currently it just checks for the presence of both the bridges.
[ "Currently", "it", "just", "checks", "for", "the", "presence", "of", "both", "the", "bridges", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L368-L379
train
37,517
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr._fill_topology_cfg
def _fill_topology_cfg(self, topo_dict): """Fills the extra configurations in the topology. """ cfg_dict = {} if topo_dict.bond_member_ports is not None: cfg_dict.update({'bond_member_ports': topo_dict.bond_member_ports}) if topo_dict.bond_interface is not None: cfg_dict.update({'bond_interface': topo_dict.bond_interface}) return cfg_dict
python
def _fill_topology_cfg(self, topo_dict): """Fills the extra configurations in the topology. """ cfg_dict = {} if topo_dict.bond_member_ports is not None: cfg_dict.update({'bond_member_ports': topo_dict.bond_member_ports}) if topo_dict.bond_interface is not None: cfg_dict.update({'bond_interface': topo_dict.bond_interface}) return cfg_dict
[ "def", "_fill_topology_cfg", "(", "self", ",", "topo_dict", ")", ":", "cfg_dict", "=", "{", "}", "if", "topo_dict", ".", "bond_member_ports", "is", "not", "None", ":", "cfg_dict", ".", "update", "(", "{", "'bond_member_ports'", ":", "topo_dict", ".", "bond_m...
Fills the extra configurations in the topology.
[ "Fills", "the", "extra", "configurations", "in", "the", "topology", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L404-L413
train
37,518
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.uplink_bond_intf_process
def uplink_bond_intf_process(self): """Process the case when uplink interface becomes part of a bond. This is called to check if the phy interface became a part of the bond. If the below condition is True, this means, a physical interface that was not a part of a bond was earlier discovered as uplink and now that interface became part of the bond. Usually, this doesn't happen as LLDP and in turn this function will first detect a 'down' followed by an 'up'. When regular interface becomes part of bond, it's rare for it to hit this 'normal' case. But, still providing the functionality if it happens. The following is done : a. Bring down the physical interface by sending a 'down' event b. Add the bond interface by sending an 'up' event Consquently, when bond is added that will be assigned to self.phy_uplink. Then, the below condition will be False. i.e.. 'get_bond_intf' will return False, when the argument is 'bond0'. """ bond_intf = sys_utils.get_bond_intf(self.phy_uplink) if bond_intf is None: return False self.save_uplink( fail_reason=constants.port_transition_bond_down_reason) self.process_uplink_ongoing = True upl_msg = VdpQueMsg(constants.UPLINK_MSG_TYPE, status='down', phy_uplink=self.phy_uplink, br_int=self.br_integ, br_ex=self.br_ex, root_helper=self.root_helper) self.que.enqueue(constants.Q_UPL_PRIO, upl_msg) self.phy_uplink = None self.veth_intf = None self.uplink_det_compl = False # No veth interface self.save_uplink( uplink=bond_intf, fail_reason=constants.port_transition_bond_up_reason) self.phy_uplink = bond_intf self.process_uplink_ongoing = True upl_msg = VdpQueMsg(constants.UPLINK_MSG_TYPE, status='up', phy_uplink=self.phy_uplink, br_int=self.br_integ, br_ex=self.br_ex, root_helper=self.root_helper) self.que.enqueue(constants.Q_UPL_PRIO, upl_msg) return True
python
def uplink_bond_intf_process(self): """Process the case when uplink interface becomes part of a bond. This is called to check if the phy interface became a part of the bond. If the below condition is True, this means, a physical interface that was not a part of a bond was earlier discovered as uplink and now that interface became part of the bond. Usually, this doesn't happen as LLDP and in turn this function will first detect a 'down' followed by an 'up'. When regular interface becomes part of bond, it's rare for it to hit this 'normal' case. But, still providing the functionality if it happens. The following is done : a. Bring down the physical interface by sending a 'down' event b. Add the bond interface by sending an 'up' event Consquently, when bond is added that will be assigned to self.phy_uplink. Then, the below condition will be False. i.e.. 'get_bond_intf' will return False, when the argument is 'bond0'. """ bond_intf = sys_utils.get_bond_intf(self.phy_uplink) if bond_intf is None: return False self.save_uplink( fail_reason=constants.port_transition_bond_down_reason) self.process_uplink_ongoing = True upl_msg = VdpQueMsg(constants.UPLINK_MSG_TYPE, status='down', phy_uplink=self.phy_uplink, br_int=self.br_integ, br_ex=self.br_ex, root_helper=self.root_helper) self.que.enqueue(constants.Q_UPL_PRIO, upl_msg) self.phy_uplink = None self.veth_intf = None self.uplink_det_compl = False # No veth interface self.save_uplink( uplink=bond_intf, fail_reason=constants.port_transition_bond_up_reason) self.phy_uplink = bond_intf self.process_uplink_ongoing = True upl_msg = VdpQueMsg(constants.UPLINK_MSG_TYPE, status='up', phy_uplink=self.phy_uplink, br_int=self.br_integ, br_ex=self.br_ex, root_helper=self.root_helper) self.que.enqueue(constants.Q_UPL_PRIO, upl_msg) return True
[ "def", "uplink_bond_intf_process", "(", "self", ")", ":", "bond_intf", "=", "sys_utils", ".", "get_bond_intf", "(", "self", ".", "phy_uplink", ")", "if", "bond_intf", "is", "None", ":", "return", "False", "self", ".", "save_uplink", "(", "fail_reason", "=", ...
Process the case when uplink interface becomes part of a bond. This is called to check if the phy interface became a part of the bond. If the below condition is True, this means, a physical interface that was not a part of a bond was earlier discovered as uplink and now that interface became part of the bond. Usually, this doesn't happen as LLDP and in turn this function will first detect a 'down' followed by an 'up'. When regular interface becomes part of bond, it's rare for it to hit this 'normal' case. But, still providing the functionality if it happens. The following is done : a. Bring down the physical interface by sending a 'down' event b. Add the bond interface by sending an 'up' event Consquently, when bond is added that will be assigned to self.phy_uplink. Then, the below condition will be False. i.e.. 'get_bond_intf' will return False, when the argument is 'bond0'.
[ "Process", "the", "case", "when", "uplink", "interface", "becomes", "part", "of", "a", "bond", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L439-L483
train
37,519
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.check_periodic_bulk_vm_notif_rcvd
def check_periodic_bulk_vm_notif_rcvd(self): """Bulk VM check handler called from periodic uplink detection. This gets called by the 'normal' stage of uplink detection. The bulk VM event sends all the VM's running in this agent. Sometimes during upgrades, it was found that due to some race condition, the server does not send the Bulk VM event. Whenever, a save_uplink is done by the agent, the server sends the Bulk VM event. If Bulk VM event is not received after few attempts, save_uplink is done to request the Bulk VM list. It's not protected with a mutex, since worst case, Bulk VM event will be sent twice, which is not that bad. When uplink is detected for the first time, it will hit the below else case and there a save_uplink is anyways done. """ if not self.bulk_vm_rcvd_flag: if self.bulk_vm_check_cnt >= 1: self.bulk_vm_check_cnt = 0 self.save_uplink(uplink=self.phy_uplink, veth_intf=self.veth_intf) LOG.info("Doing save_uplink again to request " "Bulk VM's") else: LOG.info("Bulk VM not received, incrementing count") self.bulk_vm_check_cnt += 1
python
def check_periodic_bulk_vm_notif_rcvd(self): """Bulk VM check handler called from periodic uplink detection. This gets called by the 'normal' stage of uplink detection. The bulk VM event sends all the VM's running in this agent. Sometimes during upgrades, it was found that due to some race condition, the server does not send the Bulk VM event. Whenever, a save_uplink is done by the agent, the server sends the Bulk VM event. If Bulk VM event is not received after few attempts, save_uplink is done to request the Bulk VM list. It's not protected with a mutex, since worst case, Bulk VM event will be sent twice, which is not that bad. When uplink is detected for the first time, it will hit the below else case and there a save_uplink is anyways done. """ if not self.bulk_vm_rcvd_flag: if self.bulk_vm_check_cnt >= 1: self.bulk_vm_check_cnt = 0 self.save_uplink(uplink=self.phy_uplink, veth_intf=self.veth_intf) LOG.info("Doing save_uplink again to request " "Bulk VM's") else: LOG.info("Bulk VM not received, incrementing count") self.bulk_vm_check_cnt += 1
[ "def", "check_periodic_bulk_vm_notif_rcvd", "(", "self", ")", ":", "if", "not", "self", ".", "bulk_vm_rcvd_flag", ":", "if", "self", ".", "bulk_vm_check_cnt", ">=", "1", ":", "self", ".", "bulk_vm_check_cnt", "=", "0", "self", ".", "save_uplink", "(", "uplink"...
Bulk VM check handler called from periodic uplink detection. This gets called by the 'normal' stage of uplink detection. The bulk VM event sends all the VM's running in this agent. Sometimes during upgrades, it was found that due to some race condition, the server does not send the Bulk VM event. Whenever, a save_uplink is done by the agent, the server sends the Bulk VM event. If Bulk VM event is not received after few attempts, save_uplink is done to request the Bulk VM list. It's not protected with a mutex, since worst case, Bulk VM event will be sent twice, which is not that bad. When uplink is detected for the first time, it will hit the below else case and there a save_uplink is anyways done.
[ "Bulk", "VM", "check", "handler", "called", "from", "periodic", "uplink", "detection", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L485-L510
train
37,520
openstack/networking-cisco
networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py
VdpMgr.static_uplink_detect
def static_uplink_detect(self, veth): """Return the static uplink based on argument passed. The very first time, this function is called, it returns the uplink port read from a file. After restart, when this function is called the first time, it returns 'normal' assuming a veth is passed to this function which will be the case if uplink processing is successfully done. If user modified the uplink configuration and restarted, a 'down' will be returned to clear the old uplink. """ LOG.info("In static_uplink_detect %(veth)s", {'veth': veth}) if self.static_uplink_first: self.static_uplink_first = False if self.phy_uplink is not None and ( self.phy_uplink != self.static_uplink_port): return 'down' if veth is None: return self.static_uplink_port else: return 'normal'
python
def static_uplink_detect(self, veth): """Return the static uplink based on argument passed. The very first time, this function is called, it returns the uplink port read from a file. After restart, when this function is called the first time, it returns 'normal' assuming a veth is passed to this function which will be the case if uplink processing is successfully done. If user modified the uplink configuration and restarted, a 'down' will be returned to clear the old uplink. """ LOG.info("In static_uplink_detect %(veth)s", {'veth': veth}) if self.static_uplink_first: self.static_uplink_first = False if self.phy_uplink is not None and ( self.phy_uplink != self.static_uplink_port): return 'down' if veth is None: return self.static_uplink_port else: return 'normal'
[ "def", "static_uplink_detect", "(", "self", ",", "veth", ")", ":", "LOG", ".", "info", "(", "\"In static_uplink_detect %(veth)s\"", ",", "{", "'veth'", ":", "veth", "}", ")", "if", "self", ".", "static_uplink_first", ":", "self", ".", "static_uplink_first", "=...
Return the static uplink based on argument passed. The very first time, this function is called, it returns the uplink port read from a file. After restart, when this function is called the first time, it returns 'normal' assuming a veth is passed to this function which will be the case if uplink processing is successfully done. If user modified the uplink configuration and restarted, a 'down' will be returned to clear the old uplink.
[ "Return", "the", "static", "uplink", "based", "on", "argument", "passed", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/vdp/dfa_vdp_mgr.py#L512-L532
train
37,521
openstack/networking-cisco
networking_cisco/neutronclient/hostingdevice.py
HostingDeviceGetConfig.get_hosting_device_config
def get_hosting_device_config(self, client, hosting_device_id): """Get config of hosting_device.""" return client.get((self.resource_path + HOSTING_DEVICE_CONFIG) % hosting_device_id)
python
def get_hosting_device_config(self, client, hosting_device_id): """Get config of hosting_device.""" return client.get((self.resource_path + HOSTING_DEVICE_CONFIG) % hosting_device_id)
[ "def", "get_hosting_device_config", "(", "self", ",", "client", ",", "hosting_device_id", ")", ":", "return", "client", ".", "get", "(", "(", "self", ".", "resource_path", "+", "HOSTING_DEVICE_CONFIG", ")", "%", "hosting_device_id", ")" ]
Get config of hosting_device.
[ "Get", "config", "of", "hosting_device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/neutronclient/hostingdevice.py#L255-L258
train
37,522
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.get_client_class
def get_client_class(self, client_class_name): """Returns a specific client class details from CPNR server.""" request_url = self._build_url(['ClientClass', client_class_name]) return self._do_request('GET', request_url)
python
def get_client_class(self, client_class_name): """Returns a specific client class details from CPNR server.""" request_url = self._build_url(['ClientClass', client_class_name]) return self._do_request('GET', request_url)
[ "def", "get_client_class", "(", "self", ",", "client_class_name", ")", ":", "request_url", "=", "self", ".", "_build_url", "(", "[", "'ClientClass'", ",", "client_class_name", "]", ")", "return", "self", ".", "_do_request", "(", "'GET'", ",", "request_url", ")...
Returns a specific client class details from CPNR server.
[ "Returns", "a", "specific", "client", "class", "details", "from", "CPNR", "server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L125-L128
train
37,523
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.get_vpn
def get_vpn(self, vpn_name): """Returns a specific VPN name details from CPNR server.""" request_url = self._build_url(['VPN', vpn_name]) return self._do_request('GET', request_url)
python
def get_vpn(self, vpn_name): """Returns a specific VPN name details from CPNR server.""" request_url = self._build_url(['VPN', vpn_name]) return self._do_request('GET', request_url)
[ "def", "get_vpn", "(", "self", ",", "vpn_name", ")", ":", "request_url", "=", "self", ".", "_build_url", "(", "[", "'VPN'", ",", "vpn_name", "]", ")", "return", "self", ".", "_do_request", "(", "'GET'", ",", "request_url", ")" ]
Returns a specific VPN name details from CPNR server.
[ "Returns", "a", "specific", "VPN", "name", "details", "from", "CPNR", "server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L135-L138
train
37,524
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.get_scopes
def get_scopes(self, vpnid='.*'): """Returns a list of all the scopes from CPNR server.""" request_url = self._build_url(['Scope'], vpn=vpnid) return self._do_request('GET', request_url)
python
def get_scopes(self, vpnid='.*'): """Returns a list of all the scopes from CPNR server.""" request_url = self._build_url(['Scope'], vpn=vpnid) return self._do_request('GET', request_url)
[ "def", "get_scopes", "(", "self", ",", "vpnid", "=", "'.*'", ")", ":", "request_url", "=", "self", ".", "_build_url", "(", "[", "'Scope'", "]", ",", "vpn", "=", "vpnid", ")", "return", "self", ".", "_do_request", "(", "'GET'", ",", "request_url", ")" ]
Returns a list of all the scopes from CPNR server.
[ "Returns", "a", "list", "of", "all", "the", "scopes", "from", "CPNR", "server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L140-L143
train
37,525
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.get_scope
def get_scope(self, scope_name): """Returns a specific scope name details from CPNR server.""" request_url = self._build_url(['Scope', scope_name]) return self._do_request('GET', request_url)
python
def get_scope(self, scope_name): """Returns a specific scope name details from CPNR server.""" request_url = self._build_url(['Scope', scope_name]) return self._do_request('GET', request_url)
[ "def", "get_scope", "(", "self", ",", "scope_name", ")", ":", "request_url", "=", "self", ".", "_build_url", "(", "[", "'Scope'", ",", "scope_name", "]", ")", "return", "self", ".", "_do_request", "(", "'GET'", ",", "request_url", ")" ]
Returns a specific scope name details from CPNR server.
[ "Returns", "a", "specific", "scope", "name", "details", "from", "CPNR", "server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L145-L148
train
37,526
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.get_client_entry
def get_client_entry(self, client_entry_name): """Returns a specific client entry name details from CPNR server.""" request_url = self._build_url(['ClientEntry', client_entry_name]) return self._do_request('GET', request_url)
python
def get_client_entry(self, client_entry_name): """Returns a specific client entry name details from CPNR server.""" request_url = self._build_url(['ClientEntry', client_entry_name]) return self._do_request('GET', request_url)
[ "def", "get_client_entry", "(", "self", ",", "client_entry_name", ")", ":", "request_url", "=", "self", ".", "_build_url", "(", "[", "'ClientEntry'", ",", "client_entry_name", "]", ")", "return", "self", ".", "_do_request", "(", "'GET'", ",", "request_url", ")...
Returns a specific client entry name details from CPNR server.
[ "Returns", "a", "specific", "client", "entry", "name", "details", "from", "CPNR", "server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L155-L158
train
37,527
openstack/networking-cisco
networking_cisco/plugins/cisco/cpnr/cpnr_client.py
CpnrClient.release_address
def release_address(self, address, vpnid): """Release a specific lease, called after delete_client_entry""" query = address + "?action=releaseAddress&vpnId=" + vpnid request_url = self._build_url(['Lease', query]) return self._do_request('DELETE', request_url)
python
def release_address(self, address, vpnid): """Release a specific lease, called after delete_client_entry""" query = address + "?action=releaseAddress&vpnId=" + vpnid request_url = self._build_url(['Lease', query]) return self._do_request('DELETE', request_url)
[ "def", "release_address", "(", "self", ",", "address", ",", "vpnid", ")", ":", "query", "=", "address", "+", "\"?action=releaseAddress&vpnId=\"", "+", "vpnid", "request_url", "=", "self", ".", "_build_url", "(", "[", "'Lease'", ",", "query", "]", ")", "retur...
Release a specific lease, called after delete_client_entry
[ "Release", "a", "specific", "lease", "called", "after", "delete_client_entry" ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cpnr/cpnr_client.py#L346-L350
train
37,528
openstack/networking-cisco
networking_cisco/plugins/cisco/cfg_agent/service_helpers/service_helper.py
QueueMixin.qsize
def qsize(self, qname): """Return the approximate size of the queue.""" if qname in self._queues: return self._queues[qname].qsize() else: raise ValueError(_("queue %s is not defined"), qname)
python
def qsize(self, qname): """Return the approximate size of the queue.""" if qname in self._queues: return self._queues[qname].qsize() else: raise ValueError(_("queue %s is not defined"), qname)
[ "def", "qsize", "(", "self", ",", "qname", ")", ":", "if", "qname", "in", "self", ".", "_queues", ":", "return", "self", ".", "_queues", "[", "qname", "]", ".", "qsize", "(", ")", "else", ":", "raise", "ValueError", "(", "_", "(", "\"queue %s is not ...
Return the approximate size of the queue.
[ "Return", "the", "approximate", "size", "of", "the", "queue", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/plugins/cisco/cfg_agent/service_helpers/service_helper.py#L92-L97
train
37,529
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
get_nexusport_binding
def get_nexusport_binding(port_id, vlan_id, switch_ip, instance_id): """Lists a nexusport binding.""" LOG.debug("get_nexusport_binding() called") return _lookup_all_nexus_bindings(port_id=port_id, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id)
python
def get_nexusport_binding(port_id, vlan_id, switch_ip, instance_id): """Lists a nexusport binding.""" LOG.debug("get_nexusport_binding() called") return _lookup_all_nexus_bindings(port_id=port_id, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id)
[ "def", "get_nexusport_binding", "(", "port_id", ",", "vlan_id", ",", "switch_ip", ",", "instance_id", ")", ":", "LOG", ".", "debug", "(", "\"get_nexusport_binding() called\"", ")", "return", "_lookup_all_nexus_bindings", "(", "port_id", "=", "port_id", ",", "vlan_id...
Lists a nexusport binding.
[ "Lists", "a", "nexusport", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L37-L43
train
37,530
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
get_nexus_switchport_binding
def get_nexus_switchport_binding(port_id, switch_ip): """Lists all bindings for this switch & port.""" LOG.debug("get_nexus_switchport_binding() called") return _lookup_all_nexus_bindings(port_id=port_id, switch_ip=switch_ip)
python
def get_nexus_switchport_binding(port_id, switch_ip): """Lists all bindings for this switch & port.""" LOG.debug("get_nexus_switchport_binding() called") return _lookup_all_nexus_bindings(port_id=port_id, switch_ip=switch_ip)
[ "def", "get_nexus_switchport_binding", "(", "port_id", ",", "switch_ip", ")", ":", "LOG", ".", "debug", "(", "\"get_nexus_switchport_binding() called\"", ")", "return", "_lookup_all_nexus_bindings", "(", "port_id", "=", "port_id", ",", "switch_ip", "=", "switch_ip", "...
Lists all bindings for this switch & port.
[ "Lists", "all", "bindings", "for", "this", "switch", "&", "port", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L46-L50
train
37,531
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
get_nexusvlan_binding
def get_nexusvlan_binding(vlan_id, switch_ip): """Lists a vlan and switch binding.""" LOG.debug("get_nexusvlan_binding() called") return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip)
python
def get_nexusvlan_binding(vlan_id, switch_ip): """Lists a vlan and switch binding.""" LOG.debug("get_nexusvlan_binding() called") return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip)
[ "def", "get_nexusvlan_binding", "(", "vlan_id", ",", "switch_ip", ")", ":", "LOG", ".", "debug", "(", "\"get_nexusvlan_binding() called\"", ")", "return", "_lookup_all_nexus_bindings", "(", "vlan_id", "=", "vlan_id", ",", "switch_ip", "=", "switch_ip", ")" ]
Lists a vlan and switch binding.
[ "Lists", "a", "vlan", "and", "switch", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L53-L56
train
37,532
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
get_reserved_bindings
def get_reserved_bindings(vlan_id, instance_id, switch_ip=None, port_id=None): """Lists reserved bindings.""" LOG.debug("get_reserved_bindings() called") if port_id: return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) elif switch_ip: return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id) else: return _lookup_all_nexus_bindings(vlan_id=vlan_id, instance_id=instance_id)
python
def get_reserved_bindings(vlan_id, instance_id, switch_ip=None, port_id=None): """Lists reserved bindings.""" LOG.debug("get_reserved_bindings() called") if port_id: return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) elif switch_ip: return _lookup_all_nexus_bindings(vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id) else: return _lookup_all_nexus_bindings(vlan_id=vlan_id, instance_id=instance_id)
[ "def", "get_reserved_bindings", "(", "vlan_id", ",", "instance_id", ",", "switch_ip", "=", "None", ",", "port_id", "=", "None", ")", ":", "LOG", ".", "debug", "(", "\"get_reserved_bindings() called\"", ")", "if", "port_id", ":", "return", "_lookup_all_nexus_bindin...
Lists reserved bindings.
[ "Lists", "reserved", "bindings", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L59-L74
train
37,533
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
update_reserved_binding
def update_reserved_binding(vlan_id, switch_ip, instance_id, port_id, is_switch_binding=True, is_native=False, ch_grp=0): """Updates reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id :param ch_grp: 0 if no port-channel else non-zero integer """ if not port_id: LOG.warning("update_reserved_binding called with no state") return LOG.debug("update_reserved_binding called") session = bc.get_writer_session() if is_switch_binding: # For reserved switch binding binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id) binding.port_id = port_id else: # For reserved port binding binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) binding.is_native = is_native binding.channel_group = ch_grp session.merge(binding) session.flush() return binding
python
def update_reserved_binding(vlan_id, switch_ip, instance_id, port_id, is_switch_binding=True, is_native=False, ch_grp=0): """Updates reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id :param ch_grp: 0 if no port-channel else non-zero integer """ if not port_id: LOG.warning("update_reserved_binding called with no state") return LOG.debug("update_reserved_binding called") session = bc.get_writer_session() if is_switch_binding: # For reserved switch binding binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id) binding.port_id = port_id else: # For reserved port binding binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) binding.is_native = is_native binding.channel_group = ch_grp session.merge(binding) session.flush() return binding
[ "def", "update_reserved_binding", "(", "vlan_id", ",", "switch_ip", ",", "instance_id", ",", "port_id", ",", "is_switch_binding", "=", "True", ",", "is_native", "=", "False", ",", "ch_grp", "=", "0", ")", ":", "if", "not", "port_id", ":", "LOG", ".", "warn...
Updates reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id :param ch_grp: 0 if no port-channel else non-zero integer
[ "Updates", "reserved", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L77-L119
train
37,534
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_reserved_binding
def remove_reserved_binding(vlan_id, switch_ip, instance_id, port_id): """Removes reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id """ if not port_id: LOG.warning("remove_reserved_binding called with no state") return LOG.debug("remove_reserved_binding called") session = bc.get_writer_session() binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) for bind in binding: session.delete(bind) session.flush() return binding
python
def remove_reserved_binding(vlan_id, switch_ip, instance_id, port_id): """Removes reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id """ if not port_id: LOG.warning("remove_reserved_binding called with no state") return LOG.debug("remove_reserved_binding called") session = bc.get_writer_session() binding = _lookup_one_nexus_binding(session=session, vlan_id=vlan_id, switch_ip=switch_ip, instance_id=instance_id, port_id=port_id) for bind in binding: session.delete(bind) session.flush() return binding
[ "def", "remove_reserved_binding", "(", "vlan_id", ",", "switch_ip", ",", "instance_id", ",", "port_id", ")", ":", "if", "not", "port_id", ":", "LOG", ".", "warning", "(", "\"remove_reserved_binding called with no state\"", ")", "return", "LOG", ".", "debug", "(", ...
Removes reserved binding. This overloads port bindings to support reserved Switch binding used to maintain the state of a switch so it can be viewed by all other neutron processes. There's also the case of a reserved port binding to keep switch information on a given interface. The values of these arguments is as follows: :param vlan_id: 0 :param switch_ip: ip address of the switch :param instance_id: fixed string RESERVED_NEXUS_SWITCH_DEVICE_ID_R1 :param port_id: switch-state of ACTIVE, RESTORE_S1, RESTORE_S2, INACTIVE : port-expected port_id
[ "Removes", "reserved", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L122-L151
train
37,535
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
add_reserved_switch_binding
def add_reserved_switch_binding(switch_ip, state): """Add a reserved switch binding.""" # overload port_id to contain switch state add_nexusport_binding( state, const.NO_VLAN_OR_VNI_ID, const.NO_VLAN_OR_VNI_ID, switch_ip, const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1)
python
def add_reserved_switch_binding(switch_ip, state): """Add a reserved switch binding.""" # overload port_id to contain switch state add_nexusport_binding( state, const.NO_VLAN_OR_VNI_ID, const.NO_VLAN_OR_VNI_ID, switch_ip, const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1)
[ "def", "add_reserved_switch_binding", "(", "switch_ip", ",", "state", ")", ":", "# overload port_id to contain switch state", "add_nexusport_binding", "(", "state", ",", "const", ".", "NO_VLAN_OR_VNI_ID", ",", "const", ".", "NO_VLAN_OR_VNI_ID", ",", "switch_ip", ",", "c...
Add a reserved switch binding.
[ "Add", "a", "reserved", "switch", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L163-L172
train
37,536
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
update_reserved_switch_binding
def update_reserved_switch_binding(switch_ip, state): """Update a reserved switch binding.""" # overload port_id to contain switch state update_reserved_binding( const.NO_VLAN_OR_VNI_ID, switch_ip, const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1, state)
python
def update_reserved_switch_binding(switch_ip, state): """Update a reserved switch binding.""" # overload port_id to contain switch state update_reserved_binding( const.NO_VLAN_OR_VNI_ID, switch_ip, const.RESERVED_NEXUS_SWITCH_DEVICE_ID_R1, state)
[ "def", "update_reserved_switch_binding", "(", "switch_ip", ",", "state", ")", ":", "# overload port_id to contain switch state", "update_reserved_binding", "(", "const", ".", "NO_VLAN_OR_VNI_ID", ",", "switch_ip", ",", "const", ".", "RESERVED_NEXUS_SWITCH_DEVICE_ID_R1", ",", ...
Update a reserved switch binding.
[ "Update", "a", "reserved", "switch", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L175-L183
train
37,537
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
add_nexusport_binding
def add_nexusport_binding(port_id, vlan_id, vni, switch_ip, instance_id, is_native=False, ch_grp=0): """Adds a nexusport binding.""" LOG.debug("add_nexusport_binding() called") session = bc.get_writer_session() binding = nexus_models_v2.NexusPortBinding(port_id=port_id, vlan_id=vlan_id, vni=vni, switch_ip=switch_ip, instance_id=instance_id, is_native=is_native, channel_group=ch_grp) session.add(binding) session.flush() return binding
python
def add_nexusport_binding(port_id, vlan_id, vni, switch_ip, instance_id, is_native=False, ch_grp=0): """Adds a nexusport binding.""" LOG.debug("add_nexusport_binding() called") session = bc.get_writer_session() binding = nexus_models_v2.NexusPortBinding(port_id=port_id, vlan_id=vlan_id, vni=vni, switch_ip=switch_ip, instance_id=instance_id, is_native=is_native, channel_group=ch_grp) session.add(binding) session.flush() return binding
[ "def", "add_nexusport_binding", "(", "port_id", ",", "vlan_id", ",", "vni", ",", "switch_ip", ",", "instance_id", ",", "is_native", "=", "False", ",", "ch_grp", "=", "0", ")", ":", "LOG", ".", "debug", "(", "\"add_nexusport_binding() called\"", ")", "session",...
Adds a nexusport binding.
[ "Adds", "a", "nexusport", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L241-L255
train
37,538
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_nexusport_binding
def remove_nexusport_binding(port_id, vlan_id, vni, switch_ip, instance_id): """Removes a nexusport binding.""" LOG.debug("remove_nexusport_binding() called") session = bc.get_writer_session() binding = _lookup_all_nexus_bindings(session=session, vlan_id=vlan_id, vni=vni, switch_ip=switch_ip, port_id=port_id, instance_id=instance_id) for bind in binding: session.delete(bind) session.flush() return binding
python
def remove_nexusport_binding(port_id, vlan_id, vni, switch_ip, instance_id): """Removes a nexusport binding.""" LOG.debug("remove_nexusport_binding() called") session = bc.get_writer_session() binding = _lookup_all_nexus_bindings(session=session, vlan_id=vlan_id, vni=vni, switch_ip=switch_ip, port_id=port_id, instance_id=instance_id) for bind in binding: session.delete(bind) session.flush() return binding
[ "def", "remove_nexusport_binding", "(", "port_id", ",", "vlan_id", ",", "vni", ",", "switch_ip", ",", "instance_id", ")", ":", "LOG", ".", "debug", "(", "\"remove_nexusport_binding() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "bin...
Removes a nexusport binding.
[ "Removes", "a", "nexusport", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L258-L271
train
37,539
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
update_nexusport_binding
def update_nexusport_binding(port_id, new_vlan_id): """Updates nexusport binding.""" if not new_vlan_id: LOG.warning("update_nexusport_binding called with no vlan") return LOG.debug("update_nexusport_binding called") session = bc.get_writer_session() binding = _lookup_one_nexus_binding(session=session, port_id=port_id) binding.vlan_id = new_vlan_id session.merge(binding) session.flush() return binding
python
def update_nexusport_binding(port_id, new_vlan_id): """Updates nexusport binding.""" if not new_vlan_id: LOG.warning("update_nexusport_binding called with no vlan") return LOG.debug("update_nexusport_binding called") session = bc.get_writer_session() binding = _lookup_one_nexus_binding(session=session, port_id=port_id) binding.vlan_id = new_vlan_id session.merge(binding) session.flush() return binding
[ "def", "update_nexusport_binding", "(", "port_id", ",", "new_vlan_id", ")", ":", "if", "not", "new_vlan_id", ":", "LOG", ".", "warning", "(", "\"update_nexusport_binding called with no vlan\"", ")", "return", "LOG", ".", "debug", "(", "\"update_nexusport_binding called\...
Updates nexusport binding.
[ "Updates", "nexusport", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L274-L285
train
37,540
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_all_nexusport_bindings
def remove_all_nexusport_bindings(): """Removes all nexusport bindings.""" LOG.debug("remove_all_nexusport_bindings() called") session = bc.get_writer_session() session.query(nexus_models_v2.NexusPortBinding).delete() session.flush()
python
def remove_all_nexusport_bindings(): """Removes all nexusport bindings.""" LOG.debug("remove_all_nexusport_bindings() called") session = bc.get_writer_session() session.query(nexus_models_v2.NexusPortBinding).delete() session.flush()
[ "def", "remove_all_nexusport_bindings", "(", ")", ":", "LOG", ".", "debug", "(", "\"remove_all_nexusport_bindings() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "session", ".", "query", "(", "nexus_models_v2", ".", "NexusPortBinding", "...
Removes all nexusport bindings.
[ "Removes", "all", "nexusport", "bindings", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L288-L294
train
37,541
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
_lookup_nexus_bindings
def _lookup_nexus_bindings(query_type, session=None, **bfilter): """Look up 'query_type' Nexus bindings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for bindings query :returns: bindings if query gave a result, else raise NexusPortBindingNotFound. """ if session is None: session = bc.get_reader_session() query_method = getattr(session.query( nexus_models_v2.NexusPortBinding).filter_by(**bfilter), query_type) try: bindings = query_method() if bindings: return bindings except sa_exc.NoResultFound: pass raise c_exc.NexusPortBindingNotFound(**bfilter)
python
def _lookup_nexus_bindings(query_type, session=None, **bfilter): """Look up 'query_type' Nexus bindings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for bindings query :returns: bindings if query gave a result, else raise NexusPortBindingNotFound. """ if session is None: session = bc.get_reader_session() query_method = getattr(session.query( nexus_models_v2.NexusPortBinding).filter_by(**bfilter), query_type) try: bindings = query_method() if bindings: return bindings except sa_exc.NoResultFound: pass raise c_exc.NexusPortBindingNotFound(**bfilter)
[ "def", "_lookup_nexus_bindings", "(", "query_type", ",", "session", "=", "None", ",", "*", "*", "bfilter", ")", ":", "if", "session", "is", "None", ":", "session", "=", "bc", ".", "get_reader_session", "(", ")", "query_method", "=", "getattr", "(", "sessio...
Look up 'query_type' Nexus bindings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for bindings query :returns: bindings if query gave a result, else raise NexusPortBindingNotFound.
[ "Look", "up", "query_type", "Nexus", "bindings", "matching", "the", "filter", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L330-L349
train
37,542
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
add_nexusnve_binding
def add_nexusnve_binding(vni, switch_ip, device_id, mcast_group): """Adds a nexus nve binding.""" LOG.debug("add_nexusnve_binding() called") session = bc.get_writer_session() binding = nexus_models_v2.NexusNVEBinding(vni=vni, switch_ip=switch_ip, device_id=device_id, mcast_group=mcast_group) session.add(binding) session.flush() return binding
python
def add_nexusnve_binding(vni, switch_ip, device_id, mcast_group): """Adds a nexus nve binding.""" LOG.debug("add_nexusnve_binding() called") session = bc.get_writer_session() binding = nexus_models_v2.NexusNVEBinding(vni=vni, switch_ip=switch_ip, device_id=device_id, mcast_group=mcast_group) session.add(binding) session.flush() return binding
[ "def", "add_nexusnve_binding", "(", "vni", ",", "switch_ip", ",", "device_id", ",", "mcast_group", ")", ":", "LOG", ".", "debug", "(", "\"add_nexusnve_binding() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "binding", "=", "nexus_mod...
Adds a nexus nve binding.
[ "Adds", "a", "nexus", "nve", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L364-L374
train
37,543
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_nexusnve_binding
def remove_nexusnve_binding(vni, switch_ip, device_id): """Remove the nexus nve binding.""" LOG.debug("remove_nexusnve_binding() called") session = bc.get_writer_session() binding = (session.query(nexus_models_v2.NexusNVEBinding). filter_by(vni=vni, switch_ip=switch_ip, device_id=device_id).one()) if binding: session.delete(binding) session.flush() return binding
python
def remove_nexusnve_binding(vni, switch_ip, device_id): """Remove the nexus nve binding.""" LOG.debug("remove_nexusnve_binding() called") session = bc.get_writer_session() binding = (session.query(nexus_models_v2.NexusNVEBinding). filter_by(vni=vni, switch_ip=switch_ip, device_id=device_id).one()) if binding: session.delete(binding) session.flush() return binding
[ "def", "remove_nexusnve_binding", "(", "vni", ",", "switch_ip", ",", "device_id", ")", ":", "LOG", ".", "debug", "(", "\"remove_nexusnve_binding() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "binding", "=", "(", "session", ".", "...
Remove the nexus nve binding.
[ "Remove", "the", "nexus", "nve", "binding", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L377-L387
train
37,544
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_all_nexusnve_bindings
def remove_all_nexusnve_bindings(): """Removes all nexusnve bindings.""" LOG.debug("remove_all_nexusport_bindings() called") session = bc.get_writer_session() session.query(nexus_models_v2.NexusNVEBinding).delete() session.flush()
python
def remove_all_nexusnve_bindings(): """Removes all nexusnve bindings.""" LOG.debug("remove_all_nexusport_bindings() called") session = bc.get_writer_session() session.query(nexus_models_v2.NexusNVEBinding).delete() session.flush()
[ "def", "remove_all_nexusnve_bindings", "(", ")", ":", "LOG", ".", "debug", "(", "\"remove_all_nexusport_bindings() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "session", ".", "query", "(", "nexus_models_v2", ".", "NexusNVEBinding", ")"...
Removes all nexusnve bindings.
[ "Removes", "all", "nexusnve", "bindings", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L390-L396
train
37,545
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
_lookup_host_mappings
def _lookup_host_mappings(query_type, session=None, **bfilter): """Look up 'query_type' Nexus mappings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for mappings query :returns: mappings if query gave a result, else raise NexusHostMappingNotFound. """ if session is None: session = bc.get_reader_session() query_method = getattr(session.query( nexus_models_v2.NexusHostMapping).filter_by(**bfilter), query_type) try: mappings = query_method() if mappings: return mappings except sa_exc.NoResultFound: pass raise c_exc.NexusHostMappingNotFound(**bfilter)
python
def _lookup_host_mappings(query_type, session=None, **bfilter): """Look up 'query_type' Nexus mappings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for mappings query :returns: mappings if query gave a result, else raise NexusHostMappingNotFound. """ if session is None: session = bc.get_reader_session() query_method = getattr(session.query( nexus_models_v2.NexusHostMapping).filter_by(**bfilter), query_type) try: mappings = query_method() if mappings: return mappings except sa_exc.NoResultFound: pass raise c_exc.NexusHostMappingNotFound(**bfilter)
[ "def", "_lookup_host_mappings", "(", "query_type", ",", "session", "=", "None", ",", "*", "*", "bfilter", ")", ":", "if", "session", "is", "None", ":", "session", "=", "bc", ".", "get_reader_session", "(", ")", "query_method", "=", "getattr", "(", "session...
Look up 'query_type' Nexus mappings matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param bfilter: filter for mappings query :returns: mappings if query gave a result, else raise NexusHostMappingNotFound.
[ "Look", "up", "query_type", "Nexus", "mappings", "matching", "the", "filter", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L444-L463
train
37,546
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
add_host_mapping
def add_host_mapping(host_id, nexus_ip, interface, ch_grp, is_static): """Add Host to interface mapping entry into mapping data base. :param host_id: is the name of the host to add :param interface: is the interface for this host :param nexus_ip: is the ip addr of the nexus switch for this interface :param ch_grp: is the port channel this interface belos :param is_static: whether this is from conf file or learned from baremetal. """ LOG.debug("add_nexusport_binding() called") session = bc.get_writer_session() mapping = nexus_models_v2.NexusHostMapping(host_id=host_id, if_id=interface, switch_ip=nexus_ip, ch_grp=ch_grp, is_static=is_static) try: session.add(mapping) session.flush() except db_exc.DBDuplicateEntry: with excutils.save_and_reraise_exception() as ctxt: if is_static: ctxt.reraise = False LOG.debug("Duplicate static entry encountered " "host=%(host)s, if=%(if)s, ip=%(ip)s", {'host': host_id, 'if': interface, 'ip': nexus_ip}) return mapping
python
def add_host_mapping(host_id, nexus_ip, interface, ch_grp, is_static): """Add Host to interface mapping entry into mapping data base. :param host_id: is the name of the host to add :param interface: is the interface for this host :param nexus_ip: is the ip addr of the nexus switch for this interface :param ch_grp: is the port channel this interface belos :param is_static: whether this is from conf file or learned from baremetal. """ LOG.debug("add_nexusport_binding() called") session = bc.get_writer_session() mapping = nexus_models_v2.NexusHostMapping(host_id=host_id, if_id=interface, switch_ip=nexus_ip, ch_grp=ch_grp, is_static=is_static) try: session.add(mapping) session.flush() except db_exc.DBDuplicateEntry: with excutils.save_and_reraise_exception() as ctxt: if is_static: ctxt.reraise = False LOG.debug("Duplicate static entry encountered " "host=%(host)s, if=%(if)s, ip=%(ip)s", {'host': host_id, 'if': interface, 'ip': nexus_ip}) return mapping
[ "def", "add_host_mapping", "(", "host_id", ",", "nexus_ip", ",", "interface", ",", "ch_grp", ",", "is_static", ")", ":", "LOG", ".", "debug", "(", "\"add_nexusport_binding() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "mapping", ...
Add Host to interface mapping entry into mapping data base. :param host_id: is the name of the host to add :param interface: is the interface for this host :param nexus_ip: is the ip addr of the nexus switch for this interface :param ch_grp: is the port channel this interface belos :param is_static: whether this is from conf file or learned from baremetal.
[ "Add", "Host", "to", "interface", "mapping", "entry", "into", "mapping", "data", "base", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L496-L525
train
37,547
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_host_mapping
def remove_host_mapping(interface, nexus_ip): """Remove host to interface mapping entry from mapping data base.""" LOG.debug("remove_host_mapping() called") session = bc.get_writer_session() try: mapping = _lookup_one_host_mapping( session=session, if_id=interface, switch_ip=nexus_ip) session.delete(mapping) session.flush() except c_exc.NexusHostMappingNotFound: pass
python
def remove_host_mapping(interface, nexus_ip): """Remove host to interface mapping entry from mapping data base.""" LOG.debug("remove_host_mapping() called") session = bc.get_writer_session() try: mapping = _lookup_one_host_mapping( session=session, if_id=interface, switch_ip=nexus_ip) session.delete(mapping) session.flush() except c_exc.NexusHostMappingNotFound: pass
[ "def", "remove_host_mapping", "(", "interface", ",", "nexus_ip", ")", ":", "LOG", ".", "debug", "(", "\"remove_host_mapping() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "try", ":", "mapping", "=", "_lookup_one_host_mapping", "(", ...
Remove host to interface mapping entry from mapping data base.
[ "Remove", "host", "to", "interface", "mapping", "entry", "from", "mapping", "data", "base", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L544-L557
train
37,548
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
remove_all_static_host_mappings
def remove_all_static_host_mappings(): """Remove all entries defined in config file from mapping data base.""" LOG.debug("remove_host_mapping() called") session = bc.get_writer_session() try: mapping = _lookup_all_host_mappings( session=session, is_static=True) for host in mapping: session.delete(host) session.flush() except c_exc.NexusHostMappingNotFound: pass
python
def remove_all_static_host_mappings(): """Remove all entries defined in config file from mapping data base.""" LOG.debug("remove_host_mapping() called") session = bc.get_writer_session() try: mapping = _lookup_all_host_mappings( session=session, is_static=True) for host in mapping: session.delete(host) session.flush() except c_exc.NexusHostMappingNotFound: pass
[ "def", "remove_all_static_host_mappings", "(", ")", ":", "LOG", ".", "debug", "(", "\"remove_host_mapping() called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "try", ":", "mapping", "=", "_lookup_all_host_mappings", "(", "session", "=", "se...
Remove all entries defined in config file from mapping data base.
[ "Remove", "all", "entries", "defined", "in", "config", "file", "from", "mapping", "data", "base", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L560-L573
train
37,549
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
_lookup_vpc_allocs
def _lookup_vpc_allocs(query_type, session=None, order=None, **bfilter): """Look up 'query_type' Nexus VPC Allocs matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param order: select what field to order data :param bfilter: filter for mappings query :returns: VPCs if query gave a result, else raise NexusVPCAllocNotFound. """ if session is None: session = bc.get_reader_session() if order: query_method = getattr(session.query( nexus_models_v2.NexusVPCAlloc).filter_by(**bfilter).order_by( order), query_type) else: query_method = getattr(session.query( nexus_models_v2.NexusVPCAlloc).filter_by(**bfilter), query_type) try: vpcs = query_method() if vpcs: return vpcs except sa_exc.NoResultFound: pass raise c_exc.NexusVPCAllocNotFound(**bfilter)
python
def _lookup_vpc_allocs(query_type, session=None, order=None, **bfilter): """Look up 'query_type' Nexus VPC Allocs matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param order: select what field to order data :param bfilter: filter for mappings query :returns: VPCs if query gave a result, else raise NexusVPCAllocNotFound. """ if session is None: session = bc.get_reader_session() if order: query_method = getattr(session.query( nexus_models_v2.NexusVPCAlloc).filter_by(**bfilter).order_by( order), query_type) else: query_method = getattr(session.query( nexus_models_v2.NexusVPCAlloc).filter_by(**bfilter), query_type) try: vpcs = query_method() if vpcs: return vpcs except sa_exc.NoResultFound: pass raise c_exc.NexusVPCAllocNotFound(**bfilter)
[ "def", "_lookup_vpc_allocs", "(", "query_type", ",", "session", "=", "None", ",", "order", "=", "None", ",", "*", "*", "bfilter", ")", ":", "if", "session", "is", "None", ":", "session", "=", "bc", ".", "get_reader_session", "(", ")", "if", "order", ":...
Look up 'query_type' Nexus VPC Allocs matching the filter. :param query_type: 'all', 'one' or 'first' :param session: db session :param order: select what field to order data :param bfilter: filter for mappings query :returns: VPCs if query gave a result, else raise NexusVPCAllocNotFound.
[ "Look", "up", "query_type", "Nexus", "VPC", "Allocs", "matching", "the", "filter", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L576-L606
train
37,550
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
_get_free_vpcids_on_switches
def _get_free_vpcids_on_switches(switch_ip_list): '''Get intersect list of free vpcids in list of switches.''' session = bc.get_reader_session() prev_view = aliased(nexus_models_v2.NexusVPCAlloc) query = session.query(prev_view.vpc_id) prev_swip = switch_ip_list[0] for ip in switch_ip_list[1:]: cur_view = aliased(nexus_models_v2.NexusVPCAlloc) cur_swip = ip query = query.join(cur_view, sa.and_( prev_view.switch_ip == prev_swip, prev_view.active == False, # noqa cur_view.switch_ip == cur_swip, cur_view.active == False, # noqa prev_view.vpc_id == cur_view.vpc_id)) prev_view = cur_view prev_swip = cur_swip unique_vpcids = query.all() shuffle(unique_vpcids) return unique_vpcids
python
def _get_free_vpcids_on_switches(switch_ip_list): '''Get intersect list of free vpcids in list of switches.''' session = bc.get_reader_session() prev_view = aliased(nexus_models_v2.NexusVPCAlloc) query = session.query(prev_view.vpc_id) prev_swip = switch_ip_list[0] for ip in switch_ip_list[1:]: cur_view = aliased(nexus_models_v2.NexusVPCAlloc) cur_swip = ip query = query.join(cur_view, sa.and_( prev_view.switch_ip == prev_swip, prev_view.active == False, # noqa cur_view.switch_ip == cur_swip, cur_view.active == False, # noqa prev_view.vpc_id == cur_view.vpc_id)) prev_view = cur_view prev_swip = cur_swip unique_vpcids = query.all() shuffle(unique_vpcids) return unique_vpcids
[ "def", "_get_free_vpcids_on_switches", "(", "switch_ip_list", ")", ":", "session", "=", "bc", ".", "get_reader_session", "(", ")", "prev_view", "=", "aliased", "(", "nexus_models_v2", ".", "NexusVPCAlloc", ")", "query", "=", "session", ".", "query", "(", "prev_v...
Get intersect list of free vpcids in list of switches.
[ "Get", "intersect", "list", "of", "free", "vpcids", "in", "list", "of", "switches", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L649-L670
train
37,551
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
update_vpc_entry
def update_vpc_entry(nexus_ips, vpc_id, learned, active): """Change active state in vpc_allocate data base.""" LOG.debug("update_vpc_entry called") session = bc.get_writer_session() with session.begin(): for n_ip in nexus_ips: flipit = not active x = session.execute( sa.update(nexus_models_v2.NexusVPCAlloc).values({ 'learned': learned, 'active': active}).where(sa.and_( nexus_models_v2.NexusVPCAlloc.switch_ip == n_ip, nexus_models_v2.NexusVPCAlloc.vpc_id == vpc_id, nexus_models_v2.NexusVPCAlloc.active == flipit ))) if x.rowcount != 1: raise c_exc.NexusVPCAllocNotFound( switch_ip=n_ip, vpc_id=vpc_id, active=active)
python
def update_vpc_entry(nexus_ips, vpc_id, learned, active): """Change active state in vpc_allocate data base.""" LOG.debug("update_vpc_entry called") session = bc.get_writer_session() with session.begin(): for n_ip in nexus_ips: flipit = not active x = session.execute( sa.update(nexus_models_v2.NexusVPCAlloc).values({ 'learned': learned, 'active': active}).where(sa.and_( nexus_models_v2.NexusVPCAlloc.switch_ip == n_ip, nexus_models_v2.NexusVPCAlloc.vpc_id == vpc_id, nexus_models_v2.NexusVPCAlloc.active == flipit ))) if x.rowcount != 1: raise c_exc.NexusVPCAllocNotFound( switch_ip=n_ip, vpc_id=vpc_id, active=active)
[ "def", "update_vpc_entry", "(", "nexus_ips", ",", "vpc_id", ",", "learned", ",", "active", ")", ":", "LOG", ".", "debug", "(", "\"update_vpc_entry called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "with", "session", ".", "begin", "("...
Change active state in vpc_allocate data base.
[ "Change", "active", "state", "in", "vpc_allocate", "data", "base", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L722-L742
train
37,552
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
alloc_vpcid
def alloc_vpcid(nexus_ips): """Allocate a vpc id for the given list of switch_ips.""" LOG.debug("alloc_vpc() called") vpc_id = 0 intersect = _get_free_vpcids_on_switches(nexus_ips) for intersect_tuple in intersect: try: update_vpc_entry(nexus_ips, intersect_tuple.vpc_id, False, True) vpc_id = intersect_tuple.vpc_id break except Exception: LOG.exception( "This exception is expected if another controller " "beat us to vpcid %(vpcid)s for nexus %(ip)s", {'vpcid': intersect_tuple.vpc_id, 'ip': ', '.join(map(str, nexus_ips))}) return vpc_id
python
def alloc_vpcid(nexus_ips): """Allocate a vpc id for the given list of switch_ips.""" LOG.debug("alloc_vpc() called") vpc_id = 0 intersect = _get_free_vpcids_on_switches(nexus_ips) for intersect_tuple in intersect: try: update_vpc_entry(nexus_ips, intersect_tuple.vpc_id, False, True) vpc_id = intersect_tuple.vpc_id break except Exception: LOG.exception( "This exception is expected if another controller " "beat us to vpcid %(vpcid)s for nexus %(ip)s", {'vpcid': intersect_tuple.vpc_id, 'ip': ', '.join(map(str, nexus_ips))}) return vpc_id
[ "def", "alloc_vpcid", "(", "nexus_ips", ")", ":", "LOG", ".", "debug", "(", "\"alloc_vpc() called\"", ")", "vpc_id", "=", "0", "intersect", "=", "_get_free_vpcids_on_switches", "(", "nexus_ips", ")", "for", "intersect_tuple", "in", "intersect", ":", "try", ":", ...
Allocate a vpc id for the given list of switch_ips.
[ "Allocate", "a", "vpc", "id", "for", "the", "given", "list", "of", "switch_ips", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L745-L765
train
37,553
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
free_vpcid_for_switch_list
def free_vpcid_for_switch_list(vpc_id, nexus_ips): """Free a vpc id for the given list of switch_ips.""" LOG.debug("free_vpcid_for_switch_list() called") if vpc_id != 0: update_vpc_entry(nexus_ips, vpc_id, False, False)
python
def free_vpcid_for_switch_list(vpc_id, nexus_ips): """Free a vpc id for the given list of switch_ips.""" LOG.debug("free_vpcid_for_switch_list() called") if vpc_id != 0: update_vpc_entry(nexus_ips, vpc_id, False, False)
[ "def", "free_vpcid_for_switch_list", "(", "vpc_id", ",", "nexus_ips", ")", ":", "LOG", ".", "debug", "(", "\"free_vpcid_for_switch_list() called\"", ")", "if", "vpc_id", "!=", "0", ":", "update_vpc_entry", "(", "nexus_ips", ",", "vpc_id", ",", "False", ",", "Fal...
Free a vpc id for the given list of switch_ips.
[ "Free", "a", "vpc", "id", "for", "the", "given", "list", "of", "switch_ips", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L768-L773
train
37,554
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
free_vpcid_for_switch
def free_vpcid_for_switch(vpc_id, nexus_ip): """Free a vpc id for the given switch_ip.""" LOG.debug("free_vpcid_for_switch() called") if vpc_id != 0: update_vpc_entry([nexus_ip], vpc_id, False, False)
python
def free_vpcid_for_switch(vpc_id, nexus_ip): """Free a vpc id for the given switch_ip.""" LOG.debug("free_vpcid_for_switch() called") if vpc_id != 0: update_vpc_entry([nexus_ip], vpc_id, False, False)
[ "def", "free_vpcid_for_switch", "(", "vpc_id", ",", "nexus_ip", ")", ":", "LOG", ".", "debug", "(", "\"free_vpcid_for_switch() called\"", ")", "if", "vpc_id", "!=", "0", ":", "update_vpc_entry", "(", "[", "nexus_ip", "]", ",", "vpc_id", ",", "False", ",", "F...
Free a vpc id for the given switch_ip.
[ "Free", "a", "vpc", "id", "for", "the", "given", "switch_ip", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L776-L781
train
37,555
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_db_v2.py
delete_vpcid_for_switch
def delete_vpcid_for_switch(vpc_id, switch_ip): """Removes unused vpcid for a switch. :param vpc_id: vpc id to remove :param switch_ip: ip address of the switch """ LOG.debug("delete_vpcid_for_switch called") session = bc.get_writer_session() vpc = _lookup_one_vpc_allocs(vpc_id=vpc_id, switch_ip=switch_ip, active=False) session.delete(vpc) session.flush()
python
def delete_vpcid_for_switch(vpc_id, switch_ip): """Removes unused vpcid for a switch. :param vpc_id: vpc id to remove :param switch_ip: ip address of the switch """ LOG.debug("delete_vpcid_for_switch called") session = bc.get_writer_session() vpc = _lookup_one_vpc_allocs(vpc_id=vpc_id, switch_ip=switch_ip, active=False) session.delete(vpc) session.flush()
[ "def", "delete_vpcid_for_switch", "(", "vpc_id", ",", "switch_ip", ")", ":", "LOG", ".", "debug", "(", "\"delete_vpcid_for_switch called\"", ")", "session", "=", "bc", ".", "get_writer_session", "(", ")", "vpc", "=", "_lookup_one_vpc_allocs", "(", "vpc_id", "=", ...
Removes unused vpcid for a switch. :param vpc_id: vpc id to remove :param switch_ip: ip address of the switch
[ "Removes", "unused", "vpcid", "for", "a", "switch", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_db_v2.py#L784-L798
train
37,556
openstack/networking-cisco
networking_cisco/apps/saf/common/dfa_sys_lib.py
create_process
def create_process(cmd, root_helper=None, addl_env=None, log_output=True): """Create a process object for the given command. The return value will be a tuple of the process object and the list of command arguments used to create it. """ if root_helper: cmd = shlex.split(root_helper) + cmd cmd = map(str, cmd) log_output and LOG.info("Running command: %s", cmd) env = os.environ.copy() if addl_env: env.update(addl_env) obj = subprocess_popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) return obj, cmd
python
def create_process(cmd, root_helper=None, addl_env=None, log_output=True): """Create a process object for the given command. The return value will be a tuple of the process object and the list of command arguments used to create it. """ if root_helper: cmd = shlex.split(root_helper) + cmd cmd = map(str, cmd) log_output and LOG.info("Running command: %s", cmd) env = os.environ.copy() if addl_env: env.update(addl_env) obj = subprocess_popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env) return obj, cmd
[ "def", "create_process", "(", "cmd", ",", "root_helper", "=", "None", ",", "addl_env", "=", "None", ",", "log_output", "=", "True", ")", ":", "if", "root_helper", ":", "cmd", "=", "shlex", ".", "split", "(", "root_helper", ")", "+", "cmd", "cmd", "=", ...
Create a process object for the given command. The return value will be a tuple of the process object and the list of command arguments used to create it.
[ "Create", "a", "process", "object", "for", "the", "given", "command", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/common/dfa_sys_lib.py#L271-L289
train
37,557
openstack/networking-cisco
networking_cisco/apps/saf/common/dfa_sys_lib.py
is_intf_up
def is_intf_up(intf): """Function to check if a interface is up. """ intf_path = '/'.join(('/sys/class/net', intf)) intf_exist = os.path.exists(intf_path) if not intf_exist: LOG.error("Unable to get interface %(intf)s, Interface dir " "%(dir)s does not exist", {'intf': intf, 'dir': intf_path}) return False try: oper_file = '/'.join((intf_path, 'operstate')) with open(oper_file, 'r') as fd: oper_state = fd.read().strip('\n') if oper_state == 'up': return True except Exception as e: LOG.error("Exception in reading %s", str(e)) return False
python
def is_intf_up(intf): """Function to check if a interface is up. """ intf_path = '/'.join(('/sys/class/net', intf)) intf_exist = os.path.exists(intf_path) if not intf_exist: LOG.error("Unable to get interface %(intf)s, Interface dir " "%(dir)s does not exist", {'intf': intf, 'dir': intf_path}) return False try: oper_file = '/'.join((intf_path, 'operstate')) with open(oper_file, 'r') as fd: oper_state = fd.read().strip('\n') if oper_state == 'up': return True except Exception as e: LOG.error("Exception in reading %s", str(e)) return False
[ "def", "is_intf_up", "(", "intf", ")", ":", "intf_path", "=", "'/'", ".", "join", "(", "(", "'/sys/class/net'", ",", "intf", ")", ")", "intf_exist", "=", "os", ".", "path", ".", "exists", "(", "intf_path", ")", "if", "not", "intf_exist", ":", "LOG", ...
Function to check if a interface is up.
[ "Function", "to", "check", "if", "a", "interface", "is", "up", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/common/dfa_sys_lib.py#L393-L410
train
37,558
openstack/networking-cisco
networking_cisco/apps/saf/common/dfa_sys_lib.py
get_all_run_phy_intf
def get_all_run_phy_intf(): """Retrieve all physical interfaces that are operationally up. """ intf_list = [] base_dir = '/sys/class/net' dir_exist = os.path.exists(base_dir) if not dir_exist: LOG.error("Unable to get interface list :Base dir %s does not " "exist", base_dir) return intf_list dir_cont = os.listdir(base_dir) for subdir in dir_cont: dev_dir = base_dir + '/' + subdir + '/' + 'device' dev_exist = os.path.exists(dev_dir) if dev_exist: oper_state = is_intf_up(subdir) if oper_state is True: intf_list.append(subdir) else: LOG.info("Dev dir %s does not exist, not physical intf", dev_dir) return intf_list
python
def get_all_run_phy_intf(): """Retrieve all physical interfaces that are operationally up. """ intf_list = [] base_dir = '/sys/class/net' dir_exist = os.path.exists(base_dir) if not dir_exist: LOG.error("Unable to get interface list :Base dir %s does not " "exist", base_dir) return intf_list dir_cont = os.listdir(base_dir) for subdir in dir_cont: dev_dir = base_dir + '/' + subdir + '/' + 'device' dev_exist = os.path.exists(dev_dir) if dev_exist: oper_state = is_intf_up(subdir) if oper_state is True: intf_list.append(subdir) else: LOG.info("Dev dir %s does not exist, not physical intf", dev_dir) return intf_list
[ "def", "get_all_run_phy_intf", "(", ")", ":", "intf_list", "=", "[", "]", "base_dir", "=", "'/sys/class/net'", "dir_exist", "=", "os", ".", "path", ".", "exists", "(", "base_dir", ")", "if", "not", "dir_exist", ":", "LOG", ".", "error", "(", "\"Unable to g...
Retrieve all physical interfaces that are operationally up.
[ "Retrieve", "all", "physical", "interfaces", "that", "are", "operationally", "up", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/common/dfa_sys_lib.py#L413-L433
train
37,559
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver.check_vnic_type_and_vendor_info
def check_vnic_type_and_vendor_info(self, vnic_type, profile): """Checks if this vnic_type and vendor device info are supported. Returns True if: 1. the port vnic_type is direct or macvtap and 2. the vendor_id and product_id of the port is supported by this MD Useful in determining if this MD should bind the current port. """ # Check for vnic_type if vnic_type not in self.supported_sriov_vnic_types: LOG.info('Non SR-IOV vnic_type: %s.', vnic_type) return False if not profile: return False # Check for vendor_info return self._check_for_supported_vendor(profile)
python
def check_vnic_type_and_vendor_info(self, vnic_type, profile): """Checks if this vnic_type and vendor device info are supported. Returns True if: 1. the port vnic_type is direct or macvtap and 2. the vendor_id and product_id of the port is supported by this MD Useful in determining if this MD should bind the current port. """ # Check for vnic_type if vnic_type not in self.supported_sriov_vnic_types: LOG.info('Non SR-IOV vnic_type: %s.', vnic_type) return False if not profile: return False # Check for vendor_info return self._check_for_supported_vendor(profile)
[ "def", "check_vnic_type_and_vendor_info", "(", "self", ",", "vnic_type", ",", "profile", ")", ":", "# Check for vnic_type", "if", "vnic_type", "not", "in", "self", ".", "supported_sriov_vnic_types", ":", "LOG", ".", "info", "(", "'Non SR-IOV vnic_type: %s.'", ",", "...
Checks if this vnic_type and vendor device info are supported. Returns True if: 1. the port vnic_type is direct or macvtap and 2. the vendor_id and product_id of the port is supported by this MD Useful in determining if this MD should bind the current port.
[ "Checks", "if", "this", "vnic_type", "and", "vendor", "device", "info", "are", "supported", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L60-L79
train
37,560
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver._check_for_supported_vendor
def _check_for_supported_vendor(self, profile): """Checks if the port belongs to a supported vendor. Returns True for supported_pci_devs. """ vendor_info = profile.get('pci_vendor_info') if not vendor_info: return False if vendor_info not in self.supported_pci_devs: return False return True
python
def _check_for_supported_vendor(self, profile): """Checks if the port belongs to a supported vendor. Returns True for supported_pci_devs. """ vendor_info = profile.get('pci_vendor_info') if not vendor_info: return False if vendor_info not in self.supported_pci_devs: return False return True
[ "def", "_check_for_supported_vendor", "(", "self", ",", "profile", ")", ":", "vendor_info", "=", "profile", ".", "get", "(", "'pci_vendor_info'", ")", "if", "not", "vendor_info", ":", "return", "False", "if", "vendor_info", "not", "in", "self", ".", "supported...
Checks if the port belongs to a supported vendor. Returns True for supported_pci_devs.
[ "Checks", "if", "the", "port", "belongs", "to", "a", "supported", "vendor", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L81-L91
train
37,561
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver._import_ucsmsdk
def _import_ucsmsdk(self): """Imports the Ucsm SDK module. This module is not installed as part of the normal Neutron distributions. It is imported dynamically in this module so that the import can be mocked, allowing unit testing without requiring the installation of UcsSdk. """ # Check if SSL certificate checking has been disabled. # If so, warn the user before proceeding. if not CONF.ml2_cisco_ucsm.ucsm_https_verify: LOG.warning(const.SSL_WARNING) # Monkey patch the UCS sdk version of urllib2 to disable # https verify if required. from networking_cisco.ml2_drivers.ucsm import ucs_urllib2 ucsmsdkhandle = importutils.import_module('UcsSdk.UcsHandle') ucsmsdkhandle.urllib2 = ucs_urllib2 ucsmsdk = importutils.import_module('UcsSdk') return ucsmsdk
python
def _import_ucsmsdk(self): """Imports the Ucsm SDK module. This module is not installed as part of the normal Neutron distributions. It is imported dynamically in this module so that the import can be mocked, allowing unit testing without requiring the installation of UcsSdk. """ # Check if SSL certificate checking has been disabled. # If so, warn the user before proceeding. if not CONF.ml2_cisco_ucsm.ucsm_https_verify: LOG.warning(const.SSL_WARNING) # Monkey patch the UCS sdk version of urllib2 to disable # https verify if required. from networking_cisco.ml2_drivers.ucsm import ucs_urllib2 ucsmsdkhandle = importutils.import_module('UcsSdk.UcsHandle') ucsmsdkhandle.urllib2 = ucs_urllib2 ucsmsdk = importutils.import_module('UcsSdk') return ucsmsdk
[ "def", "_import_ucsmsdk", "(", "self", ")", ":", "# Check if SSL certificate checking has been disabled.", "# If so, warn the user before proceeding.", "if", "not", "CONF", ".", "ml2_cisco_ucsm", ".", "ucsm_https_verify", ":", "LOG", ".", "warning", "(", "const", ".", "SS...
Imports the Ucsm SDK module. This module is not installed as part of the normal Neutron distributions. It is imported dynamically in this module so that the import can be mocked, allowing unit testing without requiring the installation of UcsSdk.
[ "Imports", "the", "Ucsm", "SDK", "module", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L103-L124
train
37,562
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver._get_server_name
def _get_server_name(self, handle, service_profile_mo, ucsm_ip): """Get the contents of the 'Name' field associated with UCS Server. When a valid connection hande to UCS Manager is handed in, the Name field associated with a UCS Server is returned. """ try: resolved_dest = handle.ConfigResolveDn(service_profile_mo.PnDn) server_list = resolved_dest.OutConfig.GetChild() if not server_list: return "" return server_list[0].Name except Exception as e: # Raise a Neutron exception. Include a description of # the original exception. raise cexc.UcsmConfigReadFailed(ucsm_ip=ucsm_ip, exc=e)
python
def _get_server_name(self, handle, service_profile_mo, ucsm_ip): """Get the contents of the 'Name' field associated with UCS Server. When a valid connection hande to UCS Manager is handed in, the Name field associated with a UCS Server is returned. """ try: resolved_dest = handle.ConfigResolveDn(service_profile_mo.PnDn) server_list = resolved_dest.OutConfig.GetChild() if not server_list: return "" return server_list[0].Name except Exception as e: # Raise a Neutron exception. Include a description of # the original exception. raise cexc.UcsmConfigReadFailed(ucsm_ip=ucsm_ip, exc=e)
[ "def", "_get_server_name", "(", "self", ",", "handle", ",", "service_profile_mo", ",", "ucsm_ip", ")", ":", "try", ":", "resolved_dest", "=", "handle", ".", "ConfigResolveDn", "(", "service_profile_mo", ".", "PnDn", ")", "server_list", "=", "resolved_dest", ".",...
Get the contents of the 'Name' field associated with UCS Server. When a valid connection hande to UCS Manager is handed in, the Name field associated with a UCS Server is returned.
[ "Get", "the", "contents", "of", "the", "Name", "field", "associated", "with", "UCS", "Server", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L179-L194
train
37,563
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver._create_vlanprofile
def _create_vlanprofile(self, handle, vlan_id, ucsm_ip): """Creates VLAN profile to be assosiated with the Port Profile.""" vlan_name = self.make_vlan_name(vlan_id) vlan_profile_dest = (const.VLAN_PATH + const.VLAN_PROFILE_PATH_PREFIX + vlan_name) try: handle.StartTransaction() vp1 = handle.GetManagedObject( None, self.ucsmsdk.FabricLanCloud.ClassId(), {self.ucsmsdk.FabricLanCloud.DN: const.VLAN_PATH}) if not vp1: LOG.warning('UCS Manager network driver Vlan Profile ' 'path at %s missing', const.VLAN_PATH) return False # Create a vlan profile with the given vlan_id vp2 = handle.AddManagedObject( vp1, self.ucsmsdk.FabricVlan.ClassId(), {self.ucsmsdk.FabricVlan.COMPRESSION_TYPE: const.VLAN_COMPRESSION_TYPE, self.ucsmsdk.FabricVlan.DN: vlan_profile_dest, self.ucsmsdk.FabricVlan.SHARING: const.NONE, self.ucsmsdk.FabricVlan.PUB_NW_NAME: "", self.ucsmsdk.FabricVlan.ID: str(vlan_id), self.ucsmsdk.FabricVlan.MCAST_POLICY_NAME: "", self.ucsmsdk.FabricVlan.NAME: vlan_name, self.ucsmsdk.FabricVlan.DEFAULT_NET: "no"}) handle.CompleteTransaction() if vp2: LOG.debug('UCS Manager network driver Created Vlan ' 'Profile %s at %s', vlan_name, vlan_profile_dest) return True except Exception as e: return self._handle_ucsm_exception(e, 'Vlan Profile', vlan_name, ucsm_ip)
python
def _create_vlanprofile(self, handle, vlan_id, ucsm_ip): """Creates VLAN profile to be assosiated with the Port Profile.""" vlan_name = self.make_vlan_name(vlan_id) vlan_profile_dest = (const.VLAN_PATH + const.VLAN_PROFILE_PATH_PREFIX + vlan_name) try: handle.StartTransaction() vp1 = handle.GetManagedObject( None, self.ucsmsdk.FabricLanCloud.ClassId(), {self.ucsmsdk.FabricLanCloud.DN: const.VLAN_PATH}) if not vp1: LOG.warning('UCS Manager network driver Vlan Profile ' 'path at %s missing', const.VLAN_PATH) return False # Create a vlan profile with the given vlan_id vp2 = handle.AddManagedObject( vp1, self.ucsmsdk.FabricVlan.ClassId(), {self.ucsmsdk.FabricVlan.COMPRESSION_TYPE: const.VLAN_COMPRESSION_TYPE, self.ucsmsdk.FabricVlan.DN: vlan_profile_dest, self.ucsmsdk.FabricVlan.SHARING: const.NONE, self.ucsmsdk.FabricVlan.PUB_NW_NAME: "", self.ucsmsdk.FabricVlan.ID: str(vlan_id), self.ucsmsdk.FabricVlan.MCAST_POLICY_NAME: "", self.ucsmsdk.FabricVlan.NAME: vlan_name, self.ucsmsdk.FabricVlan.DEFAULT_NET: "no"}) handle.CompleteTransaction() if vp2: LOG.debug('UCS Manager network driver Created Vlan ' 'Profile %s at %s', vlan_name, vlan_profile_dest) return True except Exception as e: return self._handle_ucsm_exception(e, 'Vlan Profile', vlan_name, ucsm_ip)
[ "def", "_create_vlanprofile", "(", "self", ",", "handle", ",", "vlan_id", ",", "ucsm_ip", ")", ":", "vlan_name", "=", "self", ".", "make_vlan_name", "(", "vlan_id", ")", "vlan_profile_dest", "=", "(", "const", ".", "VLAN_PATH", "+", "const", ".", "VLAN_PROFI...
Creates VLAN profile to be assosiated with the Port Profile.
[ "Creates", "VLAN", "profile", "to", "be", "assosiated", "with", "the", "Port", "Profile", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L265-L304
train
37,564
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver.create_portprofile
def create_portprofile(self, profile_name, vlan_id, vnic_type, host_id, trunk_vlans): """Top level method to create Port Profiles on the UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in the creation of the Port Profile on the UCS Manager. """ ucsm_ip = self.get_ucsm_ip_for_host(host_id) if not ucsm_ip: LOG.info('UCS Manager network driver does not have UCSM IP ' 'for Host_id %s', str(host_id)) return False with self.ucsm_connect_disconnect(ucsm_ip) as handle: # Create Vlan Profile if not self._create_vlanprofile(handle, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to create ' 'Vlan Profile for vlan %s', str(vlan_id)) return False if trunk_vlans: for vlan in trunk_vlans: if not self._create_vlanprofile(handle, vlan, ucsm_ip): LOG.error('UCS Manager network driver failed to ' 'create Vlan Profile for vlan %s', vlan) return False qos_policy = CONF.ml2_cisco_ucsm.ucsms[ucsm_ip].sriov_qos_policy if qos_policy: LOG.debug('UCS Manager Network driver applying QoS Policy ' '%(qos)s to Port Profile %(port_profile)s', {'qos': qos_policy, 'port_profile': profile_name}) # Create Port Profile if not self._create_port_profile(handle, profile_name, vlan_id, vnic_type, ucsm_ip, trunk_vlans, qos_policy): LOG.error('UCS Manager network driver failed to create ' 'Port Profile %s', profile_name) return False return True
python
def create_portprofile(self, profile_name, vlan_id, vnic_type, host_id, trunk_vlans): """Top level method to create Port Profiles on the UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in the creation of the Port Profile on the UCS Manager. """ ucsm_ip = self.get_ucsm_ip_for_host(host_id) if not ucsm_ip: LOG.info('UCS Manager network driver does not have UCSM IP ' 'for Host_id %s', str(host_id)) return False with self.ucsm_connect_disconnect(ucsm_ip) as handle: # Create Vlan Profile if not self._create_vlanprofile(handle, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to create ' 'Vlan Profile for vlan %s', str(vlan_id)) return False if trunk_vlans: for vlan in trunk_vlans: if not self._create_vlanprofile(handle, vlan, ucsm_ip): LOG.error('UCS Manager network driver failed to ' 'create Vlan Profile for vlan %s', vlan) return False qos_policy = CONF.ml2_cisco_ucsm.ucsms[ucsm_ip].sriov_qos_policy if qos_policy: LOG.debug('UCS Manager Network driver applying QoS Policy ' '%(qos)s to Port Profile %(port_profile)s', {'qos': qos_policy, 'port_profile': profile_name}) # Create Port Profile if not self._create_port_profile(handle, profile_name, vlan_id, vnic_type, ucsm_ip, trunk_vlans, qos_policy): LOG.error('UCS Manager network driver failed to create ' 'Port Profile %s', profile_name) return False return True
[ "def", "create_portprofile", "(", "self", ",", "profile_name", ",", "vlan_id", ",", "vnic_type", ",", "host_id", ",", "trunk_vlans", ")", ":", "ucsm_ip", "=", "self", ".", "get_ucsm_ip_for_host", "(", "host_id", ")", "if", "not", "ucsm_ip", ":", "LOG", ".", ...
Top level method to create Port Profiles on the UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in the creation of the Port Profile on the UCS Manager.
[ "Top", "level", "method", "to", "create", "Port", "Profiles", "on", "the", "UCS", "Manager", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L434-L476
train
37,565
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver.update_serviceprofile
def update_serviceprofile(self, host_id, vlan_id): """Top level method to update Service Profiles on UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in a vlan_id getting programed on a server's ethernet ports and the Fabric Interconnect's network ports. """ ucsm_ip = self.get_ucsm_ip_for_host(host_id) if not ucsm_ip: LOG.info('UCS Manager network driver does not have UCSM IP ' 'for Host_id %s', str(host_id)) return False service_profile = self.ucsm_sp_dict.get((ucsm_ip, host_id)) if service_profile: LOG.debug('UCS Manager network driver Service Profile : %s', service_profile) else: LOG.info('UCS Manager network driver does not support ' 'Host_id %s', host_id) return False with self.ucsm_connect_disconnect(ucsm_ip) as handle: # Create Vlan Profile if not self._create_vlanprofile(handle, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to create ' 'Vlan Profile for vlan %s', str(vlan_id)) return False # Update Service Profile if not self._update_service_profile(handle, service_profile, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to update ' 'Service Profile %(service_profile)s in UCSM ' '%(ucsm_ip)s', {'service_profile': service_profile, 'ucsm_ip': ucsm_ip}) return False return True
python
def update_serviceprofile(self, host_id, vlan_id): """Top level method to update Service Profiles on UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in a vlan_id getting programed on a server's ethernet ports and the Fabric Interconnect's network ports. """ ucsm_ip = self.get_ucsm_ip_for_host(host_id) if not ucsm_ip: LOG.info('UCS Manager network driver does not have UCSM IP ' 'for Host_id %s', str(host_id)) return False service_profile = self.ucsm_sp_dict.get((ucsm_ip, host_id)) if service_profile: LOG.debug('UCS Manager network driver Service Profile : %s', service_profile) else: LOG.info('UCS Manager network driver does not support ' 'Host_id %s', host_id) return False with self.ucsm_connect_disconnect(ucsm_ip) as handle: # Create Vlan Profile if not self._create_vlanprofile(handle, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to create ' 'Vlan Profile for vlan %s', str(vlan_id)) return False # Update Service Profile if not self._update_service_profile(handle, service_profile, vlan_id, ucsm_ip): LOG.error('UCS Manager network driver failed to update ' 'Service Profile %(service_profile)s in UCSM ' '%(ucsm_ip)s', {'service_profile': service_profile, 'ucsm_ip': ucsm_ip}) return False return True
[ "def", "update_serviceprofile", "(", "self", ",", "host_id", ",", "vlan_id", ")", ":", "ucsm_ip", "=", "self", ".", "get_ucsm_ip_for_host", "(", "host_id", ")", "if", "not", "ucsm_ip", ":", "LOG", ".", "info", "(", "'UCS Manager network driver does not have UCSM I...
Top level method to update Service Profiles on UCS Manager. Calls all the methods responsible for the individual tasks that ultimately result in a vlan_id getting programed on a server's ethernet ports and the Fabric Interconnect's network ports.
[ "Top", "level", "method", "to", "update", "Service", "Profiles", "on", "UCS", "Manager", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L604-L644
train
37,566
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver._delete_port_profile
def _delete_port_profile(self, handle, port_profile, ucsm_ip): """Calls method to delete Port Profile from UCS Manager. If exception is raised by UCSM, then the PP is added to a DB table. The delete timer thread, tried to delete all PPs added to this table when it wakes up. """ try: self._delete_port_profile_from_ucsm(handle, port_profile, ucsm_ip) except Exception as e: # Add the Port Profile that we could not delete to the Port Profile # delete table. A periodic task will attempt to delete it. LOG.debug('Received Port Profile delete exception %s', e) self.ucsm_db.add_port_profile_to_delete_table(port_profile, ucsm_ip)
python
def _delete_port_profile(self, handle, port_profile, ucsm_ip): """Calls method to delete Port Profile from UCS Manager. If exception is raised by UCSM, then the PP is added to a DB table. The delete timer thread, tried to delete all PPs added to this table when it wakes up. """ try: self._delete_port_profile_from_ucsm(handle, port_profile, ucsm_ip) except Exception as e: # Add the Port Profile that we could not delete to the Port Profile # delete table. A periodic task will attempt to delete it. LOG.debug('Received Port Profile delete exception %s', e) self.ucsm_db.add_port_profile_to_delete_table(port_profile, ucsm_ip)
[ "def", "_delete_port_profile", "(", "self", ",", "handle", ",", "port_profile", ",", "ucsm_ip", ")", ":", "try", ":", "self", ".", "_delete_port_profile_from_ucsm", "(", "handle", ",", "port_profile", ",", "ucsm_ip", ")", "except", "Exception", "as", "e", ":",...
Calls method to delete Port Profile from UCS Manager. If exception is raised by UCSM, then the PP is added to a DB table. The delete timer thread, tried to delete all PPs added to this table when it wakes up.
[ "Calls", "method", "to", "delete", "Port", "Profile", "from", "UCS", "Manager", ".", "If", "exception", "is", "raised", "by", "UCSM", "then", "the", "PP", "is", "added", "to", "a", "DB", "table", ".", "The", "delete", "timer", "thread", "tried", "to", ...
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L778-L792
train
37,567
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver.delete_all_config_for_vlan
def delete_all_config_for_vlan(self, vlan_id, port_profile, trunk_vlans): """Top level method to delete all config for vlan_id.""" ucsm_ips = list(CONF.ml2_cisco_ucsm.ucsms) for ucsm_ip in ucsm_ips: with self.ucsm_connect_disconnect(ucsm_ip) as handle: LOG.debug('Deleting config for VLAN %d from UCSM %s', vlan_id, ucsm_ip) if (port_profile): self._delete_port_profile(handle, port_profile, ucsm_ip) ucsm = CONF.ml2_cisco_ucsm.ucsms[ucsm_ip] if ucsm.sp_template_list: self._remove_vlan_from_all_sp_templates(handle, vlan_id, ucsm_ip) if ucsm.vnic_template_list: self._remove_vlan_from_vnic_templates(handle, vlan_id, ucsm_ip) if not (ucsm.sp_template_list and ucsm.vnic_template_list): self._remove_vlan_from_all_service_profiles(handle, vlan_id, ucsm_ip) self._delete_vlan_profile(handle, vlan_id, ucsm_ip) if trunk_vlans: for vlan_id in trunk_vlans: self._delete_vlan_profile(handle, vlan_id, ucsm_ip)
python
def delete_all_config_for_vlan(self, vlan_id, port_profile, trunk_vlans): """Top level method to delete all config for vlan_id.""" ucsm_ips = list(CONF.ml2_cisco_ucsm.ucsms) for ucsm_ip in ucsm_ips: with self.ucsm_connect_disconnect(ucsm_ip) as handle: LOG.debug('Deleting config for VLAN %d from UCSM %s', vlan_id, ucsm_ip) if (port_profile): self._delete_port_profile(handle, port_profile, ucsm_ip) ucsm = CONF.ml2_cisco_ucsm.ucsms[ucsm_ip] if ucsm.sp_template_list: self._remove_vlan_from_all_sp_templates(handle, vlan_id, ucsm_ip) if ucsm.vnic_template_list: self._remove_vlan_from_vnic_templates(handle, vlan_id, ucsm_ip) if not (ucsm.sp_template_list and ucsm.vnic_template_list): self._remove_vlan_from_all_service_profiles(handle, vlan_id, ucsm_ip) self._delete_vlan_profile(handle, vlan_id, ucsm_ip) if trunk_vlans: for vlan_id in trunk_vlans: self._delete_vlan_profile(handle, vlan_id, ucsm_ip)
[ "def", "delete_all_config_for_vlan", "(", "self", ",", "vlan_id", ",", "port_profile", ",", "trunk_vlans", ")", ":", "ucsm_ips", "=", "list", "(", "CONF", ".", "ml2_cisco_ucsm", ".", "ucsms", ")", "for", "ucsm_ip", "in", "ucsm_ips", ":", "with", "self", ".",...
Top level method to delete all config for vlan_id.
[ "Top", "level", "method", "to", "delete", "all", "config", "for", "vlan_id", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L964-L993
train
37,568
openstack/networking-cisco
networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py
CiscoUcsmDriver.ucs_manager_disconnect
def ucs_manager_disconnect(self, handle, ucsm_ip): """Disconnects from the UCS Manager. After the disconnect, the handle associated with this connection is no longer valid. """ try: handle.Logout() except Exception as e: # Raise a Neutron exception. Include a description of # the original exception. raise cexc.UcsmDisconnectFailed(ucsm_ip=ucsm_ip, exc=e)
python
def ucs_manager_disconnect(self, handle, ucsm_ip): """Disconnects from the UCS Manager. After the disconnect, the handle associated with this connection is no longer valid. """ try: handle.Logout() except Exception as e: # Raise a Neutron exception. Include a description of # the original exception. raise cexc.UcsmDisconnectFailed(ucsm_ip=ucsm_ip, exc=e)
[ "def", "ucs_manager_disconnect", "(", "self", ",", "handle", ",", "ucsm_ip", ")", ":", "try", ":", "handle", ".", "Logout", "(", ")", "except", "Exception", "as", "e", ":", "# Raise a Neutron exception. Include a description of", "# the original exception.", "raise",...
Disconnects from the UCS Manager. After the disconnect, the handle associated with this connection is no longer valid.
[ "Disconnects", "from", "the", "UCS", "Manager", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/ucsm/deprecated_network_driver.py#L1009-L1020
train
37,569
openstack/networking-cisco
networking_cisco/apps/saf/server/dfa_fail_recovery.py
DfaFailureRecovery.add_events
def add_events(self, **kwargs): """Add failure event into the queue.""" event_q = kwargs.get('event_queue') pri = kwargs.get('priority') if not event_q or not pri: return try: event_type = 'server.failure.recovery' payload = {} timestamp = time.ctime() data = (event_type, payload) event_q.put((pri, timestamp, data)) LOG.debug('Added failure recovery event to the queue.') except Exception as exc: LOG.exception('Error: %(exc)s for event %(event)s', {'exc': str(exc), 'event': event_type}) raise exc
python
def add_events(self, **kwargs): """Add failure event into the queue.""" event_q = kwargs.get('event_queue') pri = kwargs.get('priority') if not event_q or not pri: return try: event_type = 'server.failure.recovery' payload = {} timestamp = time.ctime() data = (event_type, payload) event_q.put((pri, timestamp, data)) LOG.debug('Added failure recovery event to the queue.') except Exception as exc: LOG.exception('Error: %(exc)s for event %(event)s', {'exc': str(exc), 'event': event_type}) raise exc
[ "def", "add_events", "(", "self", ",", "*", "*", "kwargs", ")", ":", "event_q", "=", "kwargs", ".", "get", "(", "'event_queue'", ")", "pri", "=", "kwargs", ".", "get", "(", "'priority'", ")", "if", "not", "event_q", "or", "not", "pri", ":", "return",...
Add failure event into the queue.
[ "Add", "failure", "event", "into", "the", "queue", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/server/dfa_fail_recovery.py#L39-L57
train
37,570
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.init_params
def init_params(self, protocol_interface, phy_interface): """Initializing parameters. """ self.lldp_cfgd = False self.local_intf = protocol_interface self.phy_interface = phy_interface self.remote_evb_cfgd = False self.remote_evb_mode = None self.remote_mgmt_addr = None self.remote_system_desc = None self.remote_system_name = None self.remote_port = None self.remote_chassis_id_mac = None self.remote_port_id_mac = None self.local_evb_cfgd = False self.local_evb_mode = None self.local_mgmt_address = None self.local_system_desc = None self.local_system_name = None self.local_port = None self.local_chassis_id_mac = None self.local_port_id_mac = None self.db_retry_status = False self.topo_send_cnt = 0 self.bond_interface = None self.bond_member_ports = None
python
def init_params(self, protocol_interface, phy_interface): """Initializing parameters. """ self.lldp_cfgd = False self.local_intf = protocol_interface self.phy_interface = phy_interface self.remote_evb_cfgd = False self.remote_evb_mode = None self.remote_mgmt_addr = None self.remote_system_desc = None self.remote_system_name = None self.remote_port = None self.remote_chassis_id_mac = None self.remote_port_id_mac = None self.local_evb_cfgd = False self.local_evb_mode = None self.local_mgmt_address = None self.local_system_desc = None self.local_system_name = None self.local_port = None self.local_chassis_id_mac = None self.local_port_id_mac = None self.db_retry_status = False self.topo_send_cnt = 0 self.bond_interface = None self.bond_member_ports = None
[ "def", "init_params", "(", "self", ",", "protocol_interface", ",", "phy_interface", ")", ":", "self", ".", "lldp_cfgd", "=", "False", "self", ".", "local_intf", "=", "protocol_interface", "self", ".", "phy_interface", "=", "phy_interface", "self", ".", "remote_e...
Initializing parameters.
[ "Initializing", "parameters", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L41-L65
train
37,571
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.cmp_update_bond_intf
def cmp_update_bond_intf(self, bond_interface): """Update the bond interface and its members. Update the bond interface, if this interface is a part of bond Return True if there's a change. """ if bond_interface != self.bond_interface: self.bond_interface = bond_interface self.bond_member_ports = sys_utils.get_member_ports(bond_interface) return True return False
python
def cmp_update_bond_intf(self, bond_interface): """Update the bond interface and its members. Update the bond interface, if this interface is a part of bond Return True if there's a change. """ if bond_interface != self.bond_interface: self.bond_interface = bond_interface self.bond_member_ports = sys_utils.get_member_ports(bond_interface) return True return False
[ "def", "cmp_update_bond_intf", "(", "self", ",", "bond_interface", ")", ":", "if", "bond_interface", "!=", "self", ".", "bond_interface", ":", "self", ".", "bond_interface", "=", "bond_interface", "self", ".", "bond_member_ports", "=", "sys_utils", ".", "get_membe...
Update the bond interface and its members. Update the bond interface, if this interface is a part of bond Return True if there's a change.
[ "Update", "the", "bond", "interface", "and", "its", "members", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L71-L81
train
37,572
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_evb_mode_uneq_store
def remote_evb_mode_uneq_store(self, remote_evb_mode): """Saves the EVB mode, if it is not the same as stored. """ if remote_evb_mode != self.remote_evb_mode: self.remote_evb_mode = remote_evb_mode return True return False
python
def remote_evb_mode_uneq_store(self, remote_evb_mode): """Saves the EVB mode, if it is not the same as stored. """ if remote_evb_mode != self.remote_evb_mode: self.remote_evb_mode = remote_evb_mode return True return False
[ "def", "remote_evb_mode_uneq_store", "(", "self", ",", "remote_evb_mode", ")", ":", "if", "remote_evb_mode", "!=", "self", ".", "remote_evb_mode", ":", "self", ".", "remote_evb_mode", "=", "remote_evb_mode", "return", "True", "return", "False" ]
Saves the EVB mode, if it is not the same as stored.
[ "Saves", "the", "EVB", "mode", "if", "it", "is", "not", "the", "same", "as", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L114-L119
train
37,573
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_evb_cfgd_uneq_store
def remote_evb_cfgd_uneq_store(self, remote_evb_cfgd): """This saves the EVB cfg, if it is not the same as stored. """ if remote_evb_cfgd != self.remote_evb_cfgd: self.remote_evb_cfgd = remote_evb_cfgd return True return False
python
def remote_evb_cfgd_uneq_store(self, remote_evb_cfgd): """This saves the EVB cfg, if it is not the same as stored. """ if remote_evb_cfgd != self.remote_evb_cfgd: self.remote_evb_cfgd = remote_evb_cfgd return True return False
[ "def", "remote_evb_cfgd_uneq_store", "(", "self", ",", "remote_evb_cfgd", ")", ":", "if", "remote_evb_cfgd", "!=", "self", ".", "remote_evb_cfgd", ":", "self", ".", "remote_evb_cfgd", "=", "remote_evb_cfgd", "return", "True", "return", "False" ]
This saves the EVB cfg, if it is not the same as stored.
[ "This", "saves", "the", "EVB", "cfg", "if", "it", "is", "not", "the", "same", "as", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L121-L126
train
37,574
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_mgmt_addr_uneq_store
def remote_mgmt_addr_uneq_store(self, remote_mgmt_addr): """This function saves the MGMT address, if different from stored. """ if remote_mgmt_addr != self.remote_mgmt_addr: self.remote_mgmt_addr = remote_mgmt_addr return True return False
python
def remote_mgmt_addr_uneq_store(self, remote_mgmt_addr): """This function saves the MGMT address, if different from stored. """ if remote_mgmt_addr != self.remote_mgmt_addr: self.remote_mgmt_addr = remote_mgmt_addr return True return False
[ "def", "remote_mgmt_addr_uneq_store", "(", "self", ",", "remote_mgmt_addr", ")", ":", "if", "remote_mgmt_addr", "!=", "self", ".", "remote_mgmt_addr", ":", "self", ".", "remote_mgmt_addr", "=", "remote_mgmt_addr", "return", "True", "return", "False" ]
This function saves the MGMT address, if different from stored.
[ "This", "function", "saves", "the", "MGMT", "address", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L128-L133
train
37,575
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_sys_desc_uneq_store
def remote_sys_desc_uneq_store(self, remote_system_desc): """This function saves the system desc, if different from stored. """ if remote_system_desc != self.remote_system_desc: self.remote_system_desc = remote_system_desc return True return False
python
def remote_sys_desc_uneq_store(self, remote_system_desc): """This function saves the system desc, if different from stored. """ if remote_system_desc != self.remote_system_desc: self.remote_system_desc = remote_system_desc return True return False
[ "def", "remote_sys_desc_uneq_store", "(", "self", ",", "remote_system_desc", ")", ":", "if", "remote_system_desc", "!=", "self", ".", "remote_system_desc", ":", "self", ".", "remote_system_desc", "=", "remote_system_desc", "return", "True", "return", "False" ]
This function saves the system desc, if different from stored.
[ "This", "function", "saves", "the", "system", "desc", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L135-L140
train
37,576
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_sys_name_uneq_store
def remote_sys_name_uneq_store(self, remote_system_name): """This function saves the system name, if different from stored. """ if remote_system_name != self.remote_system_name: self.remote_system_name = remote_system_name return True return False
python
def remote_sys_name_uneq_store(self, remote_system_name): """This function saves the system name, if different from stored. """ if remote_system_name != self.remote_system_name: self.remote_system_name = remote_system_name return True return False
[ "def", "remote_sys_name_uneq_store", "(", "self", ",", "remote_system_name", ")", ":", "if", "remote_system_name", "!=", "self", ".", "remote_system_name", ":", "self", ".", "remote_system_name", "=", "remote_system_name", "return", "True", "return", "False" ]
This function saves the system name, if different from stored.
[ "This", "function", "saves", "the", "system", "name", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L142-L147
train
37,577
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_port_uneq_store
def remote_port_uneq_store(self, remote_port): """This function saves the port, if different from stored. """ if remote_port != self.remote_port: self.remote_port = remote_port return True return False
python
def remote_port_uneq_store(self, remote_port): """This function saves the port, if different from stored. """ if remote_port != self.remote_port: self.remote_port = remote_port return True return False
[ "def", "remote_port_uneq_store", "(", "self", ",", "remote_port", ")", ":", "if", "remote_port", "!=", "self", ".", "remote_port", ":", "self", ".", "remote_port", "=", "remote_port", "return", "True", "return", "False" ]
This function saves the port, if different from stored.
[ "This", "function", "saves", "the", "port", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L149-L154
train
37,578
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_chassis_id_mac_uneq_store
def remote_chassis_id_mac_uneq_store(self, remote_chassis_id_mac): """This function saves the Chassis MAC, if different from stored. """ if remote_chassis_id_mac != self.remote_chassis_id_mac: self.remote_chassis_id_mac = remote_chassis_id_mac return True return False
python
def remote_chassis_id_mac_uneq_store(self, remote_chassis_id_mac): """This function saves the Chassis MAC, if different from stored. """ if remote_chassis_id_mac != self.remote_chassis_id_mac: self.remote_chassis_id_mac = remote_chassis_id_mac return True return False
[ "def", "remote_chassis_id_mac_uneq_store", "(", "self", ",", "remote_chassis_id_mac", ")", ":", "if", "remote_chassis_id_mac", "!=", "self", ".", "remote_chassis_id_mac", ":", "self", ".", "remote_chassis_id_mac", "=", "remote_chassis_id_mac", "return", "True", "return", ...
This function saves the Chassis MAC, if different from stored.
[ "This", "function", "saves", "the", "Chassis", "MAC", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L156-L161
train
37,579
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoIntfAttr.remote_port_id_mac_uneq_store
def remote_port_id_mac_uneq_store(self, remote_port_id_mac): """This function saves the port MAC, if different from stored. """ if remote_port_id_mac != self.remote_port_id_mac: self.remote_port_id_mac = remote_port_id_mac return True return False
python
def remote_port_id_mac_uneq_store(self, remote_port_id_mac): """This function saves the port MAC, if different from stored. """ if remote_port_id_mac != self.remote_port_id_mac: self.remote_port_id_mac = remote_port_id_mac return True return False
[ "def", "remote_port_id_mac_uneq_store", "(", "self", ",", "remote_port_id_mac", ")", ":", "if", "remote_port_id_mac", "!=", "self", ".", "remote_port_id_mac", ":", "self", ".", "remote_port_id_mac", "=", "remote_port_id_mac", "return", "True", "return", "False" ]
This function saves the port MAC, if different from stored.
[ "This", "function", "saves", "the", "port", "MAC", "if", "different", "from", "stored", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L163-L168
train
37,580
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDiscPubApi.get_lldp_status
def get_lldp_status(cls, intf): """Retrieves the LLDP status. """ if intf not in cls.topo_intf_obj_dict: LOG.error("Interface %s not configured at all", intf) return False intf_obj = cls.topo_intf_obj_dict.get(intf) return intf_obj.get_lldp_status()
python
def get_lldp_status(cls, intf): """Retrieves the LLDP status. """ if intf not in cls.topo_intf_obj_dict: LOG.error("Interface %s not configured at all", intf) return False intf_obj = cls.topo_intf_obj_dict.get(intf) return intf_obj.get_lldp_status()
[ "def", "get_lldp_status", "(", "cls", ",", "intf", ")", ":", "if", "intf", "not", "in", "cls", ".", "topo_intf_obj_dict", ":", "LOG", ".", "error", "(", "\"Interface %s not configured at all\"", ",", "intf", ")", "return", "False", "intf_obj", "=", "cls", "....
Retrieves the LLDP status.
[ "Retrieves", "the", "LLDP", "status", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L180-L186
train
37,581
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc._init_cfg_interfaces
def _init_cfg_interfaces(self, cb, intf_list=None, all_intf=True): """Configure the interfaces during init time. """ if not all_intf: self.intf_list = intf_list else: self.intf_list = sys_utils.get_all_run_phy_intf() self.cb = cb self.intf_attr = {} self.cfg_lldp_interface_list(self.intf_list)
python
def _init_cfg_interfaces(self, cb, intf_list=None, all_intf=True): """Configure the interfaces during init time. """ if not all_intf: self.intf_list = intf_list else: self.intf_list = sys_utils.get_all_run_phy_intf() self.cb = cb self.intf_attr = {} self.cfg_lldp_interface_list(self.intf_list)
[ "def", "_init_cfg_interfaces", "(", "self", ",", "cb", ",", "intf_list", "=", "None", ",", "all_intf", "=", "True", ")", ":", "if", "not", "all_intf", ":", "self", ".", "intf_list", "=", "intf_list", "else", ":", "self", ".", "intf_list", "=", "sys_utils...
Configure the interfaces during init time.
[ "Configure", "the", "interfaces", "during", "init", "time", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L208-L216
train
37,582
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc.cfg_intf
def cfg_intf(self, protocol_interface, phy_interface=None): """Called by application to add an interface to the list. """ self.intf_list.append(protocol_interface) self.cfg_lldp_interface(protocol_interface, phy_interface)
python
def cfg_intf(self, protocol_interface, phy_interface=None): """Called by application to add an interface to the list. """ self.intf_list.append(protocol_interface) self.cfg_lldp_interface(protocol_interface, phy_interface)
[ "def", "cfg_intf", "(", "self", ",", "protocol_interface", ",", "phy_interface", "=", "None", ")", ":", "self", ".", "intf_list", ".", "append", "(", "protocol_interface", ")", "self", ".", "cfg_lldp_interface", "(", "protocol_interface", ",", "phy_interface", "...
Called by application to add an interface to the list.
[ "Called", "by", "application", "to", "add", "an", "interface", "to", "the", "list", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L218-L221
train
37,583
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc.create_attr_obj
def create_attr_obj(self, protocol_interface, phy_interface): """Creates the local interface attribute object and stores it. """ self.intf_attr[protocol_interface] = TopoIntfAttr( protocol_interface, phy_interface) self.store_obj(protocol_interface, self.intf_attr[protocol_interface])
python
def create_attr_obj(self, protocol_interface, phy_interface): """Creates the local interface attribute object and stores it. """ self.intf_attr[protocol_interface] = TopoIntfAttr( protocol_interface, phy_interface) self.store_obj(protocol_interface, self.intf_attr[protocol_interface])
[ "def", "create_attr_obj", "(", "self", ",", "protocol_interface", ",", "phy_interface", ")", ":", "self", ".", "intf_attr", "[", "protocol_interface", "]", "=", "TopoIntfAttr", "(", "protocol_interface", ",", "phy_interface", ")", "self", ".", "store_obj", "(", ...
Creates the local interface attribute object and stores it.
[ "Creates", "the", "local", "interface", "attribute", "object", "and", "stores", "it", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L239-L243
train
37,584
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc.cmp_store_tlv_params
def cmp_store_tlv_params(self, intf, tlv_data): """Compare and store the received TLV. Compares the received TLV with stored TLV. Store the new TLV if it is different. """ flag = False attr_obj = self.get_attr_obj(intf) remote_evb_mode = self.pub_lldp.get_remote_evb_mode(tlv_data) if attr_obj.remote_evb_mode_uneq_store(remote_evb_mode): flag = True remote_evb_cfgd = self.pub_lldp.get_remote_evb_cfgd(tlv_data) if attr_obj.remote_evb_cfgd_uneq_store(remote_evb_cfgd): flag = True remote_mgmt_addr = self.pub_lldp.get_remote_mgmt_addr(tlv_data) if attr_obj.remote_mgmt_addr_uneq_store(remote_mgmt_addr): flag = True remote_sys_desc = self.pub_lldp.get_remote_sys_desc(tlv_data) if attr_obj.remote_sys_desc_uneq_store(remote_sys_desc): flag = True remote_sys_name = self.pub_lldp.get_remote_sys_name(tlv_data) if attr_obj.remote_sys_name_uneq_store(remote_sys_name): flag = True remote_port = self.pub_lldp.get_remote_port(tlv_data) if attr_obj.remote_port_uneq_store(remote_port): flag = True remote_chassis_id_mac = self.pub_lldp.\ get_remote_chassis_id_mac(tlv_data) if attr_obj.remote_chassis_id_mac_uneq_store(remote_chassis_id_mac): flag = True remote_port_id_mac = self.pub_lldp.get_remote_port_id_mac(tlv_data) if attr_obj.remote_port_id_mac_uneq_store(remote_port_id_mac): flag = True return flag
python
def cmp_store_tlv_params(self, intf, tlv_data): """Compare and store the received TLV. Compares the received TLV with stored TLV. Store the new TLV if it is different. """ flag = False attr_obj = self.get_attr_obj(intf) remote_evb_mode = self.pub_lldp.get_remote_evb_mode(tlv_data) if attr_obj.remote_evb_mode_uneq_store(remote_evb_mode): flag = True remote_evb_cfgd = self.pub_lldp.get_remote_evb_cfgd(tlv_data) if attr_obj.remote_evb_cfgd_uneq_store(remote_evb_cfgd): flag = True remote_mgmt_addr = self.pub_lldp.get_remote_mgmt_addr(tlv_data) if attr_obj.remote_mgmt_addr_uneq_store(remote_mgmt_addr): flag = True remote_sys_desc = self.pub_lldp.get_remote_sys_desc(tlv_data) if attr_obj.remote_sys_desc_uneq_store(remote_sys_desc): flag = True remote_sys_name = self.pub_lldp.get_remote_sys_name(tlv_data) if attr_obj.remote_sys_name_uneq_store(remote_sys_name): flag = True remote_port = self.pub_lldp.get_remote_port(tlv_data) if attr_obj.remote_port_uneq_store(remote_port): flag = True remote_chassis_id_mac = self.pub_lldp.\ get_remote_chassis_id_mac(tlv_data) if attr_obj.remote_chassis_id_mac_uneq_store(remote_chassis_id_mac): flag = True remote_port_id_mac = self.pub_lldp.get_remote_port_id_mac(tlv_data) if attr_obj.remote_port_id_mac_uneq_store(remote_port_id_mac): flag = True return flag
[ "def", "cmp_store_tlv_params", "(", "self", ",", "intf", ",", "tlv_data", ")", ":", "flag", "=", "False", "attr_obj", "=", "self", ".", "get_attr_obj", "(", "intf", ")", "remote_evb_mode", "=", "self", ".", "pub_lldp", ".", "get_remote_evb_mode", "(", "tlv_d...
Compare and store the received TLV. Compares the received TLV with stored TLV. Store the new TLV if it is different.
[ "Compare", "and", "store", "the", "received", "TLV", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L249-L282
train
37,585
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc.cfg_lldp_interface
def cfg_lldp_interface(self, protocol_interface, phy_interface=None): """Cfg LLDP on interface and create object. """ if phy_interface is None: phy_interface = protocol_interface self.create_attr_obj(protocol_interface, phy_interface) ret = self.pub_lldp.enable_lldp(protocol_interface) attr_obj = self.get_attr_obj(protocol_interface) attr_obj.update_lldp_status(ret)
python
def cfg_lldp_interface(self, protocol_interface, phy_interface=None): """Cfg LLDP on interface and create object. """ if phy_interface is None: phy_interface = protocol_interface self.create_attr_obj(protocol_interface, phy_interface) ret = self.pub_lldp.enable_lldp(protocol_interface) attr_obj = self.get_attr_obj(protocol_interface) attr_obj.update_lldp_status(ret)
[ "def", "cfg_lldp_interface", "(", "self", ",", "protocol_interface", ",", "phy_interface", "=", "None", ")", ":", "if", "phy_interface", "is", "None", ":", "phy_interface", "=", "protocol_interface", "self", ".", "create_attr_obj", "(", "protocol_interface", ",", ...
Cfg LLDP on interface and create object.
[ "Cfg", "LLDP", "on", "interface", "and", "create", "object", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L284-L291
train
37,586
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc.periodic_discovery_task
def periodic_discovery_task(self): """Periodic task that checks the interface TLV attributes. """ try: self._periodic_task_int() except Exception as exc: LOG.error("Exception caught in periodic discovery task %s", str(exc))
python
def periodic_discovery_task(self): """Periodic task that checks the interface TLV attributes. """ try: self._periodic_task_int() except Exception as exc: LOG.error("Exception caught in periodic discovery task %s", str(exc))
[ "def", "periodic_discovery_task", "(", "self", ")", ":", "try", ":", "self", ".", "_periodic_task_int", "(", ")", "except", "Exception", "as", "exc", ":", "LOG", ".", "error", "(", "\"Exception caught in periodic discovery task %s\"", ",", "str", "(", "exc", ")"...
Periodic task that checks the interface TLV attributes.
[ "Periodic", "task", "that", "checks", "the", "interface", "TLV", "attributes", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L298-L304
train
37,587
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc._check_bond_interface_change
def _check_bond_interface_change(self, phy_interface, attr_obj): """Check if there's any change in bond interface. First check if the interface passed itself is a bond-interface and then retrieve the member list and compare. Next, check if the interface passed is a part of the bond interface and then retrieve the member list and compare. """ bond_phy = sys_utils.get_bond_intf(phy_interface) if sys_utils.is_intf_bond(phy_interface): bond_intf = phy_interface else: bond_intf = bond_phy # This can be an addition or removal of the interface to a bond. bond_intf_change = attr_obj.cmp_update_bond_intf(bond_intf) return bond_intf_change
python
def _check_bond_interface_change(self, phy_interface, attr_obj): """Check if there's any change in bond interface. First check if the interface passed itself is a bond-interface and then retrieve the member list and compare. Next, check if the interface passed is a part of the bond interface and then retrieve the member list and compare. """ bond_phy = sys_utils.get_bond_intf(phy_interface) if sys_utils.is_intf_bond(phy_interface): bond_intf = phy_interface else: bond_intf = bond_phy # This can be an addition or removal of the interface to a bond. bond_intf_change = attr_obj.cmp_update_bond_intf(bond_intf) return bond_intf_change
[ "def", "_check_bond_interface_change", "(", "self", ",", "phy_interface", ",", "attr_obj", ")", ":", "bond_phy", "=", "sys_utils", ".", "get_bond_intf", "(", "phy_interface", ")", "if", "sys_utils", ".", "is_intf_bond", "(", "phy_interface", ")", ":", "bond_intf",...
Check if there's any change in bond interface. First check if the interface passed itself is a bond-interface and then retrieve the member list and compare. Next, check if the interface passed is a part of the bond interface and then retrieve the member list and compare.
[ "Check", "if", "there", "s", "any", "change", "in", "bond", "interface", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L306-L321
train
37,588
openstack/networking-cisco
networking_cisco/apps/saf/agent/topo_disc/topo_disc.py
TopoDisc._periodic_task_int
def _periodic_task_int(self): """Internal periodic discovery task routine to check TLV attributes. This routine retrieves the LLDP TLC's on all its configured interfaces. If the retrieved TLC is different than the stored TLV, it invokes the callback. """ for intf in self.intf_list: attr_obj = self.get_attr_obj(intf) status = attr_obj.get_lldp_status() if not status: ret = self.pub_lldp.enable_lldp(intf) attr_obj.update_lldp_status(ret) continue bond_intf_change = self._check_bond_interface_change( attr_obj.get_phy_interface(), attr_obj) tlv_data = self.pub_lldp.get_lldp_tlv(intf) # This should take care of storing the information of interest if self.cmp_store_tlv_params(intf, tlv_data) or ( attr_obj.get_db_retry_status() or bond_intf_change or ( attr_obj.get_topo_disc_send_cnt() > ( constants.TOPO_DISC_SEND_THRESHOLD))): # Passing the interface attribute object to CB ret = self.cb(intf, attr_obj) status = not ret attr_obj.store_db_retry_status(status) attr_obj.reset_topo_disc_send_cnt() else: attr_obj.incr_topo_disc_send_cnt()
python
def _periodic_task_int(self): """Internal periodic discovery task routine to check TLV attributes. This routine retrieves the LLDP TLC's on all its configured interfaces. If the retrieved TLC is different than the stored TLV, it invokes the callback. """ for intf in self.intf_list: attr_obj = self.get_attr_obj(intf) status = attr_obj.get_lldp_status() if not status: ret = self.pub_lldp.enable_lldp(intf) attr_obj.update_lldp_status(ret) continue bond_intf_change = self._check_bond_interface_change( attr_obj.get_phy_interface(), attr_obj) tlv_data = self.pub_lldp.get_lldp_tlv(intf) # This should take care of storing the information of interest if self.cmp_store_tlv_params(intf, tlv_data) or ( attr_obj.get_db_retry_status() or bond_intf_change or ( attr_obj.get_topo_disc_send_cnt() > ( constants.TOPO_DISC_SEND_THRESHOLD))): # Passing the interface attribute object to CB ret = self.cb(intf, attr_obj) status = not ret attr_obj.store_db_retry_status(status) attr_obj.reset_topo_disc_send_cnt() else: attr_obj.incr_topo_disc_send_cnt()
[ "def", "_periodic_task_int", "(", "self", ")", ":", "for", "intf", "in", "self", ".", "intf_list", ":", "attr_obj", "=", "self", ".", "get_attr_obj", "(", "intf", ")", "status", "=", "attr_obj", ".", "get_lldp_status", "(", ")", "if", "not", "status", ":...
Internal periodic discovery task routine to check TLV attributes. This routine retrieves the LLDP TLC's on all its configured interfaces. If the retrieved TLC is different than the stored TLV, it invokes the callback.
[ "Internal", "periodic", "discovery", "task", "routine", "to", "check", "TLV", "attributes", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/apps/saf/agent/topo_disc/topo_disc.py#L323-L351
train
37,589
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/nexus_restapi_client.py
CiscoNexusRestapiClient._get_cookie
def _get_cookie(self, mgmt_ip, config, refresh=False): """Performs authentication and retries cookie.""" if mgmt_ip not in self.credentials: return None security_data = self.credentials[mgmt_ip] verify = security_data[const.HTTPS_CERT_TUPLE] if not verify: verify = security_data[const.HTTPS_VERIFY_TUPLE] if not refresh and security_data[const.COOKIE_TUPLE]: return security_data[const.COOKIE_TUPLE], verify payload = {"aaaUser": {"attributes": { "name": security_data[const.UNAME_TUPLE], "pwd": security_data[const.PW_TUPLE]}}} headers = {"Content-type": "application/json", "Accept": "text/plain"} url = "{0}://{1}/api/aaaLogin.json".format(DEFAULT_SCHEME, mgmt_ip) try: response = self.session.request('POST', url, data=jsonutils.dumps(payload), headers=headers, verify=verify, timeout=self.timeout * 2) except Exception as e: raise cexc.NexusConnectFailed(nexus_host=mgmt_ip, exc=e) self.status = response.status_code if response.status_code == requests.codes.OK: cookie = response.headers.get('Set-Cookie') security_data = ( security_data[const.UNAME_TUPLE:const.COOKIE_TUPLE] + (cookie,)) self.credentials[mgmt_ip] = security_data return cookie, verify else: e = "REST API connect returned Error code: " e += str(self.status) raise cexc.NexusConnectFailed(nexus_host=mgmt_ip, exc=e)
python
def _get_cookie(self, mgmt_ip, config, refresh=False): """Performs authentication and retries cookie.""" if mgmt_ip not in self.credentials: return None security_data = self.credentials[mgmt_ip] verify = security_data[const.HTTPS_CERT_TUPLE] if not verify: verify = security_data[const.HTTPS_VERIFY_TUPLE] if not refresh and security_data[const.COOKIE_TUPLE]: return security_data[const.COOKIE_TUPLE], verify payload = {"aaaUser": {"attributes": { "name": security_data[const.UNAME_TUPLE], "pwd": security_data[const.PW_TUPLE]}}} headers = {"Content-type": "application/json", "Accept": "text/plain"} url = "{0}://{1}/api/aaaLogin.json".format(DEFAULT_SCHEME, mgmt_ip) try: response = self.session.request('POST', url, data=jsonutils.dumps(payload), headers=headers, verify=verify, timeout=self.timeout * 2) except Exception as e: raise cexc.NexusConnectFailed(nexus_host=mgmt_ip, exc=e) self.status = response.status_code if response.status_code == requests.codes.OK: cookie = response.headers.get('Set-Cookie') security_data = ( security_data[const.UNAME_TUPLE:const.COOKIE_TUPLE] + (cookie,)) self.credentials[mgmt_ip] = security_data return cookie, verify else: e = "REST API connect returned Error code: " e += str(self.status) raise cexc.NexusConnectFailed(nexus_host=mgmt_ip, exc=e)
[ "def", "_get_cookie", "(", "self", ",", "mgmt_ip", ",", "config", ",", "refresh", "=", "False", ")", ":", "if", "mgmt_ip", "not", "in", "self", ".", "credentials", ":", "return", "None", "security_data", "=", "self", ".", "credentials", "[", "mgmt_ip", "...
Performs authentication and retries cookie.
[ "Performs", "authentication", "and", "retries", "cookie", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/nexus_restapi_client.py#L61-L105
train
37,590
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusCfgMonitor._initialize_trunk_interfaces_to_none
def _initialize_trunk_interfaces_to_none(self, switch_ip, replay=True): """Initialize all nexus interfaces to trunk allowed none.""" try: # The following determines if the switch interfaces are # in place. If so, make sure they have a basic trunk # configuration applied to none. switch_ifs = self._mdriver._get_switch_interfaces( switch_ip, cfg_only=(False if replay else True)) if not switch_ifs: LOG.debug("Skipping switch %s which has no configured " "interfaces", switch_ip) return self._driver.initialize_all_switch_interfaces( switch_ifs, switch_ip) except Exception: with excutils.save_and_reraise_exception(): LOG.warning("Unable to initialize interfaces to " "switch %(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay init_interface') if self._mdriver.is_replay_enabled(): return
python
def _initialize_trunk_interfaces_to_none(self, switch_ip, replay=True): """Initialize all nexus interfaces to trunk allowed none.""" try: # The following determines if the switch interfaces are # in place. If so, make sure they have a basic trunk # configuration applied to none. switch_ifs = self._mdriver._get_switch_interfaces( switch_ip, cfg_only=(False if replay else True)) if not switch_ifs: LOG.debug("Skipping switch %s which has no configured " "interfaces", switch_ip) return self._driver.initialize_all_switch_interfaces( switch_ifs, switch_ip) except Exception: with excutils.save_and_reraise_exception(): LOG.warning("Unable to initialize interfaces to " "switch %(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay init_interface') if self._mdriver.is_replay_enabled(): return
[ "def", "_initialize_trunk_interfaces_to_none", "(", "self", ",", "switch_ip", ",", "replay", "=", "True", ")", ":", "try", ":", "# The following determines if the switch interfaces are", "# in place. If so, make sure they have a basic trunk", "# configuration applied to none.", "s...
Initialize all nexus interfaces to trunk allowed none.
[ "Initialize", "all", "nexus", "interfaces", "to", "trunk", "allowed", "none", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L121-L146
train
37,591
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusCfgMonitor.replay_config
def replay_config(self, switch_ip): """Sends pending config data in OpenStack to Nexus.""" LOG.debug("Replaying config for switch ip %(switch_ip)s", {'switch_ip': switch_ip}) # Before replaying all config, initialize trunk interfaces # to none as required. If this fails, the switch may not # be up all the way. Quit and retry later. try: self._initialize_trunk_interfaces_to_none(switch_ip) except Exception: return nve_bindings = nxos_db.get_nve_switch_bindings(switch_ip) # If configured to set global VXLAN values and # there exists VXLAN data base entries, then configure # the "interface nve" entry on the switch. if (len(nve_bindings) > 0 and cfg.CONF.ml2_cisco.vxlan_global_config): LOG.debug("Nexus: Replay NVE Interface") loopback = self._mdriver.get_nve_loopback(switch_ip) self._driver.enable_vxlan_feature(switch_ip, const.NVE_INT_NUM, loopback) for x in nve_bindings: try: self._driver.create_nve_member(switch_ip, const.NVE_INT_NUM, x.vni, x.mcast_group) except Exception as e: LOG.error("Failed to configure nve_member for " "switch %(switch_ip)s, vni %(vni)s" "Reason:%(reason)s ", {'switch_ip': switch_ip, 'vni': x.vni, 'reason': e}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay create_nve_member') return try: port_bindings = nxos_db.get_nexusport_switch_bindings(switch_ip) except excep.NexusPortBindingNotFound: LOG.warning("No port entries found for switch ip " "%(switch_ip)s during replay.", {'switch_ip': switch_ip}) return try: self._mdriver.configure_switch_entries( switch_ip, port_bindings) except Exception as e: LOG.error("Unexpected exception while replaying " "entries for switch %(switch_ip)s, Reason:%(reason)s ", {'switch_ip': switch_ip, 'reason': e}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay switch_entries')
python
def replay_config(self, switch_ip): """Sends pending config data in OpenStack to Nexus.""" LOG.debug("Replaying config for switch ip %(switch_ip)s", {'switch_ip': switch_ip}) # Before replaying all config, initialize trunk interfaces # to none as required. If this fails, the switch may not # be up all the way. Quit and retry later. try: self._initialize_trunk_interfaces_to_none(switch_ip) except Exception: return nve_bindings = nxos_db.get_nve_switch_bindings(switch_ip) # If configured to set global VXLAN values and # there exists VXLAN data base entries, then configure # the "interface nve" entry on the switch. if (len(nve_bindings) > 0 and cfg.CONF.ml2_cisco.vxlan_global_config): LOG.debug("Nexus: Replay NVE Interface") loopback = self._mdriver.get_nve_loopback(switch_ip) self._driver.enable_vxlan_feature(switch_ip, const.NVE_INT_NUM, loopback) for x in nve_bindings: try: self._driver.create_nve_member(switch_ip, const.NVE_INT_NUM, x.vni, x.mcast_group) except Exception as e: LOG.error("Failed to configure nve_member for " "switch %(switch_ip)s, vni %(vni)s" "Reason:%(reason)s ", {'switch_ip': switch_ip, 'vni': x.vni, 'reason': e}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay create_nve_member') return try: port_bindings = nxos_db.get_nexusport_switch_bindings(switch_ip) except excep.NexusPortBindingNotFound: LOG.warning("No port entries found for switch ip " "%(switch_ip)s during replay.", {'switch_ip': switch_ip}) return try: self._mdriver.configure_switch_entries( switch_ip, port_bindings) except Exception as e: LOG.error("Unexpected exception while replaying " "entries for switch %(switch_ip)s, Reason:%(reason)s ", {'switch_ip': switch_ip, 'reason': e}) self._mdriver.register_switch_as_inactive(switch_ip, 'replay switch_entries')
[ "def", "replay_config", "(", "self", ",", "switch_ip", ")", ":", "LOG", ".", "debug", "(", "\"Replaying config for switch ip %(switch_ip)s\"", ",", "{", "'switch_ip'", ":", "switch_ip", "}", ")", "# Before replaying all config, initialize trunk interfaces", "# to none as re...
Sends pending config data in OpenStack to Nexus.
[ "Sends", "pending", "config", "data", "in", "OpenStack", "to", "Nexus", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L148-L203
train
37,592
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusCfgMonitor.check_connections
def check_connections(self): """Check connection between OpenStack to Nexus device.""" switch_connections = self._mdriver.get_all_switch_ips() for switch_ip in switch_connections: state = self._mdriver.get_switch_ip_and_active_state(switch_ip) config_failure = self._mdriver.get_switch_replay_failure( const.FAIL_CONFIG, switch_ip) contact_failure = self._mdriver.get_switch_replay_failure( const.FAIL_CONTACT, switch_ip) LOG.debug("check_connections() thread %(thid)d, switch " "%(switch_ip)s state %(state)s " "contact_failure %(contact_failure)d " "config_failure %(config_failure)d ", {'thid': threading.current_thread().ident, 'switch_ip': switch_ip, 'state': state, 'contact_failure': contact_failure, 'config_failure': config_failure}) try: # Send a simple get nexus type to determine if # the switch is up nexus_type = self._driver.get_nexus_type(switch_ip) except Exception: if state != const.SWITCH_INACTIVE: LOG.error("Lost connection to switch ip " "%(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.set_switch_ip_and_active_state( switch_ip, const.SWITCH_INACTIVE) else: self._mdriver.incr_switch_replay_failure( const.FAIL_CONTACT, switch_ip) else: if state == const.SWITCH_RESTORE_S2: try: self._mdriver.configure_next_batch_of_vlans(switch_ip) except Exception as e: LOG.error("Unexpected exception while replaying " "entries for switch %(switch_ip)s, " "Reason:%(reason)s ", {'switch_ip': switch_ip, 'reason': e}) self._mdriver.register_switch_as_inactive( switch_ip, 'replay next_vlan_batch') continue if state == const.SWITCH_INACTIVE: self._configure_nexus_type(switch_ip, nexus_type) LOG.info("Re-established connection to switch " "ip %(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.set_switch_ip_and_active_state( switch_ip, const.SWITCH_RESTORE_S1) self.replay_config(switch_ip) # If replay failed, it stops trying to configure db entries # and sets switch state to inactive so this caller knows # it failed. If it did fail, we increment the # retry counter else reset it to 0. if self._mdriver.get_switch_ip_and_active_state( switch_ip) == const.SWITCH_INACTIVE: self._mdriver.incr_switch_replay_failure( const.FAIL_CONFIG, switch_ip) LOG.warning("Replay config failed for " "ip %(switch_ip)s", {'switch_ip': switch_ip}) else: self._mdriver.reset_switch_replay_failure( const.FAIL_CONFIG, switch_ip) self._mdriver.reset_switch_replay_failure( const.FAIL_CONTACT, switch_ip) LOG.info("Replay config successful for " "ip %(switch_ip)s", {'switch_ip': switch_ip})
python
def check_connections(self): """Check connection between OpenStack to Nexus device.""" switch_connections = self._mdriver.get_all_switch_ips() for switch_ip in switch_connections: state = self._mdriver.get_switch_ip_and_active_state(switch_ip) config_failure = self._mdriver.get_switch_replay_failure( const.FAIL_CONFIG, switch_ip) contact_failure = self._mdriver.get_switch_replay_failure( const.FAIL_CONTACT, switch_ip) LOG.debug("check_connections() thread %(thid)d, switch " "%(switch_ip)s state %(state)s " "contact_failure %(contact_failure)d " "config_failure %(config_failure)d ", {'thid': threading.current_thread().ident, 'switch_ip': switch_ip, 'state': state, 'contact_failure': contact_failure, 'config_failure': config_failure}) try: # Send a simple get nexus type to determine if # the switch is up nexus_type = self._driver.get_nexus_type(switch_ip) except Exception: if state != const.SWITCH_INACTIVE: LOG.error("Lost connection to switch ip " "%(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.set_switch_ip_and_active_state( switch_ip, const.SWITCH_INACTIVE) else: self._mdriver.incr_switch_replay_failure( const.FAIL_CONTACT, switch_ip) else: if state == const.SWITCH_RESTORE_S2: try: self._mdriver.configure_next_batch_of_vlans(switch_ip) except Exception as e: LOG.error("Unexpected exception while replaying " "entries for switch %(switch_ip)s, " "Reason:%(reason)s ", {'switch_ip': switch_ip, 'reason': e}) self._mdriver.register_switch_as_inactive( switch_ip, 'replay next_vlan_batch') continue if state == const.SWITCH_INACTIVE: self._configure_nexus_type(switch_ip, nexus_type) LOG.info("Re-established connection to switch " "ip %(switch_ip)s", {'switch_ip': switch_ip}) self._mdriver.set_switch_ip_and_active_state( switch_ip, const.SWITCH_RESTORE_S1) self.replay_config(switch_ip) # If replay failed, it stops trying to configure db entries # and sets switch state to inactive so this caller knows # it failed. If it did fail, we increment the # retry counter else reset it to 0. if self._mdriver.get_switch_ip_and_active_state( switch_ip) == const.SWITCH_INACTIVE: self._mdriver.incr_switch_replay_failure( const.FAIL_CONFIG, switch_ip) LOG.warning("Replay config failed for " "ip %(switch_ip)s", {'switch_ip': switch_ip}) else: self._mdriver.reset_switch_replay_failure( const.FAIL_CONFIG, switch_ip) self._mdriver.reset_switch_replay_failure( const.FAIL_CONTACT, switch_ip) LOG.info("Replay config successful for " "ip %(switch_ip)s", {'switch_ip': switch_ip})
[ "def", "check_connections", "(", "self", ")", ":", "switch_connections", "=", "self", ".", "_mdriver", ".", "get_all_switch_ips", "(", ")", "for", "switch_ip", "in", "switch_connections", ":", "state", "=", "self", ".", "_mdriver", ".", "get_switch_ip_and_active_s...
Check connection between OpenStack to Nexus device.
[ "Check", "connection", "between", "OpenStack", "to", "Nexus", "device", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L205-L277
train
37,593
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver._pop_vlan_range
def _pop_vlan_range(self, switch_ip, size): """Extract a specific number of vlans from storage. Purpose: Can only send a limited number of vlans to Nexus at a time. Sample Use Cases: 1) vlan_range is a list of vlans. If there is a list 1000, 1001, 1002, thru 2000 and size is 6, then the result is '1000-1005' and 1006 thru 2000 is pushed back into storage. 2) if the list is 1000, 1003, 1004, 1006 thru 2000 and size is 6, then the result is '1000, 1003-1004, 1006-1008' and 1009 thru 2000 is pushed back into storage for next time. """ vlan_range = self._get_switch_vlan_range(switch_ip) sized_range = '' fr = 0 to = 0 # if vlan_range not empty and haven't met requested size while size > 0 and vlan_range: vlan_id, vni = vlan_range.pop(0) size -= 1 if fr == 0 and to == 0: fr = vlan_id to = vlan_id else: diff = vlan_id - to if diff == 1: to = vlan_id else: if fr == to: sized_range += str(to) + ',' else: sized_range += str(fr) + '-' sized_range += str(to) + ',' fr = vlan_id to = vlan_id if fr != 0: if fr == to: sized_range += str(to) else: sized_range += str(fr) + '-' sized_range += str(to) self._save_switch_vlan_range(switch_ip, vlan_range) return sized_range
python
def _pop_vlan_range(self, switch_ip, size): """Extract a specific number of vlans from storage. Purpose: Can only send a limited number of vlans to Nexus at a time. Sample Use Cases: 1) vlan_range is a list of vlans. If there is a list 1000, 1001, 1002, thru 2000 and size is 6, then the result is '1000-1005' and 1006 thru 2000 is pushed back into storage. 2) if the list is 1000, 1003, 1004, 1006 thru 2000 and size is 6, then the result is '1000, 1003-1004, 1006-1008' and 1009 thru 2000 is pushed back into storage for next time. """ vlan_range = self._get_switch_vlan_range(switch_ip) sized_range = '' fr = 0 to = 0 # if vlan_range not empty and haven't met requested size while size > 0 and vlan_range: vlan_id, vni = vlan_range.pop(0) size -= 1 if fr == 0 and to == 0: fr = vlan_id to = vlan_id else: diff = vlan_id - to if diff == 1: to = vlan_id else: if fr == to: sized_range += str(to) + ',' else: sized_range += str(fr) + '-' sized_range += str(to) + ',' fr = vlan_id to = vlan_id if fr != 0: if fr == to: sized_range += str(to) else: sized_range += str(fr) + '-' sized_range += str(to) self._save_switch_vlan_range(switch_ip, vlan_range) return sized_range
[ "def", "_pop_vlan_range", "(", "self", ",", "switch_ip", ",", "size", ")", ":", "vlan_range", "=", "self", ".", "_get_switch_vlan_range", "(", "switch_ip", ")", "sized_range", "=", "''", "fr", "=", "0", "to", "=", "0", "# if vlan_range not empty and haven't met ...
Extract a specific number of vlans from storage. Purpose: Can only send a limited number of vlans to Nexus at a time. Sample Use Cases: 1) vlan_range is a list of vlans. If there is a list 1000, 1001, 1002, thru 2000 and size is 6, then the result is '1000-1005' and 1006 thru 2000 is pushed back into storage. 2) if the list is 1000, 1003, 1004, 1006 thru 2000 and size is 6, then the result is '1000, 1003-1004, 1006-1008' and 1009 thru 2000 is pushed back into storage for next time.
[ "Extract", "a", "specific", "number", "of", "vlans", "from", "storage", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L505-L552
train
37,594
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver.get_all_switch_ips
def get_all_switch_ips(self): """Using reserved switch binding get all switch ips.""" switch_connections = [] try: bindings = nxos_db.get_reserved_switch_binding() except excep.NexusPortBindingNotFound: LOG.error("No switch bindings in the port data base") bindings = [] for switch in bindings: switch_connections.append(switch.switch_ip) return switch_connections
python
def get_all_switch_ips(self): """Using reserved switch binding get all switch ips.""" switch_connections = [] try: bindings = nxos_db.get_reserved_switch_binding() except excep.NexusPortBindingNotFound: LOG.error("No switch bindings in the port data base") bindings = [] for switch in bindings: switch_connections.append(switch.switch_ip) return switch_connections
[ "def", "get_all_switch_ips", "(", "self", ")", ":", "switch_connections", "=", "[", "]", "try", ":", "bindings", "=", "nxos_db", ".", "get_reserved_switch_binding", "(", ")", "except", "excep", ".", "NexusPortBindingNotFound", ":", "LOG", ".", "error", "(", "\...
Using reserved switch binding get all switch ips.
[ "Using", "reserved", "switch", "binding", "get", "all", "switch", "ips", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L578-L590
train
37,595
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver._get_baremetal_switch_info
def _get_baremetal_switch_info(self, link_info): """Get switch_info dictionary from context.""" try: switch_info = link_info['switch_info'] if not isinstance(switch_info, dict): switch_info = jsonutils.loads(switch_info) except Exception as e: LOG.error("switch_info can't be decoded: %(exp)s", {"exp": e}) switch_info = {} return switch_info
python
def _get_baremetal_switch_info(self, link_info): """Get switch_info dictionary from context.""" try: switch_info = link_info['switch_info'] if not isinstance(switch_info, dict): switch_info = jsonutils.loads(switch_info) except Exception as e: LOG.error("switch_info can't be decoded: %(exp)s", {"exp": e}) switch_info = {} return switch_info
[ "def", "_get_baremetal_switch_info", "(", "self", ",", "link_info", ")", ":", "try", ":", "switch_info", "=", "link_info", "[", "'switch_info'", "]", "if", "not", "isinstance", "(", "switch_info", ",", "dict", ")", ":", "switch_info", "=", "jsonutils", ".", ...
Get switch_info dictionary from context.
[ "Get", "switch_info", "dictionary", "from", "context", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L620-L632
train
37,596
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver._supported_baremetal_transaction
def _supported_baremetal_transaction(self, context): """Verify transaction is complete and for us.""" port = context.current if self.trunk.is_trunk_subport_baremetal(port): return self._baremetal_set_binding(context) if not nexus_help.is_baremetal(port): return False if bc.portbindings.PROFILE not in port: return False profile = port[bc.portbindings.PROFILE] if 'local_link_information' not in profile: return False all_link_info = profile['local_link_information'] selected = False for link_info in all_link_info: if 'port_id' not in link_info: return False switch_info = self._get_baremetal_switch_info( link_info) if 'switch_ip' in switch_info: switch_ip = switch_info['switch_ip'] else: return False if self._switch_defined(switch_ip): selected = True else: LOG.warning("Skip switch %s. Not configured " "in ini file" % switch_ip) if not selected: return False selected = self._baremetal_set_binding(context, all_link_info) if selected: self._init_baremetal_trunk_interfaces( context.current, context.top_bound_segment) if self.trunk.is_trunk_parentport(port): self.trunk.update_subports(port) return selected
python
def _supported_baremetal_transaction(self, context): """Verify transaction is complete and for us.""" port = context.current if self.trunk.is_trunk_subport_baremetal(port): return self._baremetal_set_binding(context) if not nexus_help.is_baremetal(port): return False if bc.portbindings.PROFILE not in port: return False profile = port[bc.portbindings.PROFILE] if 'local_link_information' not in profile: return False all_link_info = profile['local_link_information'] selected = False for link_info in all_link_info: if 'port_id' not in link_info: return False switch_info = self._get_baremetal_switch_info( link_info) if 'switch_ip' in switch_info: switch_ip = switch_info['switch_ip'] else: return False if self._switch_defined(switch_ip): selected = True else: LOG.warning("Skip switch %s. Not configured " "in ini file" % switch_ip) if not selected: return False selected = self._baremetal_set_binding(context, all_link_info) if selected: self._init_baremetal_trunk_interfaces( context.current, context.top_bound_segment) if self.trunk.is_trunk_parentport(port): self.trunk.update_subports(port) return selected
[ "def", "_supported_baremetal_transaction", "(", "self", ",", "context", ")", ":", "port", "=", "context", ".", "current", "if", "self", ".", "trunk", ".", "is_trunk_subport_baremetal", "(", "port", ")", ":", "return", "self", ".", "_baremetal_set_binding", "(", ...
Verify transaction is complete and for us.
[ "Verify", "transaction", "is", "complete", "and", "for", "us", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L658-L709
train
37,597
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver._get_baremetal_switches
def _get_baremetal_switches(self, port): """Get switch ip addresses from baremetal transaction. This method is used to extract switch information from the transaction where VNIC_TYPE is baremetal. :param port: Received port transaction :returns: list of all switches :returns: list of only switches which are active """ all_switches = set() active_switches = set() all_link_info = port[bc.portbindings.PROFILE]['local_link_information'] for link_info in all_link_info: switch_info = self._get_baremetal_switch_info(link_info) if not switch_info: continue switch_ip = switch_info['switch_ip'] # If not for Nexus if not self._switch_defined(switch_ip): continue all_switches.add(switch_ip) if self.is_switch_active(switch_ip): active_switches.add(switch_ip) return list(all_switches), list(active_switches)
python
def _get_baremetal_switches(self, port): """Get switch ip addresses from baremetal transaction. This method is used to extract switch information from the transaction where VNIC_TYPE is baremetal. :param port: Received port transaction :returns: list of all switches :returns: list of only switches which are active """ all_switches = set() active_switches = set() all_link_info = port[bc.portbindings.PROFILE]['local_link_information'] for link_info in all_link_info: switch_info = self._get_baremetal_switch_info(link_info) if not switch_info: continue switch_ip = switch_info['switch_ip'] # If not for Nexus if not self._switch_defined(switch_ip): continue all_switches.add(switch_ip) if self.is_switch_active(switch_ip): active_switches.add(switch_ip) return list(all_switches), list(active_switches)
[ "def", "_get_baremetal_switches", "(", "self", ",", "port", ")", ":", "all_switches", "=", "set", "(", ")", "active_switches", "=", "set", "(", ")", "all_link_info", "=", "port", "[", "bc", ".", "portbindings", ".", "PROFILE", "]", "[", "'local_link_informat...
Get switch ip addresses from baremetal transaction. This method is used to extract switch information from the transaction where VNIC_TYPE is baremetal. :param port: Received port transaction :returns: list of all switches :returns: list of only switches which are active
[ "Get", "switch", "ip", "addresses", "from", "baremetal", "transaction", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L711-L739
train
37,598
openstack/networking-cisco
networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py
CiscoNexusMechanismDriver._get_baremetal_connections
def _get_baremetal_connections(self, port, only_active_switch=False, from_segment=False): """Get switch ips and interfaces from baremetal transaction. This method is used to extract switch/interface information from transactions where VNIC_TYPE is baremetal. :param port: Received port transaction :param only_active_switch: Indicator for selecting connections with switches that are active :param from_segment: only return interfaces from the segment/transaction as opposed to say port channels which are learned. :Returns: list of switch_ip, intf_type, port_id, is_native """ connections = [] is_native = False if self.trunk.is_trunk_subport(port) else True all_link_info = port[bc.portbindings.PROFILE]['local_link_information'] for link_info in all_link_info: # Extract port info intf_type, port = nexus_help.split_interface_name( link_info['port_id']) # Determine if this switch is to be skipped switch_info = self._get_baremetal_switch_info( link_info) if not switch_info: continue switch_ip = switch_info['switch_ip'] # If not for Nexus if not self._switch_defined(switch_ip): continue # Requested connections for only active switches if (only_active_switch and not self.is_switch_active(switch_ip)): continue ch_grp = 0 if not from_segment: try: reserved = nxos_db.get_switch_if_host_mappings( switch_ip, nexus_help.format_interface_name( intf_type, port)) if reserved[0].ch_grp > 0: ch_grp = reserved[0].ch_grp intf_type, port = nexus_help.split_interface_name( '', ch_grp) except excep.NexusHostMappingNotFound: pass connections.append((switch_ip, intf_type, port, is_native, ch_grp)) return connections
python
def _get_baremetal_connections(self, port, only_active_switch=False, from_segment=False): """Get switch ips and interfaces from baremetal transaction. This method is used to extract switch/interface information from transactions where VNIC_TYPE is baremetal. :param port: Received port transaction :param only_active_switch: Indicator for selecting connections with switches that are active :param from_segment: only return interfaces from the segment/transaction as opposed to say port channels which are learned. :Returns: list of switch_ip, intf_type, port_id, is_native """ connections = [] is_native = False if self.trunk.is_trunk_subport(port) else True all_link_info = port[bc.portbindings.PROFILE]['local_link_information'] for link_info in all_link_info: # Extract port info intf_type, port = nexus_help.split_interface_name( link_info['port_id']) # Determine if this switch is to be skipped switch_info = self._get_baremetal_switch_info( link_info) if not switch_info: continue switch_ip = switch_info['switch_ip'] # If not for Nexus if not self._switch_defined(switch_ip): continue # Requested connections for only active switches if (only_active_switch and not self.is_switch_active(switch_ip)): continue ch_grp = 0 if not from_segment: try: reserved = nxos_db.get_switch_if_host_mappings( switch_ip, nexus_help.format_interface_name( intf_type, port)) if reserved[0].ch_grp > 0: ch_grp = reserved[0].ch_grp intf_type, port = nexus_help.split_interface_name( '', ch_grp) except excep.NexusHostMappingNotFound: pass connections.append((switch_ip, intf_type, port, is_native, ch_grp)) return connections
[ "def", "_get_baremetal_connections", "(", "self", ",", "port", ",", "only_active_switch", "=", "False", ",", "from_segment", "=", "False", ")", ":", "connections", "=", "[", "]", "is_native", "=", "False", "if", "self", ".", "trunk", ".", "is_trunk_subport", ...
Get switch ips and interfaces from baremetal transaction. This method is used to extract switch/interface information from transactions where VNIC_TYPE is baremetal. :param port: Received port transaction :param only_active_switch: Indicator for selecting connections with switches that are active :param from_segment: only return interfaces from the segment/transaction as opposed to say port channels which are learned. :Returns: list of switch_ip, intf_type, port_id, is_native
[ "Get", "switch", "ips", "and", "interfaces", "from", "baremetal", "transaction", "." ]
aa58a30aec25b86f9aa5952b0863045975debfa9
https://github.com/openstack/networking-cisco/blob/aa58a30aec25b86f9aa5952b0863045975debfa9/networking_cisco/ml2_drivers/nexus/mech_cisco_nexus.py#L741-L804
train
37,599