+ "NOTE: If onfence-poweroff is set, the agent won't be able to power on the node again, it will have to be powered on manually or with other automation."
+ ),
+ "vendorurl": "http://www.amazon.com"
+ }
+ show_docs(options, docs)
+
+ if "--onfence-poweroff" not in options and options.get("--action", "") == "reboot":
+The fence_aws_vpc_net agent is a network and power fencing agent for AWS VPC that operates by manipulating security groups. This document outlines the design and architecture of the agent.
+
+## Class Diagram
+
+```mermaid
+classDiagram
+ class FenceAWSVPCNet {
+ -logger: Logger
+ -conn: boto3.resource
+ -options: dict
+ +main()
+ +define_new_opts()
+ +process_input()
+ +check_input()
+ +get_power_status()
+ +set_power_status()
+ }
+
+ class InstanceOperations {
+ +get_instance_id()
+ +get_instance_details()
+ +shutdown_instance()
+ +get_nodes_list()
+ }
+
+ class SecurityGroupOperations {
+ +modify_security_groups()
+ +create_backup_tag()
+ +restore_security_groups()
+ -validate_sg_changes()
+ }
+
+ class TagOperations {
+ +set_lastfence_tag()
+ +create_backup_tag()
+ +restore_from_backup()
+ -handle_chunked_tags()
+ }
+
+ class LoggingManager {
+ +configure_logging()
+ +configure_boto3_logging()
+ +handle_debug_file()
+ }
+
+ FenceAWSVPCNet --> InstanceOperations
+ FenceAWSVPCNet --> SecurityGroupOperations
+ FenceAWSVPCNet --> TagOperations
+ FenceAWSVPCNet --> LoggingManager
+ SecurityGroupOperations --> TagOperations
+```
+
+## Sequence Diagrams
+
+### Fence Operation (Power Off)
+
+```mermaid
+sequenceDiagram
+ participant Client
+ participant FenceAgent
+ participant AWS
+ participant SecurityGroups
+ participant Tags
+
+ Client->>FenceAgent: Execute fence operation
+ FenceAgent->>AWS: Validate AWS credentials
+ AWS-->>FenceAgent: Credentials valid
+
+ opt skip-race-check not set
+ FenceAgent->>AWS: Get self instance ID
+ AWS-->>FenceAgent: Instance ID
+ FenceAgent->>FenceAgent: Check for self-fencing
+ end
+
+ FenceAgent->>AWS: Get instance details
+ AWS-->>FenceAgent: Instance details
+
+ alt Instance is running
+ FenceAgent->>SecurityGroups: Backup current security groups
+ SecurityGroups-->>FenceAgent: Backup created
+
+ alt ignore-tag-write-failure not set
+ FenceAgent->>Tags: Create lastfence tag
+ Tags-->>FenceAgent: Tag created
+ end
+
+ FenceAgent->>SecurityGroups: Modify security groups
+ SecurityGroups-->>FenceAgent: Groups modified
+
+ opt onfence-poweroff enabled
+ FenceAgent->>AWS: Initiate shutdown
+ AWS-->>FenceAgent: Shutdown initiated
+ end
+
+ FenceAgent-->>Client: Success
+ else Instance not running
+ FenceAgent-->>Client: Fail - Instance not running
+ end
+```
+
+### Unfence Operation (Power On)
+
+```mermaid
+sequenceDiagram
+ participant Client
+ participant FenceAgent
+ participant AWS
+ participant SecurityGroups
+ participant Tags
+
+ Client->>FenceAgent: Execute unfence operation
+ FenceAgent->>AWS: Validate AWS credentials
+ AWS-->>FenceAgent: Credentials valid
+
+ alt unfence-ignore-restore not set
+ FenceAgent->>Tags: Get lastfence tag
+ Tags-->>FenceAgent: Lastfence tag
+
+ FenceAgent->>Tags: Get backup tags
+ Tags-->>FenceAgent: Backup tags
+
+ alt Valid backup found
+ FenceAgent->>SecurityGroups: Restore original security groups
+ SecurityGroups-->>FenceAgent: Groups restored
+
+ FenceAgent->>Tags: Cleanup backup tags
+ Tags-->>FenceAgent: Tags cleaned
+
+ FenceAgent-->>Client: Success
+ else No valid backup
+ FenceAgent-->>Client: Fail - No valid backup found
+ end
+ else
+ FenceAgent-->>Client: Success - Restore skipped
+ end
+```
+
+## Component Details
+
+### 1. Main Controller (FenceAWSVPCNet)
+- **Purpose**: Main entry point and orchestration
+- **Key Responsibilities**:
+ - Process command line options
+ - Initialize AWS connection
+ - Execute fence operations
+ - Handle logging and errors
+ - Manage self-fencing prevention
+ - Support tag write failure handling
+
+### 2. Instance Operations
+- **Purpose**: Handle EC2 instance operations
+- **Key Responsibilities**:
+ - Get instance details and metadata
+ - Handle instance power operations
+ - Validate instance states
+ - List and filter instances
+ - Handle instance shutdown
+
+### 3. Security Group Operations
+- **Purpose**: Manage security group operations
+- **Key Responsibilities**:
+ - Modify security groups (remove or keep-only modes)
+<resource-agent name="fence_aws_vpc_net" shortdesc="Fence agent for AWS (Amazon Web Services) Net" >
+<longdesc>fence_aws_vpc is a Network and Power Fencing agent for AWS VPC that works by manipulating security groups. It uses the boto3 library to connect to AWS.
+
+boto3 can be configured with AWS CLI or by creating ~/.aws/credentials.
+For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.html#configuration NOTE: If onfence-poweroff is set, the agent won't be able to power on the node again, it will have to be powered on manually or with other automation.</longdesc>
+ <shortdesc lang="en">Level of debugging detail in output. Defaults to the number of --verbose flags specified on the command line, or to 1 if verbose=1 in a stonith device configuration (i.e., on stdin).</shortdesc>