Compare commits
No commits in common. "feature/vpc" and "master" have entirely different histories.
feature/vp
...
master
@ -6,5 +6,3 @@ users:
|
|||||||
groups: wheel
|
groups: wheel
|
||||||
plain_text_passwd: abc123
|
plain_text_passwd: abc123
|
||||||
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
|
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
|
||||||
ssh_authorized_keys:
|
|
||||||
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDUz3WF4qPhk01//5QUuNWyHTn8shv86i/qEyRqa1kTF alexander@miku
|
|
@ -28,8 +28,6 @@ resource "aws_instance" "test-instance-1" {
|
|||||||
|
|
||||||
private_ip = "192.168.122.3"
|
private_ip = "192.168.122.3"
|
||||||
|
|
||||||
user_data = file("cloudinit.yaml")
|
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
UseCase = "k8s-control-plane"
|
UseCase = "k8s-control-plane"
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
ifId=$1
|
|
||||||
cidr=$2
|
|
||||||
broadcast=$3
|
|
||||||
|
|
||||||
ip link add name "$ifId" type bridge
|
|
||||||
ip addr add "$cidr" dev "$ifId" broadcast "$broadcast"
|
|
||||||
ip link set dev "$ifId" up
|
|
||||||
|
|
||||||
# TODO: NAT
|
|
@ -6,7 +6,6 @@ from openec2.db.user import User
|
|||||||
from openec2.config import OpenEC2Config
|
from openec2.config import OpenEC2Config
|
||||||
from openec2.db import DatabaseDep
|
from openec2.db import DatabaseDep
|
||||||
from openec2.db.vpc import VPC
|
from openec2.db.vpc import VPC
|
||||||
from openec2.network.vpc import prepare_host_vpc
|
|
||||||
|
|
||||||
|
|
||||||
def create_vpc(
|
def create_vpc(
|
||||||
@ -15,19 +14,4 @@ def create_vpc(
|
|||||||
db: DatabaseDep,
|
db: DatabaseDep,
|
||||||
user: User,
|
user: User,
|
||||||
):
|
):
|
||||||
# TODO: Check if it already exists
|
|
||||||
cidr_block = params["CidrBlock"]
|
cidr_block = params["CidrBlock"]
|
||||||
vpcs = db.exec(select(VPC)).all()
|
|
||||||
max_interface_num = max(v.bridge_num for v in vpcs) if vpcs else 0
|
|
||||||
|
|
||||||
# Create the VPC
|
|
||||||
vpc = VPC(
|
|
||||||
bridge_num=max_interface_num + 1,
|
|
||||||
cidr=cidr_block,
|
|
||||||
owner_id=user.id,
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
prepare_host_vpc(vpc)
|
|
||||||
|
|
||||||
db.add(vpc)
|
|
||||||
db.commit()
|
|
||||||
|
@ -55,7 +55,6 @@ def describe_instances(
|
|||||||
code=48,
|
code=48,
|
||||||
name="terminated",
|
name="terminated",
|
||||||
),
|
),
|
||||||
privateIpAddress=instance.privateIPv4,
|
|
||||||
tagSet=[
|
tagSet=[
|
||||||
Tag(
|
Tag(
|
||||||
key=key,
|
key=key,
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from pydantic_xml import BaseXmlModel, wrapped, element
|
|
@ -11,7 +11,6 @@ class InstanceDescription(
|
|||||||
instanceId: str = element()
|
instanceId: str = element()
|
||||||
imageId: str = element()
|
imageId: str = element()
|
||||||
instanceState: InstanceState = element()
|
instanceState: InstanceState = element()
|
||||||
privateIpAddress: str = element()
|
|
||||||
tagSet: list[Tag] = wrapped("tagSet", element(tag="item"))
|
tagSet: list[Tag] = wrapped("tagSet", element(tag="item"))
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +43,6 @@ def describe_instance(
|
|||||||
instanceId=instance.id,
|
instanceId=instance.id,
|
||||||
imageId=instance.imageId,
|
imageId=instance.imageId,
|
||||||
instanceState=describe_instance_state(domain),
|
instanceState=describe_instance_state(domain),
|
||||||
privateIpAddress=instance.privateIPv4,
|
|
||||||
tagSet=[
|
tagSet=[
|
||||||
Tag(
|
Tag(
|
||||||
key=key,
|
key=key,
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from ipaddress import ip_network
|
|
||||||
|
|
||||||
from sqlmodel import SQLModel, Field
|
from sqlmodel import SQLModel, Field
|
||||||
|
|
||||||
|
|
||||||
@ -7,28 +5,8 @@ class VPC(SQLModel, table=True):
|
|||||||
# ID of the VPC
|
# ID of the VPC
|
||||||
id: str = Field(default=None, primary_key=True)
|
id: str = Field(default=None, primary_key=True)
|
||||||
|
|
||||||
# Number-suffix of the bridge device
|
|
||||||
bridge_num: int
|
|
||||||
|
|
||||||
# Base IPv4
|
# Base IPv4
|
||||||
cidr: str
|
cidr: str
|
||||||
|
|
||||||
# Flag indicating whether this VPC is the user's default VPC
|
|
||||||
default: bool
|
|
||||||
|
|
||||||
# Owning user
|
# Owning user
|
||||||
owner_id: int = Field(foreign_key="user.id")
|
owner_id: int = Field(foreign_key="user.id")
|
||||||
|
|
||||||
@property
|
|
||||||
def virbr(self) -> str:
|
|
||||||
return f"virbr{self.bridge_num}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def gateway(self) -> str:
|
|
||||||
network = ip_network(self.cidr)
|
|
||||||
return f"{network[1]}/{network.prefixlen}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def broadcast(self) -> str:
|
|
||||||
network = ip_network(self.cidr)
|
|
||||||
return f"{network[255]}"
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
|
|
||||||
from openec2.db.vpc import VPC
|
|
||||||
|
|
||||||
|
|
||||||
def prepare_host_vpc(vpc: VPC):
|
|
||||||
# Create the bridge
|
|
||||||
subprocess.call([
|
|
||||||
"/home/alexander/Development/Personal/openec2/scripts/create-network-interface.sh",
|
|
||||||
vpc.virbr,
|
|
||||||
vpc.gateway,
|
|
||||||
vpc.broadcast,
|
|
||||||
])
|
|
Loading…
Reference in New Issue
Block a user