from rally.task import scenario
from rally.task import atomic
import time

@scenario.configure(name="ScenarioPlugin.esi_node_network_attach")
class EsiNodeNetworkAttachScenario(scenario.Scenario):
    def esi_node_network_attach(self, node, network=None, port=None, trunk=None, mac_address=None):
        """Scenario to test 'openstack esi node network attach' command."""
        command = f"openstack esi node network attach {node}"
        if network:
            command += f" --network {network}"
        if port:
            command += f" --port {port}"
        if trunk:
            command += f" --trunk {trunk}"
        if mac_address:
            command += f" --mac-address {mac_address}"
        
        start_time = time.time()
        output = self._run_command(command)
        end_time = time.time()
        execution_time = end_time - start_time

        self.add_output(name="esi_node_network_attach_output", description="Output of 'openstack esi node network attach' command.", data=output)
        self.add_output(name="esi_node_network_attach_execution_time", description="Execution time of 'openstack esi node network attach' command.", data=execution_time)

    def run(self):
        self.esi_node_network_attach(node,network,port,trunk,mac_address)


