"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 AWSConnection {
- -region: str
- -access_key: str
- -secret_key: str
- +establish_connection()
- +validate_credentials()
+ class InstanceOperations {
+ +get_instance_id()
+ +get_instance_details()
+ +shutdown_instance()
+ +get_nodes_list()
}
- class SecurityGroupManager {
+ class SecurityGroupOperations {
+modify_security_groups()
+create_backup_tag()
+restore_security_groups()
-validate_sg_changes()
}
- class InstanceManager {
- +get_instance_details()
- +shutdown_instance()
- +get_power_status()
- +set_power_status()
- -validate_instance_state()
- }
-
- class TagManager {
+ class TagOperations {
+set_lastfence_tag()
- +get_backup_tags()
- +cleanup_tags()
- -validate_tag_operations()
+ +create_backup_tag()
+ +restore_from_backup()
+ -handle_chunked_tags()
}
- FenceAWSVPCNet --> AWSConnection
- FenceAWSVPCNet --> SecurityGroupManager
- FenceAWSVPCNet --> InstanceManager
- SecurityGroupManager --> TagManager
- InstanceManager --> TagManager
+ 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
- FenceAgent->>Tags: Create lastfence tag
- Tags-->>FenceAgent: Tag 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
- FenceAgent->>Tags: Get lastfence tag
- Tags-->>FenceAgent: Lastfence tag
+ alt unfence-ignore-restore not set
+ FenceAgent->>Tags: Get lastfence tag
+ Tags-->>FenceAgent: Lastfence tag
- FenceAgent->>Tags: Get backup tags
- Tags-->>FenceAgent: Backup tags
+ FenceAgent->>Tags: Get backup tags
+ Tags-->>FenceAgent: Backup tags
- alt Valid backup found
- FenceAgent->>SecurityGroups: Restore original security groups
- SecurityGroups-->>FenceAgent: Groups restored
+ alt Valid backup found
+ FenceAgent->>SecurityGroups: Restore original security groups
+ SecurityGroups-->>FenceAgent: Groups restored
- FenceAgent->>Tags: Cleanup backup tags
- Tags-->>FenceAgent: Tags cleaned
+ FenceAgent->>Tags: Cleanup backup tags
+ Tags-->>FenceAgent: Tags cleaned
- FenceAgent-->>Client: Success
- else No valid backup
- FenceAgent-->>Client: Fail - No valid backup found
+ 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. AWS Connection Manager
-- **Purpose**: Handle AWS connectivity
+### 2. Instance Operations
+- **Purpose**: Handle EC2 instance operations
- **Key Responsibilities**:
- - Establish and maintain AWS connection
- - Handle credentials and regions
- - Manage API retries and timeouts
+ - Get instance details and metadata
+ - Handle instance power operations
+ - Validate instance states
+ - List and filter instances
+ - Handle instance shutdown
-### 3. Security Group Manager
+### 3. Security Group Operations
- **Purpose**: Manage security group operations
- **Key Responsibilities**:
- - Modify security groups
- - Create backups of security group configurations
+ - 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>