def testFoundInstNameKeyFromStdin(self): self.WriteInput(self.GetKeyFileContent()) msg = self.messages self.Run(""" compute instances create hamlet --csek-key-file - --zone central2-a """) self.CheckRequests( self.zone_get_request, self.project_get_request, [(self.compute.instances, 'Insert', msg.ComputeInstancesInsertRequest( instance=msg.Instance( canIpForward=False, deletionProtection=False, disks=[ msg.AttachedDisk( autoDelete=True, boot=True, deviceName='hamlet', initializeParams=msg. AttachedDiskInitializeParams( sourceImage=create_test_base.DefaultImageOf( self.api_version)), mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT, diskEncryptionKey=msg.CustomerEncryptionKey( rawKey=('abcdefghijklmnopqrstuv' 'wxyz1234567890AAAAAAA=')), ) ], machineType=create_test_base.DefaultMachineTypeOf( self.api_version), metadata=msg.Metadata(), name='hamlet', networkInterfaces=[ msg.NetworkInterface( accessConfigs=[ msg.AccessConfig(name='external-nat', type=self._one_to_one_nat) ], network=create_test_base.DefaultNetworkOf( self.api_version)) ], serviceAccounts=[ msg.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=msg.Scheduling(automaticRestart=True), ), project='my-project', zone='central2-a', ))], )
def testFoundInstanceNameKeyFileWrappedRsaKey(self): private_key_fname = self.WriteKeyFile(include_rsa_encrypted=True) msg = self.messages self.Run(""" compute instances create wrappedkeydisk --csek-key-file {0} --zone central2-a """.format(private_key_fname)) self.CheckRequests( self.zone_get_request, self.project_get_request, [(self.compute.instances, 'Insert', msg.ComputeInstancesInsertRequest( instance=msg.Instance( canIpForward=False, deletionProtection=False, disks=[ msg.AttachedDisk( autoDelete=True, boot=True, deviceName='wrappedkeydisk', initializeParams=msg. AttachedDiskInitializeParams( sourceImage=create_test_base.DefaultImageOf( self.api_version)), mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT, diskEncryptionKey=msg.CustomerEncryptionKey( rsaEncryptedKey=test_base. SAMPLE_WRAPPED_CSEK_KEY)) ], machineType=create_test_base.DefaultMachineTypeOf( self.api_version), metadata=msg.Metadata(), name='wrappedkeydisk', networkInterfaces=[ msg.NetworkInterface( accessConfigs=[ msg.AccessConfig(name='external-nat', type=self._one_to_one_nat) ], network=create_test_base.DefaultNetworkOf( self.api_version)) ], serviceAccounts=[ msg.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=msg.Scheduling(automaticRestart=True), ), project='my-project', zone='central2-a', ))], )
def testImageFamilyURI(self): msg = self.messages self.Run(""" compute instances create hamlet --zone central2-a --image-family '{0}/projects/my-project/global/images/family/yorik' """.format(self.compute_uri)) self.CheckRequests( self.zone_get_request, self.project_get_request, [(self.compute.instances, 'Insert', msg.ComputeInstancesInsertRequest( instance=msg.Instance( canIpForward=False, deletionProtection=False, disks=[ msg.AttachedDisk( autoDelete=True, boot=True, initializeParams=msg. AttachedDiskInitializeParams(sourceImage=( self.compute_uri + '/projects/my-project/global/images/' 'family/yorik'), ), mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT) ], machineType=create_test_base.DefaultMachineTypeOf( self.api_version), metadata=msg.Metadata(), name='hamlet', networkInterfaces=[ msg.NetworkInterface( accessConfigs=[ msg.AccessConfig(name='external-nat', type=self._one_to_one_nat) ], network=create_test_base.DefaultNetworkOf( self.api_version)) ], serviceAccounts=[ msg.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=msg.Scheduling(automaticRestart=True), ), project='my-project', zone='central2-a', ))], )
def testMultipleNetworkInterfaceCards(self): msg = self.messages self.Run(""" compute instances create hamlet --zone central2-a --image '{0}/projects/my-project/global/images/family/yorik' --network-interface network=default,address= --network-interface network=some-net,private-network-ip=10.0.0.1,address=8.8.8.8 --network-interface subnet=some-subnet """.format(self.compute_uri)) self.CheckRequests( self.zone_get_request, self.project_get_request, [(self.compute.instances, 'Insert', msg.ComputeInstancesInsertRequest( instance=msg.Instance( canIpForward=False, deletionProtection=False, disks=[ msg.AttachedDisk( autoDelete=True, boot=True, initializeParams=msg. AttachedDiskInitializeParams(sourceImage=( self.compute_uri + '/projects/my-project/global/images/' 'family/yorik'), ), mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT) ], machineType=create_test_base.DefaultMachineTypeOf( self.api_version), metadata=msg.Metadata(), name='hamlet', networkInterfaces=[ msg.NetworkInterface( accessConfigs=[ msg.AccessConfig( name='external-nat', networkTier=self._default_network_tier, type=self._one_to_one_nat) ], network=create_test_base.DefaultNetworkOf( self.api_version)), msg.NetworkInterface( accessConfigs=[ msg.AccessConfig( name='external-nat', networkTier=self._default_network_tier, natIP='8.8.8.8', type=self._one_to_one_nat) ], network= ('https://compute.googleapis.com/compute/alpha/' 'projects/my-project/global/networks/' 'some-net'), networkIP='10.0.0.1'), msg.NetworkInterface( subnetwork=( 'https://compute.googleapis.com/compute/' 'alpha/projects/my-project/regions/' 'central2/subnetworks/some-subnet'), accessConfigs=[ msg.AccessConfig( name='external-nat', networkTier=self._default_network_tier, type=self._one_to_one_nat) ], ), ], serviceAccounts=[ msg.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=msg.Scheduling(automaticRestart=True), ), project='my-project', zone='central2-a', ))], )
def testTwoDisksFoundKeyFile(self): private_key_fname = self.WriteKeyFile() msg = self.messages self.Run(""" compute instances create instance-1 --disk name=hamlet,boot=yes --disk name=ophelia --csek-key-file {0} --zone central2-a """.format(private_key_fname)) self.CheckRequests( self.zone_get_request, self.project_get_request, [(self.compute.instances, 'Insert', msg.ComputeInstancesInsertRequest( instance=msg.Instance( canIpForward=False, deletionProtection=False, disks=[ msg.AttachedDisk( autoDelete=False, boot=True, mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT, source=( self.compute_uri + '/projects/my-project/zones/central2-a/disks/' 'hamlet'.format(api=self.api)), diskEncryptionKey=msg.CustomerEncryptionKey( rawKey=('abcdefghijklmnopqrstuv' 'wxyz1234567890AAAAAAA='))), msg.AttachedDisk( autoDelete=False, boot=False, mode=msg.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=msg.AttachedDisk.TypeValueValuesEnum. PERSISTENT, source=( self.compute_uri + '/projects/my-project/zones/central2-a/disks/' 'ophelia'.format(api=self.api)), diskEncryptionKey=msg.CustomerEncryptionKey( rawKey=('OpheliaOphelia00000000' '00000000000000000000X='))) ], machineType=create_test_base.DefaultMachineTypeOf( self.api_version), metadata=msg.Metadata(), name='instance-1', networkInterfaces=[ msg.NetworkInterface( accessConfigs=[ msg.AccessConfig(name='external-nat', type=self._one_to_one_nat) ], network=create_test_base.DefaultNetworkOf( self.api_version)) ], serviceAccounts=[ msg.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=msg.Scheduling(automaticRestart=True), ), project='my-project', zone='central2-a', ))], )
def testPreemptible(self): m = self.messages self.make_requests.side_effect = iter([ [ m.Zone(name='us-central2-b'), ], [ self.messages.Project( defaultServiceAccount='*****@*****.**'), ], [], ]) self.Run(""" compute instances create instance-1 --machine-type=n1-standard-1 --zone=us-central1-b --preemptible --no-restart-on-failure --maintenance-policy=terminate """) self.CheckRequests( [(self.compute.zones, 'Get', m.ComputeZonesGetRequest(project='my-project', zone='us-central1-b'))], self.project_get_request, [(self.compute.instances, 'Insert', m.ComputeInstancesInsertRequest( instance=m.Instance( canIpForward=False, deletionProtection=False, disks=[ m.AttachedDisk( autoDelete=True, boot=True, initializeParams=m.AttachedDiskInitializeParams( sourceImage=create_test_base.DefaultImageOf( self.api_version), ), mode=m.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=m.AttachedDisk.TypeValueValuesEnum. PERSISTENT) ], machineType=create_test_base. DefaultPreemptibleMachineTypeOf(self.api_version), metadata=m.Metadata(), name='instance-1', networkInterfaces=[ m.NetworkInterface( accessConfigs=[ m.AccessConfig( name='external-nat', type=m.AccessConfig.TypeValueValuesEnum. ONE_TO_ONE_NAT) ], network=create_test_base.DefaultNetworkOf( self.api_version)) ], serviceAccounts=[ m.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=m.Scheduling( automaticRestart=False, onHostMaintenance=m.Scheduling. OnHostMaintenanceValueValuesEnum.TERMINATE, preemptible=True)), project='my-project', zone='us-central1-b', ))], )
def testCreateWithLabels(self): m = self.messages self.make_requests.side_effect = iter([ [ m.Zone(name='central2-a'), ], [ m.Project(defaultServiceAccount='*****@*****.**'), ], [], ]) self.Run(""" compute instances create instance-with-labels --zone=central2-a --labels=k0=v0,k-1=v-1 --labels=foo=bar """) labels_in_request = (('foo', 'bar'), ('k-1', 'v-1'), ('k0', 'v0')) self.CheckRequests( [(self.compute.zones, 'Get', m.ComputeZonesGetRequest(project='my-project', zone='central2-a'))], self.project_get_request, [(self.compute.instances, 'Insert', m.ComputeInstancesInsertRequest( instance=m.Instance( canIpForward=False, deletionProtection=False, disks=[ m.AttachedDisk( autoDelete=True, boot=True, initializeParams=m.AttachedDiskInitializeParams( sourceImage=create_test_base.DefaultImageOf( 'v1'), ), mode=m.AttachedDisk.ModeValueValuesEnum. READ_WRITE, type=m.AttachedDisk.TypeValueValuesEnum. PERSISTENT) ], labels=m.Instance.LabelsValue(additionalProperties=[ m.Instance.LabelsValue.AdditionalProperty( key=pair[0], value=pair[1]) for pair in labels_in_request ]), metadata=m.Metadata(), machineType=create_test_base.DefaultMachineTypeOf( self.api_version), name='instance-with-labels', networkInterfaces=[ m.NetworkInterface( accessConfigs=[ m.AccessConfig( name='external-nat', type=m.AccessConfig.TypeValueValuesEnum. ONE_TO_ONE_NAT) ], network=create_test_base.DefaultNetworkOf('v1')) ], serviceAccounts=[ m.ServiceAccount( email='default', scopes=create_test_base.DEFAULT_SCOPES), ], scheduling=m.Scheduling(automaticRestart=True)), project='my-project', zone='central2-a', ))], )