mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
[CLOUDSTACK-10020] Changes to make marvin work with projects and VPCs (#2206)
Co-authored-by: dahn <daan.hoogland@shapeblue.com>
This commit is contained in:
parent
f4f35a8995
commit
5316810aa3
@ -451,34 +451,53 @@ class VirtualMachine:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def access_ssh_over_nat(
|
def access_ssh_over_nat(
|
||||||
cls, apiclient, services, virtual_machine, allow_egress=False,
|
cls, apiclient, services, virtual_machine, allow_egress=False,
|
||||||
networkid=None):
|
networkid=None, vpcid=None):
|
||||||
"""
|
"""
|
||||||
Program NAT and PF rules to open up ssh access to deployed guest
|
Program NAT and PF rules to open up ssh access to deployed guest
|
||||||
@return:
|
@return:
|
||||||
"""
|
"""
|
||||||
public_ip = PublicIPAddress.create(
|
# VPCs have ACLs managed differently
|
||||||
apiclient=apiclient,
|
if vpcid:
|
||||||
accountid=virtual_machine.account,
|
public_ip = PublicIPAddress.create(
|
||||||
zoneid=virtual_machine.zoneid,
|
apiclient=apiclient,
|
||||||
domainid=virtual_machine.domainid,
|
accountid=virtual_machine.account,
|
||||||
services=services,
|
zoneid=virtual_machine.zoneid,
|
||||||
networkid=networkid
|
domainid=virtual_machine.domainid,
|
||||||
)
|
services=services,
|
||||||
FireWallRule.create(
|
vpcid=vpcid
|
||||||
apiclient=apiclient,
|
)
|
||||||
ipaddressid=public_ip.ipaddress.id,
|
|
||||||
protocol='TCP',
|
nat_rule = NATRule.create(
|
||||||
cidrlist=['0.0.0.0/0'],
|
apiclient=apiclient,
|
||||||
startport=22,
|
virtual_machine=virtual_machine,
|
||||||
endport=22
|
services=services,
|
||||||
)
|
ipaddressid=public_ip.ipaddress.id,
|
||||||
nat_rule = NATRule.create(
|
networkid=networkid)
|
||||||
apiclient=apiclient,
|
else:
|
||||||
virtual_machine=virtual_machine,
|
public_ip = PublicIPAddress.create(
|
||||||
services=services,
|
apiclient=apiclient,
|
||||||
ipaddressid=public_ip.ipaddress.id
|
accountid=virtual_machine.account,
|
||||||
)
|
zoneid=virtual_machine.zoneid,
|
||||||
if allow_egress:
|
domainid=virtual_machine.domainid,
|
||||||
|
services=services,
|
||||||
|
networkid=networkid,
|
||||||
|
)
|
||||||
|
|
||||||
|
FireWallRule.create(
|
||||||
|
apiclient=apiclient,
|
||||||
|
ipaddressid=public_ip.ipaddress.id,
|
||||||
|
protocol='TCP',
|
||||||
|
cidrlist=['0.0.0.0/0'],
|
||||||
|
startport=22,
|
||||||
|
endport=22
|
||||||
|
)
|
||||||
|
nat_rule = NATRule.create(
|
||||||
|
apiclient=apiclient,
|
||||||
|
virtual_machine=virtual_machine,
|
||||||
|
services=services,
|
||||||
|
ipaddressid=public_ip.ipaddress.id)
|
||||||
|
|
||||||
|
if allow_egress and not vpcid:
|
||||||
try:
|
try:
|
||||||
EgressFireWallRule.create(
|
EgressFireWallRule.create(
|
||||||
apiclient=apiclient,
|
apiclient=apiclient,
|
||||||
@ -502,7 +521,7 @@ class VirtualMachine:
|
|||||||
hostid=None, keypair=None, ipaddress=None, mode='default',
|
hostid=None, keypair=None, ipaddress=None, mode='default',
|
||||||
method='GET', hypervisor=None, customcpunumber=None,
|
method='GET', hypervisor=None, customcpunumber=None,
|
||||||
customcpuspeed=None, custommemory=None, rootdisksize=None,
|
customcpuspeed=None, custommemory=None, rootdisksize=None,
|
||||||
rootdiskcontroller=None, macaddress=None, datadisktemplate_diskoffering_list={}):
|
rootdiskcontroller=None, vpcid=None, macaddress=None, datadisktemplate_diskoffering_list={}):
|
||||||
"""Create the instance"""
|
"""Create the instance"""
|
||||||
|
|
||||||
cmd = deployVirtualMachine.deployVirtualMachineCmd()
|
cmd = deployVirtualMachine.deployVirtualMachineCmd()
|
||||||
@ -654,7 +673,8 @@ class VirtualMachine:
|
|||||||
services,
|
services,
|
||||||
virtual_machine,
|
virtual_machine,
|
||||||
allow_egress=allow_egress,
|
allow_egress=allow_egress,
|
||||||
networkid=cmd.networkids[0] if cmd.networkids else None)
|
networkid=cmd.networkids[0] if cmd.networkids else None,
|
||||||
|
vpcid=vpcid)
|
||||||
elif mode.lower() == 'basic':
|
elif mode.lower() == 'basic':
|
||||||
if virtual_machine.publicip is not None:
|
if virtual_machine.publicip is not None:
|
||||||
# EIP/ELB (netscaler) enabled zone
|
# EIP/ELB (netscaler) enabled zone
|
||||||
@ -1042,7 +1062,7 @@ class Volume:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_custom_disk(cls, apiclient, services, account=None,
|
def create_custom_disk(cls, apiclient, services, account=None,
|
||||||
domainid=None, diskofferingid=None):
|
domainid=None, diskofferingid=None, projectid=None):
|
||||||
"""Create Volume from Custom disk offering"""
|
"""Create Volume from Custom disk offering"""
|
||||||
cmd = createVolume.createVolumeCmd()
|
cmd = createVolume.createVolumeCmd()
|
||||||
cmd.name = services["diskname"]
|
cmd.name = services["diskname"]
|
||||||
@ -1065,19 +1085,22 @@ class Volume:
|
|||||||
|
|
||||||
if account:
|
if account:
|
||||||
cmd.account = account
|
cmd.account = account
|
||||||
else:
|
elif "account" in services:
|
||||||
cmd.account = services["account"]
|
cmd.account = services["account"]
|
||||||
|
|
||||||
if domainid:
|
if domainid:
|
||||||
cmd.domainid = domainid
|
cmd.domainid = domainid
|
||||||
else:
|
elif "domainid" in services:
|
||||||
cmd.domainid = services["domainid"]
|
cmd.domainid = services["domainid"]
|
||||||
|
|
||||||
|
if projectid:
|
||||||
|
cmd.projectid = projectid
|
||||||
|
|
||||||
return Volume(apiclient.createVolume(cmd).__dict__)
|
return Volume(apiclient.createVolume(cmd).__dict__)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_snapshot(cls, apiclient, snapshot_id, services,
|
def create_from_snapshot(cls, apiclient, snapshot_id, services,
|
||||||
account=None, domainid=None):
|
account=None, domainid=None, projectid=None):
|
||||||
"""Create Volume from snapshot"""
|
"""Create Volume from snapshot"""
|
||||||
cmd = createVolume.createVolumeCmd()
|
cmd = createVolume.createVolumeCmd()
|
||||||
cmd.name = "-".join([services["diskname"], random_gen()])
|
cmd.name = "-".join([services["diskname"], random_gen()])
|
||||||
@ -1091,12 +1114,16 @@ class Volume:
|
|||||||
cmd.ispublic = False
|
cmd.ispublic = False
|
||||||
if account:
|
if account:
|
||||||
cmd.account = account
|
cmd.account = account
|
||||||
else:
|
elif "account" in services:
|
||||||
cmd.account = services["account"]
|
cmd.account = services["account"]
|
||||||
if domainid:
|
if domainid:
|
||||||
cmd.domainid = domainid
|
cmd.domainid = domainid
|
||||||
else:
|
elif "domainid" in services:
|
||||||
cmd.domainid = services["domainid"]
|
cmd.domainid = services["domainid"]
|
||||||
|
|
||||||
|
if projectid:
|
||||||
|
cmd.projectid = projectid
|
||||||
|
|
||||||
return Volume(apiclient.createVolume(cmd).__dict__)
|
return Volume(apiclient.createVolume(cmd).__dict__)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -1445,8 +1472,8 @@ class Template:
|
|||||||
return Template(apiclient.createTemplate(cmd).__dict__)
|
return Template(apiclient.createTemplate(cmd).__dict__)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_snapshot(cls, apiclient, snapshot, services,
|
def create_from_snapshot(cls, apiclient, snapshot, services, account=None,
|
||||||
random_name=True):
|
domainid=None, projectid=None, random_name=True):
|
||||||
"""Create Template from snapshot"""
|
"""Create Template from snapshot"""
|
||||||
# Create template from Snapshot ID
|
# Create template from Snapshot ID
|
||||||
cmd = createTemplate.createTemplateCmd()
|
cmd = createTemplate.createTemplateCmd()
|
||||||
@ -1485,6 +1512,17 @@ class Template:
|
|||||||
raise Exception(
|
raise Exception(
|
||||||
"Unable to find Ostype is required for creating template")
|
"Unable to find Ostype is required for creating template")
|
||||||
|
|
||||||
|
cmd.snapshotid = snapshot.id
|
||||||
|
|
||||||
|
if account:
|
||||||
|
cmd.account = account
|
||||||
|
if domainid:
|
||||||
|
cmd.domainid = domainid
|
||||||
|
if projectid:
|
||||||
|
cmd.projectid = projectid
|
||||||
|
|
||||||
|
return Template(apiclient.createTemplate(cmd).__dict__)
|
||||||
|
|
||||||
def delete(self, apiclient, zoneid=None):
|
def delete(self, apiclient, zoneid=None):
|
||||||
"""Delete Template"""
|
"""Delete Template"""
|
||||||
|
|
||||||
@ -3921,7 +3959,7 @@ class VpnCustomerGateway:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, apiclient, services, name, gateway, cidrlist,
|
def create(cls, apiclient, services, name, gateway, cidrlist,
|
||||||
account=None, domainid=None):
|
account=None, domainid=None, projectid=None):
|
||||||
"""Create VPN Customer Gateway"""
|
"""Create VPN Customer Gateway"""
|
||||||
cmd = createVpnCustomerGateway.createVpnCustomerGatewayCmd()
|
cmd = createVpnCustomerGateway.createVpnCustomerGatewayCmd()
|
||||||
cmd.name = name
|
cmd.name = name
|
||||||
@ -3945,6 +3983,9 @@ class VpnCustomerGateway:
|
|||||||
cmd.account = account
|
cmd.account = account
|
||||||
if domainid:
|
if domainid:
|
||||||
cmd.domainid = domainid
|
cmd.domainid = domainid
|
||||||
|
if projectid:
|
||||||
|
cmd.projectid = projectid
|
||||||
|
|
||||||
return VpnCustomerGateway(
|
return VpnCustomerGateway(
|
||||||
apiclient.createVpnCustomerGateway(cmd).__dict__)
|
apiclient.createVpnCustomerGateway(cmd).__dict__)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user