Skip to content

Commit 5316810

Browse files
syedDaanHoogland
andauthored
[CLOUDSTACK-10020] Changes to make marvin work with projects and VPCs (#2206)
Co-authored-by: dahn <daan.hoogland@shapeblue.com>
1 parent f4f35a8 commit 5316810

File tree

1 file changed

+76
-35
lines changed

1 file changed

+76
-35
lines changed

tools/marvin/marvin/lib/base.py

Lines changed: 76 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -451,34 +451,53 @@ def ssh_access_group(cls, apiclient, cmd):
451451
@classmethod
452452
def access_ssh_over_nat(
453453
cls, apiclient, services, virtual_machine, allow_egress=False,
454-
networkid=None):
454+
networkid=None, vpcid=None):
455455
"""
456456
Program NAT and PF rules to open up ssh access to deployed guest
457457
@return:
458458
"""
459-
public_ip = PublicIPAddress.create(
460-
apiclient=apiclient,
461-
accountid=virtual_machine.account,
462-
zoneid=virtual_machine.zoneid,
463-
domainid=virtual_machine.domainid,
464-
services=services,
465-
networkid=networkid
466-
)
467-
FireWallRule.create(
468-
apiclient=apiclient,
469-
ipaddressid=public_ip.ipaddress.id,
470-
protocol='TCP',
471-
cidrlist=['0.0.0.0/0'],
472-
startport=22,
473-
endport=22
474-
)
475-
nat_rule = NATRule.create(
476-
apiclient=apiclient,
477-
virtual_machine=virtual_machine,
478-
services=services,
479-
ipaddressid=public_ip.ipaddress.id
480-
)
481-
if allow_egress:
459+
# VPCs have ACLs managed differently
460+
if vpcid:
461+
public_ip = PublicIPAddress.create(
462+
apiclient=apiclient,
463+
accountid=virtual_machine.account,
464+
zoneid=virtual_machine.zoneid,
465+
domainid=virtual_machine.domainid,
466+
services=services,
467+
vpcid=vpcid
468+
)
469+
470+
nat_rule = NATRule.create(
471+
apiclient=apiclient,
472+
virtual_machine=virtual_machine,
473+
services=services,
474+
ipaddressid=public_ip.ipaddress.id,
475+
networkid=networkid)
476+
else:
477+
public_ip = PublicIPAddress.create(
478+
apiclient=apiclient,
479+
accountid=virtual_machine.account,
480+
zoneid=virtual_machine.zoneid,
481+
domainid=virtual_machine.domainid,
482+
services=services,
483+
networkid=networkid,
484+
)
485+
486+
FireWallRule.create(
487+
apiclient=apiclient,
488+
ipaddressid=public_ip.ipaddress.id,
489+
protocol='TCP',
490+
cidrlist=['0.0.0.0/0'],
491+
startport=22,
492+
endport=22
493+
)
494+
nat_rule = NATRule.create(
495+
apiclient=apiclient,
496+
virtual_machine=virtual_machine,
497+
services=services,
498+
ipaddressid=public_ip.ipaddress.id)
499+
500+
if allow_egress and not vpcid:
482501
try:
483502
EgressFireWallRule.create(
484503
apiclient=apiclient,
@@ -502,7 +521,7 @@ def create(cls, apiclient, services, templateid=None, accountid=None,
502521
hostid=None, keypair=None, ipaddress=None, mode='default',
503522
method='GET', hypervisor=None, customcpunumber=None,
504523
customcpuspeed=None, custommemory=None, rootdisksize=None,
505-
rootdiskcontroller=None, macaddress=None, datadisktemplate_diskoffering_list={}):
524+
rootdiskcontroller=None, vpcid=None, macaddress=None, datadisktemplate_diskoffering_list={}):
506525
"""Create the instance"""
507526

