def create_network_in_backends(network): job_ids = [] for bend in Backend.objects.filter(offline=False): network.create_backend_network(bend) jobs = backend_mod.create_network(network=network, backend=bend, connect=True) job_ids.extend(jobs) return job_ids
def reconcile_missing_network(self, network, backend): self.log.info("D: Missing Ganeti network %s in backend %s", network, backend) if self.fix: backend_mod.create_network(network, backend) self.log.info("F: Issued OP_NETWORK_CONNECT")
def handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") dry_run = options["dry_run"] name = options['name'] subnet = options['subnet'] backend_id = options['backend_id'] public = options['public'] flavor = options['flavor'] mode = options['mode'] link = options['link'] mac_prefix = options['mac_prefix'] tags = options['tags'] userid = options["owner"] if not name: raise CommandError("Name is required") if not subnet: raise CommandError("Subnet is required") if not flavor: raise CommandError("Flavor is required") if public and not backend_id: raise CommandError("backend-id is required") if not userid and not public: raise CommandError("'owner' is required for private networks") if mac_prefix and flavor == "MAC_FILTERED": raise CommandError("Can not override MAC_FILTERED mac-prefix") if link and flavor == "PHYSICAL_VLAN": raise CommandError("Can not override PHYSICAL_VLAN link") if backend_id: backend = get_backend(backend_id) fmode, flink, fmac_prefix, ftags = values_from_flavor(flavor) mode = mode or fmode link = link or flink mac_prefix = mac_prefix or fmac_prefix tags = tags or ftags try: validate_mac(mac_prefix + "0:00:00:00") except InvalidMacAddress: raise CommandError("Invalid MAC prefix '%s'" % mac_prefix) subnet, gateway, subnet6, gateway6 = validate_network_info(options) if not link or not mode: raise CommandError("Can not create network." " No connectivity link or mode") netinfo = { "name": name, "userid": options["owner"], "subnet": subnet, "gateway": gateway, "gateway6": gateway6, "subnet6": subnet6, "dhcp": options["dhcp"], "flavor": flavor, "public": public, "mode": mode, "link": link, "mac_prefix": mac_prefix, "tags": tags, "state": "ACTIVE"} if dry_run: self.stdout.write("Creating network:\n") pprint_table(self.stdout, tuple(netinfo.items())) return network = Network.objects.create(**netinfo) if userid: quotas.issue_and_accept_commission(network) if backend_id: # Create BackendNetwork only to the specified Backend network.create_backend_network(backend) create_network(network=network, backend=backend, connect=True)
def handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") dry_run = options["dry_run"] name = options['name'] subnet = options['subnet'] backend_id = options['backend_id'] public = options['public'] flavor = options['flavor'] mode = options['mode'] link = options['link'] mac_prefix = options['mac_prefix'] tags = options['tags'] userid = options["owner"] if not name: raise CommandError("Name is required") if not subnet: raise CommandError("Subnet is required") if not flavor: raise CommandError("Flavor is required") if public and not backend_id: raise CommandError("backend-id is required") if not userid and not public: raise CommandError("'owner' is required for private networks") if mac_prefix and flavor == "MAC_FILTERED": raise CommandError("Can not override MAC_FILTERED mac-prefix") if link and flavor == "PHYSICAL_VLAN": raise CommandError("Can not override PHYSICAL_VLAN link") if backend_id: backend = get_backend(backend_id) fmode, flink, fmac_prefix, ftags = values_from_flavor(flavor) mode = mode or fmode link = link or flink mac_prefix = mac_prefix or fmac_prefix tags = tags or ftags try: validate_mac(mac_prefix + "0:00:00:00") except InvalidMacAddress: raise CommandError("Invalid MAC prefix '%s'" % mac_prefix) subnet, gateway, subnet6, gateway6 = validate_network_info(options) if not link or not mode: raise CommandError("Can not create network." " No connectivity link or mode") netinfo = { "name": name, "userid": options["owner"], "subnet": subnet, "gateway": gateway, "gateway6": gateway6, "subnet6": subnet6, "dhcp": options["dhcp"], "flavor": flavor, "public": public, "mode": mode, "link": link, "mac_prefix": mac_prefix, "tags": tags, "state": "ACTIVE" } if dry_run: self.stdout.write("Creating network:\n") pprint_table(self.stdout, tuple(netinfo.items())) return network = Network.objects.create(**netinfo) if userid: quotas.issue_and_accept_commission(network) if backend_id: # Create BackendNetwork only to the specified Backend network.create_backend_network(backend) create_network(network=network, backend=backend, connect=True)
def reconcile_missing_network(network, backend): write("D: Missing Ganeti network %s in backend %s\n" % (network, backend)) if fix: backend_mod.create_network(network, backend) write("F: Issued OP_NETWORK_CONNECT\n")