Ejemplo n.º 1
0
    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',
              ))],
        )
Ejemplo n.º 2
0
    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',
              ))],
        )
Ejemplo n.º 3
0
 def assertBootDiskWithKmsKey(self, expected_key=None):
   if not expected_key:
     expected_key = self.global_kms_key
   m = self.messages
   self.assertDefaultRequestWithAttachedDisks(
       m.AttachedDisk(
           autoDelete=True,
           boot=True,
           diskEncryptionKey=expected_key,
           initializeParams=m.AttachedDiskInitializeParams(
               sourceImage=create_test_base.DefaultImageOf(self.api_version),),
           mode=(m.AttachedDisk.ModeValueValuesEnum.READ_WRITE),
           type=(m.AttachedDisk.TypeValueValuesEnum.PERSISTENT)))
Ejemplo n.º 4
0
    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',
              ))],
        )
Ejemplo n.º 5
0
    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',
              ))],
        )