508527
cmd = deployVirtualMachine.deployVirtualMachineCmd()
@@ -654,7 +673,8 @@ def create(cls, apiclient, services, templateid=None, accountid=None,
654673
services,
655674
virtual_machine,
656675
allow_egress=allow_egress,
657-
networkid=cmd.networkids[0] if cmd.networkids else None)
676+
networkid=cmd.networkids[0] if cmd.networkids else None,
677+
vpcid=vpcid)
658678
elif mode.lower() == 'basic':
659679
if virtual_machine.publicip is not None:
660680
# EIP/ELB (netscaler) enabled zone
@@ -1042,7 +1062,7 @@ def create(cls, apiclient, services, zoneid=None, account=None,
10421062

10431063
@classmethod
10441064
def create_custom_disk(cls, apiclient, services, account=None,
1045-
domainid=None, diskofferingid=None):
1065+
domainid=None, diskofferingid=None, projectid=None):
10461066
"""Create Volume from Custom disk offering"""
10471067
cmd = createVolume.createVolumeCmd()
10481068
cmd.name = services["diskname"]
@@ -1065,19 +1085,22 @@ def create_custom_disk(cls, apiclient, services, account=None,
10651085

10661086
if account:
10671087
cmd.account = account
1068-
else:
1088+
elif "account" in services:
10691089
cmd.account = services["account"]
10701090

10711091
if domainid:
10721092
cmd.domainid = domainid
1073-
else:
1093+
elif "domainid" in services:
10741094
cmd.domainid = services["domainid"]
10751095

1096+
if projectid:
1097+
cmd.projectid = projectid
1098+
10761099
return Volume(apiclient.createVolume(cmd).__dict__)
10771100

10781101
@classmethod
10791102
def create_from_snapshot(cls, apiclient, snapshot_id, services,
1080-
account=None, domainid=None):
1103+
account=None, domainid=None, projectid=None):
10811104
"""Create Volume from snapshot"""
10821105
cmd = createVolume.createVolumeCmd()
10831106
cmd.name = "-".join([services["diskname"], random_gen()])
@@ -1091,12 +1114,16 @@ def create_from_snapshot(cls, apiclient, snapshot_id, services,
10911114
cmd.ispublic = False
10921115
if account:
10931116
cmd.account = account
1094-
else:
1117+
elif "account" in services:
10951118
cmd.account = services["account"]
10961119
if domainid:
10971120
cmd.domainid = domainid
1098-
else:
1121+
elif "domainid" in services:
10991122
cmd.domainid = services["domainid"]
1123+
1124+
if projectid:
1125+
cmd.projectid = projectid
1126+
11001127
return Volume(apiclient.createVolume(cmd).__dict__)
11011128

11021129
@classmethod
@@ -1445,8 +1472,8 @@ def create_from_volume(cls, apiclient, volume, services,
14451472
return Template(apiclient.createTemplate(cmd).__dict__)
14461473

14471474
@classmethod
1448-
def create_from_snapshot(cls, apiclient, snapshot, services,
1449-
random_name=True):
1475+
def create_from_snapshot(cls, apiclient, snapshot, services, account=None,
1476+
domainid=None, projectid=None, random_name=True):
14501477
"""Create Template from snapshot"""
14511478
# Create template from Snapshot ID
14521479
cmd = createTemplate.createTemplateCmd()
@@ -1485,6 +1512,17 @@ def _set_command(cls, apiclient, cmd, services, random_name=True):
14851512
raise Exception(
14861513
"Unable to find Ostype is required for creating template")
14871514

1515+
cmd.snapshotid = snapshot.id
1516+
1517+
if account:
1518+
cmd.account = account
1519+
if domainid:
1520+
cmd.domainid = domainid
1521+
if projectid:
1522+
cmd.projectid = projectid
1523+
1524+
return Template(apiclient.createTemplate(cmd).__dict__)
1525+
14881526
def delete(self, apiclient, zoneid=None):
14891527
"""Delete Template"""
14901528

@@ -3921,7 +3959,7 @@ def __init__(self, items):
39213959

39223960
@classmethod
39233961
def create(cls, apiclient, services, name, gateway, cidrlist,
3924-
account=None, domainid=None):
3962+
account=None, domainid=None, projectid=None):
39253963
"""Create VPN Customer Gateway"""
39263964
cmd = createVpnCustomerGateway.createVpnCustomerGatewayCmd()
39273965
cmd.name = name
@@ -3945,6 +3983,9 @@ def create(cls, apiclient, services, name, gateway, cidrlist,
39453983
cmd.account = account
39463984
if domainid:
39473985
cmd.domainid = domainid
3986+
if projectid:
3987+
cmd.projectid = projectid
3988+
39483989
return VpnCustomerGateway(
39493990
apiclient.createVpnCustomerGateway(cmd).__dict__)
39503991

0 commit comments

Comments
 (0)