Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fencing: AWS VPC network resource fencer #609

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

robbybrodie
Copy link

A networking resource fencer for AWS VPC that works be manipulating security groups

Copy link

knet-jenkins bot commented Feb 1, 2025

Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/fence-agents/job/fence-agents-pipeline/job/PR-609/1/input

changed aws metadata calls to use TLS
Copy link

knet-jenkins bot commented Feb 1, 2025

Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/fence-agents/job/fence-agents-pipeline/job/PR-609/2/input

Copy link

knet-jenkins bot commented Feb 2, 2025

Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/fence-agents/job/fence-agents-pipeline/job/PR-609/3/input

updated spec file to remediate typo
Copy link

knet-jenkins bot commented Feb 2, 2025

Can one of the admins check and authorise this run please: https://ci.kronosnet.org/job/fence-agents/job/fence-agents-pipeline/job/PR-609/4/input

Copy link
Collaborator

@oalbrigt oalbrigt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general.

I think we should name the agent fence_aws_vpc_net or similar to indicate it is a network fence agent.

I've added some comments for improvements.

Can we make remove_security_groups()/keep_only_security_groups() one function to avoid duplicate code?

import time
import requests
from requests import HTTPError
from requests.exceptions import HTTPError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTPError isnt used, and if we're going to use them they should be imported with their full name, e.g. import requests.HTTPError.


sys.path.append("@FENCEAGENTSLIBDIR@")
#sys.path.append("/usr/share/fence")
#sys.path.append("/usr/share/fence")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, in branch changes-_PR609

#sys.path.append("/usr/share/fence")

from fencing import *
from fencing import (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise

# Check if we are the self-fencing node

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the blank line here.

Copy link
Author

@robbybrodie robbybrodie Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, in branch changes-_PR609

logger.debug("Captured my (%s) state and it %s - returning OK - Proceeding with fencing",instance_id,state.upper())
return "ok"
else:
logger.debug("Captured my (%s) state it is %s - returning Alert - Unable to fence other nodes",instance_id,state.upper())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use formatted strings for these 2 as well for consistency.


def main():
conn = None
#print("in main")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all commented out code in main().

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, in branch changes-_PR609

"access_key",
"secret_key",
"secg",
"plug",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "port" as explained above.

Copy link
Author

@robbybrodie robbybrodie Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? @oalbrigt i don't have an issue with changing it, however i'd like to check as my understanding from the docs is was port is deprecated to plug?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but port is the name it's using internally in the library and provides both plug and port (shown as deprecated in metadata) parameters.

except Exception as e:
logger.error(f"Failed to process input options: {str(e)}")
#print(f"Error details: {str(e)}")
sys.exit(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use EC-code.

docs = {
"shortdesc": "Fence agent for AWS VPC",
"longdesc": (
"fence_aws_vpc is a Power Fencing agent for AWS VPC that works by "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "Network and Power Fencing agent".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, in branch changes-_PR609

"fence_aws_vpc is a Power Fencing agent for AWS VPC that works by "
"manipulating security groups. It uses the boto3 library to connect to AWS.\n\n"
"boto3 can be configured with AWS CLI or by creating ~/.aws/credentials.\n"
"For instructions see: https://boto3.readthedocs.io/en/latest/guide/quickstart.html#configuration"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a "NOTE:" that says the agent wont be able to power on the node again if onfence-poweroff is set.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, in branch changes-_PR609

@robbybrodie
Copy link
Author

robbybrodie commented Feb 4, 2025

@oalbrigt

Can we make remove_security_groups()/keep_only_security_groups() one function to avoid duplicate code?

yes. ive put in this branch changes-_PR609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants