Program NAT and PF rules to open up ssh access to deployed guest @return:
(
cls, apiclient, services, virtual_machine, allow_egress=False,
networkid=None, vpcid=None)
| 455 | |
| 456 | @classmethod |
| 457 | def access_ssh_over_nat( |
| 458 | cls, apiclient, services, virtual_machine, allow_egress=False, |
| 459 | networkid=None, vpcid=None): |
| 460 | """ |
| 461 | Program NAT and PF rules to open up ssh access to deployed guest |
| 462 | @return: |
| 463 | """ |
| 464 | # VPCs have ACLs managed differently |
| 465 | if vpcid: |
| 466 | public_ip = PublicIPAddress.create( |
| 467 | apiclient=apiclient, |
| 468 | accountid=virtual_machine.account, |
| 469 | zoneid=virtual_machine.zoneid, |
| 470 | domainid=virtual_machine.domainid, |
| 471 | services=services, |
| 472 | vpcid=vpcid |
| 473 | ) |
| 474 | |
| 475 | nat_rule = NATRule.create( |
| 476 | apiclient=apiclient, |
| 477 | virtual_machine=virtual_machine, |
| 478 | services=services, |
| 479 | ipaddressid=public_ip.ipaddress.id, |
| 480 | networkid=networkid) |
| 481 | else: |
| 482 | public_ip = PublicIPAddress.create( |
| 483 | apiclient=apiclient, |
| 484 | accountid=virtual_machine.account, |
| 485 | zoneid=virtual_machine.zoneid, |
| 486 | domainid=virtual_machine.domainid, |
| 487 | services=services, |
| 488 | networkid=networkid, |
| 489 | ) |
| 490 | |
| 491 | FireWallRule.create( |
| 492 | apiclient=apiclient, |
| 493 | ipaddressid=public_ip.ipaddress.id, |
| 494 | protocol='TCP', |
| 495 | cidrlist=['0.0.0.0/0'], |
| 496 | startport=22, |
| 497 | endport=22 |
| 498 | ) |
| 499 | nat_rule = NATRule.create( |
| 500 | apiclient=apiclient, |
| 501 | virtual_machine=virtual_machine, |
| 502 | services=services, |
| 503 | ipaddressid=public_ip.ipaddress.id) |
| 504 | |
| 505 | if allow_egress and not vpcid: |
| 506 | try: |
| 507 | EgressFireWallRule.create( |
| 508 | apiclient=apiclient, |
| 509 | networkid=virtual_machine.nic[0].networkid, |
| 510 | protocol='All', |
| 511 | cidrlist='0.0.0.0/0' |
| 512 | ) |
| 513 | except CloudstackAPIException as e: |
| 514 | # This could fail because we've already set up the same rule |
no test coverage detected