Skip to content

Commit

Permalink
Copy dcnm_inventory action plugin and modify for dcnm_image_upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
allenrobel committed Dec 21, 2023
1 parent fc53763 commit 2ca3fb4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions plugins/action/dcnm_image_upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (c) 2024 Cisco and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

from ansible_collections.ansible.netcommon.plugins.action.network import (
ActionModule as ActionNetworkModule,
)
from ansible.utils.display import Display

display = Display()


class ActionModule(ActionNetworkModule):
def run(self, tmp=None, task_vars=None):

connection = self._connection
persistent_connect_timeout = connection.get_option("persistent_connect_timeout")
persistent_command_timeout = connection.get_option("persistent_command_timeout")

timeout = 1000

if (persistent_command_timeout < timeout or persistent_connect_timeout < timeout):
display.warning(
"PERSISTENT_COMMAND_TIMEOUT is %s"
% str(persistent_command_timeout),
self._play_context.remote_addr,
)
display.warning(
"PERSISTENT_CONNECT_TIMEOUT is %s"
% str(persistent_connect_timeout),
self._play_context.remote_addr,
)
msg = (
"PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT"
)
msg += " must be set to {0} seconds or higher when using dcnm_image_upgrade module.".format(timeout)
msg += " Current persistent_command_timeout setting:" + str(
persistent_command_timeout
)
msg += " Current persistent_connect_timeout setting:" + str(
persistent_connect_timeout
)
return {"failed": True, "msg": msg}

if self._task.args.get('state') == 'merged':
display.warning("Upgrading switches can take a while. Please be patient...")
self.result = super(ActionModule, self).run(task_vars=task_vars)
return self.result

0 comments on commit 2ca3fb4

Please sign in to comment.