def apply(self):
        stub = network_pb2_grpc.ComputeNetworkServiceStub(channel.Channel())
        request = network_pb2.ApplyComputeNetworkRequest()
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.name):
            request.resource.name = Primitive.to_proto(self.name)

        if Primitive.to_proto(self.auto_create_subnetworks):
            request.resource.auto_create_subnetworks = Primitive.to_proto(
                self.auto_create_subnetworks)

        if NetworkRoutingConfig.to_proto(self.routing_config):
            request.resource.routing_config.CopyFrom(
                NetworkRoutingConfig.to_proto(self.routing_config))
        else:
            request.resource.ClearField("routing_config")
        if Primitive.to_proto(self.project):
            request.resource.project = Primitive.to_proto(self.project)

        request.service_account_file = self.service_account_file

        response = stub.ApplyComputeNetwork(request)
        self.description = Primitive.from_proto(response.description)
        self.gateway_ipv4 = Primitive.from_proto(response.gateway_ipv4)
        self.ipv4_range = Primitive.from_proto(response.ipv4_range)
        self.name = Primitive.from_proto(response.name)
        self.auto_create_subnetworks = Primitive.from_proto(
            response.auto_create_subnetworks)
        self.routing_config = NetworkRoutingConfig.from_proto(
            response.routing_config)
        self.project = Primitive.from_proto(response.project)
        self.self_link = Primitive.from_proto(response.self_link)
    def list(self, project, service_account_file=""):
        stub = network_pb2_grpc.ComputeNetworkServiceStub(channel.Channel())
        request = network_pb2.ListComputeNetworkRequest()
        request.service_account_file = service_account_file
        request.Project = project

        return stub.ListComputeNetwork(request).items
Example #3
0
    def delete(self):
        stub = network_pb2_grpc.ComputeNetworkServiceStub(channel.Channel())
        request = network_pb2.DeleteComputeNetworkRequest()
        request.service_account_file = self.service_account_file
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.name):
            request.resource.name = Primitive.to_proto(self.name)

        if Primitive.to_proto(self.auto_create_subnetworks):
            request.resource.auto_create_subnetworks = Primitive.to_proto(
                self.auto_create_subnetworks)

        if NetworkRoutingConfig.to_proto(self.routing_config):
            request.resource.routing_config.CopyFrom(
                NetworkRoutingConfig.to_proto(self.routing_config))
        else:
            request.resource.ClearField("routing_config")
        if Primitive.to_proto(self.mtu):
            request.resource.mtu = Primitive.to_proto(self.mtu)

        if Primitive.to_proto(self.project):
            request.resource.project = Primitive.to_proto(self.project)

        response = stub.DeleteComputeNetwork(request)
Example #4
0
    def delete(self, project, name, service_account_file=""):
        stub = network_pb2_grpc.ComputeNetworkServiceStub(channel.Channel())
        request = network_pb2.DeleteComputeNetworkRequest()
        request.service_account_file = service_account_file
        request.Project = project

        request.Name = name

        response = stub.DeleteComputeNetwork(request)
Example #5
0
    def hcl(self):
        stub = network_pb2_grpc.ComputeNetworkServiceStub(channel.Channel())
        request = network_pb2.ComputeNetworkAsHclRequest()
        if Primitive.to_proto(self.description):
            request.resource.description = Primitive.to_proto(self.description)

        if Primitive.to_proto(self.name):
            request.resource.name = Primitive.to_proto(self.name)

        if Primitive.to_proto(self.auto_create_subnetworks):
            request.resource.auto_create_subnetworks = Primitive.to_proto(
                self.auto_create_subnetworks)

        if NetworkRoutingConfig.to_proto(self.routing_config):
            request.resource.routing_config.CopyFrom(
                NetworkRoutingConfig.to_proto(self.routing_config))
        else:
            request.resource.ClearField("routing_config")
        if Primitive.to_proto(self.project):
            request.resource.project = Primitive.to_proto(self.project)

        response = stub.ComputeNetworkAsHcl(request)
        return response.hcl