Shutdown Source VM (PAUSED) on successfull migration + blackened all .py files
This commit is contained in:
parent
29e938dc74
commit
9bdf4d2180
31 changed files with 1307 additions and 638 deletions
|
|
@ -16,21 +16,23 @@ logger = logging.getLogger(__name__)
|
|||
def check_otp(name, realm, token):
|
||||
try:
|
||||
data = {
|
||||
"auth_name": settings['otp']['auth_name'],
|
||||
"auth_token": TOTP(settings['otp']['auth_seed']).now(),
|
||||
"auth_realm": settings['otp']['auth_realm'],
|
||||
"auth_name": settings["otp"]["auth_name"],
|
||||
"auth_token": TOTP(settings["otp"]["auth_seed"]).now(),
|
||||
"auth_realm": settings["otp"]["auth_realm"],
|
||||
"name": name,
|
||||
"realm": realm,
|
||||
"token": token,
|
||||
}
|
||||
except binascii.Error as err:
|
||||
logger.error(
|
||||
"Cannot compute OTP for seed: {}".format(settings['otp']['auth_seed'])
|
||||
"Cannot compute OTP for seed: {}".format(
|
||||
settings["otp"]["auth_seed"]
|
||||
)
|
||||
)
|
||||
return 400
|
||||
|
||||
response = requests.post(
|
||||
settings['otp']['verification_controller_url'], json=data
|
||||
settings["otp"]["verification_controller_url"], json=data
|
||||
)
|
||||
return response.status_code
|
||||
|
||||
|
|
@ -43,7 +45,8 @@ def resolve_vm_name(name, owner):
|
|||
"""
|
||||
result = next(
|
||||
filter(
|
||||
lambda vm: vm.value["owner"] == owner and vm.value["name"] == name,
|
||||
lambda vm: vm.value["owner"] == owner
|
||||
and vm.value["name"] == name,
|
||||
shared.vm_pool.vms,
|
||||
),
|
||||
None,
|
||||
|
|
@ -80,18 +83,27 @@ def resolve_image_name(name, etcd_client):
|
|||
"""
|
||||
store_name, image_name = store_name_and_image_name
|
||||
except Exception:
|
||||
raise ValueError("Image name not in correct format i.e {store_name}:{image_name}")
|
||||
raise ValueError(
|
||||
"Image name not in correct format i.e {store_name}:{image_name}"
|
||||
)
|
||||
|
||||
images = etcd_client.get_prefix(settings['etcd']['image_prefix'], value_in_json=True)
|
||||
images = etcd_client.get_prefix(
|
||||
settings["etcd"]["image_prefix"], value_in_json=True
|
||||
)
|
||||
|
||||
# Try to find image with name == image_name and store_name == store_name
|
||||
try:
|
||||
image = next(filter(lambda im: im.value['name'] == image_name
|
||||
and im.value['store_name'] == store_name, images))
|
||||
image = next(
|
||||
filter(
|
||||
lambda im: im.value["name"] == image_name
|
||||
and im.value["store_name"] == store_name,
|
||||
images,
|
||||
)
|
||||
)
|
||||
except StopIteration:
|
||||
raise KeyError("No image with name {} found.".format(name))
|
||||
else:
|
||||
image_uuid = image.key.split('/')[-1]
|
||||
image_uuid = image.key.split("/")[-1]
|
||||
|
||||
return image_uuid
|
||||
|
||||
|
|
@ -100,7 +112,9 @@ def random_bytes(num=6):
|
|||
return [random.randrange(256) for _ in range(num)]
|
||||
|
||||
|
||||
def generate_mac(uaa=False, multicast=False, oui=None, separator=':', byte_fmt='%02x'):
|
||||
def generate_mac(
|
||||
uaa=False, multicast=False, oui=None, separator=":", byte_fmt="%02x"
|
||||
):
|
||||
mac = random_bytes()
|
||||
if oui:
|
||||
if type(oui) == str:
|
||||
|
|
@ -131,7 +145,9 @@ def get_ip_addr(mac_address, device):
|
|||
and is connected/neighbor of arg:device
|
||||
"""
|
||||
try:
|
||||
output = sp.check_output(['ip', '-6', 'neigh', 'show', 'dev', device], stderr=sp.PIPE)
|
||||
output = sp.check_output(
|
||||
["ip", "-6", "neigh", "show", "dev", device], stderr=sp.PIPE
|
||||
)
|
||||
except sp.CalledProcessError:
|
||||
return None
|
||||
else:
|
||||
|
|
@ -160,7 +176,7 @@ def mac2ipv6(mac, prefix):
|
|||
# format output
|
||||
ipv6_parts = [str(0)] * 4
|
||||
for i in range(0, len(parts), 2):
|
||||
ipv6_parts.append("".join(parts[i:i + 2]))
|
||||
ipv6_parts.append("".join(parts[i : i + 2]))
|
||||
|
||||
lower_part = ipaddress.IPv6Address(":".join(ipv6_parts))
|
||||
prefix = ipaddress.IPv6Address(prefix)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue